When working with Nginx and PHP-FPM, a common frustration occurs when editing php.ini
settings like post_max_size
and upload_max_filesize
- the changes simply don't appear in phpinfo()
output. Here's what's really happening:
# This shows the CLI PHP configuration
php -i | grep "post_max"
post_max_size => 20M => 20M
# While phpinfo() shows FPM configuration
PHP maintains separate configurations for different SAPI (Server API) modes:
- CLI:
/etc/php5/cli/php.ini
- FPM:
/etc/php5/fpm/php.ini
- Additional .ini files: Loaded from
/etc/php5/fpm/conf.d/
Here's the step-by-step approach to ensure your changes take effect:
# 1. Edit the correct php.ini
sudo nano /etc/php5/fpm/php.ini
# 2. Modify these values:
post_max_size = 20M
upload_max_filesize = 18M
# 3. Check for overrides in conf.d
grep -r "post_max_size" /etc/php5/fpm/conf.d/
# 4. Restart services properly
sudo service php5-fpm restart
sudo service nginx restart
# 5. Verify with both methods
php -i | grep "post_max_size"
# And check phpinfo() in browser
Case 1: Changes made to CLI php.ini instead of FPM
Solution: Always modify /etc/php5/fpm/php.ini
for web applications
Case 2: PHP-FPM not properly restarted
Solution: Use sudo service php5-fpm restart
instead of reload
Case 3: Nginx fastcgi cache interfering
Solution: Clear Nginx cache if configured:
sudo rm -rf /var/run/nginx-cache/*
sudo service nginx reload
Create a test script to verify active configuration:
<?php
// config_test.php
header('Content-Type: text/plain');
echo "post_max_size: ".ini_get('post_max_size')."\n";
echo "upload_max_filesize: ".ini_get('upload_max_filesize')."\n";
?>
Run it both via CLI and web:
php config_test.php
curl http://localhost/config_test.php
When working with Nginx + PHP-FPM setups, a common frustration occurs when editing php.ini
parameters like:
post_max_size = 20M
upload_max_filesize = 18M
only to find phpinfo() still showing default 8M values after service restarts. The root cause lies in PHP's dual configuration system.
Key diagnostic commands reveal the conflict:
# CLI shows one config path
php -i | grep "Configuration File"
# While phpinfo() shows another
php -r "phpinfo();" | grep "php.ini"
This happens because:
/etc/php5/cli/php.ini
controls command-line PHP/etc/php5/fpm/php.ini
governs PHP-FPM processes
To properly apply changes:
# 1. Edit the correct file
sudo nano /etc/php5/fpm/php.ini
# 2. Modify both directives
upload_max_filesize = 20M
post_max_size = 22M
# 3. Full service restart sequence
sudo service php5-fpm restart
sudo service nginx reload
Scan for overriding settings in:
/etc/php5/fpm/conf.d/*.ini
/etc/php5/fpm/pool.d/*.conf
Example pool override:
; /etc/php5/fpm/pool.d/www.conf
php_admin_value[post_max_size] = 8M
php_admin_value[upload_max_filesize] = 8M
Verify changes through multiple methods:
# Method 1: CLI check
php -r "echo ini_get('upload_max_filesize');"
# Method 2: Create test.php
<?php
phpinfo(INFO_MODULES);
?>
# Method 3: Direct FPM query
sudo php5-fpm -i | grep max_filesize
Remember that Nginx itself doesn't cache PHP configurations - this is purely a PHP-FPM service configuration matter.