Skip to main content

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.

Quick Summary
  • Find the active config with php --ini and (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, or lsws).
  • 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.

show-php-cli-ini.sh
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.

find-php-fpm-service.sh
systemctl list-units --type=service | rg -n 'php.*fpm'

If your distro provides a versioned binary, this shows the loaded file:

show-php-fpm-loaded-ini.sh
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)

These values are the most common reasons for WordPress admin issues (uploads failing, timeouts during imports, memory errors).

SettingWhy it mattersTypical starting point
memory_limitPHP memory per request256M to 512M
upload_max_filesizeMax single file upload64M to 256M
post_max_sizeMax POST body sizeMatch or exceed upload_max_filesize
max_execution_timeScript timeout120 to 300
max_input_timeInput parsing time120
max_input_varsLarge forms/menus3000 to 10000

Edit the file

warning

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.

edit-php-ini.sh
sudo nano /etc/php/8.2/fpm/php.ini

Example changes:

php-ini-wordpress-snippet.ini
memory_limit = 512M
upload_max_filesize = 256M
post_max_size = 256M
max_execution_time = 300
max_input_vars = 5000

Reload the right service

reload-php-fpm.sh
sudo systemctl reload php8.2-fpm

If your service name differs, pick the correct one from systemctl list-units.

Verify from the browser (and remove the test)

Create a temporary PHP file that prints the effective runtime values.

create-php-config-test-file.sh
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:

remove-php-config-test-file.sh
sudo rm -f /var/www/example.com/html/php-settings-test.php

Troubleshooting

SymptomLikely causeFix
Changes don't applyEdited the wrong php.iniRe-check PHP handler (FPM vs mod_php vs lsphp)
502/504 errors after changesFPM not running or config invalidRevert last change, check FPM logs, restart service
Uploads still failpost_max_size smaller than upload_max_filesizeIncrease post_max_size
WordPress shows memory errorsWP memory constants or low memory_limitRaise memory_limit, validate WP constants