Editing php.ini
WordPress performance and upload behavior often comes down to a few PHP runtime limits. The tricky part is that php.ini location depends on how PHP is installed (CLI vs FPM vs LiteSpeed PHP), and changes only take effect after the correct service reload.
- Find the active config with
php --iniand (for FPM)php-fpm* -i | rg -n 'Loaded Configuration File'. - Change only a few settings at a time and reload the right service (
php-fpm,apache2, orlsws). - Verify with a small test script and remove it after confirming.
Prerequisites
- SSH access with
sudo. - PHP installed.
- Know which stack you run:
- Apache + mod_php
- Nginx/Apache + PHP-FPM
- OpenLiteSpeed + lsphp
Find the correct php.ini
Start by identifying where PHP is reading configuration.
php --ini
For WordPress, the important config is usually the one used by the web server, not the CLI. Use the tab that matches your deployment.
- Nginx/Apache + PHP-FPM
- Apache + mod_php
- OpenLiteSpeed + lsphp
systemctl list-units --type=service | rg -n 'php.*fpm'
If your distro provides a versioned binary, this shows the loaded file:
php-fpm -i 2>/dev/null | rg -n 'Loaded Configuration File|Scan this dir for additional .ini'
Common locations:
/etc/php/<version>/fpm/php.ini(Debian/Ubuntu)/etc/php.ini+/etc/php.d/(RHEL family)
Apache with mod_php typically uses the same php.ini family as CLI, but confirm by checking the loaded modules:
apachectl -M 2>/dev/null | rg -n 'php'
Common locations:
/etc/php/<version>/apache2/php.ini(Debian/Ubuntu)/etc/php.ini+/etc/php.d/(RHEL family)
OpenLiteSpeed uses LiteSpeed PHP (lsphp) and supports per-vhost overrides, so confirm which PHP handler you use.
Typical config paths:
- Global:
/usr/local/lsws/lsphp*/etc/php/<version>/litespeed/php.ini(varies by package) - Per-vhost overrides:
phpIniOverrideinsidevhconf.conf
If you are unsure, search for php.ini under LiteSpeed's tree:
sudo ls -1d /usr/local/lsws/lsphp*/etc/php/*/litespeed/php.ini 2>/dev/null || true
Common WordPress-related settings
These values are the most common reasons for WordPress admin issues (uploads failing, timeouts during imports, memory errors).
| Setting | Why it matters | Typical starting point |
|---|---|---|
memory_limit | PHP memory per request | 256M to 512M |
upload_max_filesize | Max single file upload | 64M to 256M |
post_max_size | Max POST body size | Match or exceed upload_max_filesize |
max_execution_time | Script timeout | 120 to 300 |
max_input_time | Input parsing time | 120 |
max_input_vars | Large forms/menus | 3000 to 10000 |
Edit the file
Editing the wrong php.ini can make you think nothing changed. Always re-check php --ini (CLI) and verify from the web server side after reload.
Use your editor of choice. This example uses nano.
sudo nano /etc/php/8.2/fpm/php.ini
Example changes:
memory_limit = 512M
upload_max_filesize = 256M
post_max_size = 256M
max_execution_time = 300
max_input_vars = 5000
Reload the right service
- PHP-FPM
- Apache
- OpenLiteSpeed
sudo systemctl reload php8.2-fpm
If your service name differs, pick the correct one from systemctl list-units.
sudo systemctl reload apache2
sudo systemctl reload lsws
Verify from the browser (and remove the test)
Create a temporary PHP file that prints the effective runtime values.
cat <<'PHP' | sudo tee /var/www/example.com/html/php-settings-test.php >/dev/null
<?php
header('Content-Type: text/plain');
echo "memory_limit=" . ini_get('memory_limit') . "\n";
echo "upload_max_filesize=" . ini_get('upload_max_filesize') . "\n";
echo "post_max_size=" . ini_get('post_max_size') . "\n";
echo "max_execution_time=" . ini_get('max_execution_time') . "\n";
PHP
Visit:
https://example.com/php-settings-test.php
Then remove the file:
sudo rm -f /var/www/example.com/html/php-settings-test.php
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| Changes don't apply | Edited the wrong php.ini | Re-check PHP handler (FPM vs mod_php vs lsphp) |
| 502/504 errors after changes | FPM not running or config invalid | Revert last change, check FPM logs, restart service |
| Uploads still fail | post_max_size smaller than upload_max_filesize | Increase post_max_size |
| WordPress shows memory errors | WP memory constants or low memory_limit | Raise memory_limit, validate WP constants |