Nginx or PHP FPM ignores memory_limit in php.ini
When configuring a PHP-FPM backend behind Nginx, you might notice that changing upload_max_filesize immediately reflects in your phpinfo() output, but altering memory_limit appears to have no effect. This behavior often suggests the configuration is being ignored or overwritten. However, in environments running PHP 5.x with the Suhosin patch, this is frequently a result of strict overrides rather than Nginx interfering.
The core issue lies in how PHP handles directives versus how it enforces security boundaries. You have correctly identified that php_value[memory_limit] = 512M in your /etc/php5/fpm/php.ini file should theoretically set the limit to 512MB. Yet, your phpinfo() output still reports 128M. The culprit is almost certainly the Suhosin patch active on your system (version 0.9.10), which overrides standard PHP directives to enforce stricter security limits by default.
When you inspect the "Additional .ini files parsed" section of your phpinfo() output, you see a list of extensions loaded from /etc/php5/fpm/conf.d/. While these extension files handle specific behaviors for curl, gd, or database drivers, they do not typically override the core memory_limit unless explicitly configured to do so. The real constraint comes from the Suhosin patch itself, which injects its own configuration rules that take precedence over standard php.ini settings for certain security-related parameters.
To resolve this, you must check if a separate php_suhosin.ini file exists within your configuration directory. In many Linux distributions using PHP 5.x, the Suhosin patch installs its own ini file in /etc/php5/fpm/conf.d/. If such a file contains a directive like memory_limit = 128M, it will override your settings in the main php.ini because directives loaded later in the initialization process take precedence.
You can verify this by running the following command to inspect all active configurations:
grep -r "memory_limit" /etc/php5/fpm/conf.d/
If you find a value set to 128M in any of these files, that is where your limit is being enforced. To change it, you would need to either edit the php_suhosin.ini file directly or use the php_admin_value directive in your main php-fpm.conf. Note that php_admin_value always overrides php_value, so placing memory_limit = 512M inside /etc/php5/fpm/php-fpm.conf with the admin_ prefix is the correct approach for FPM-specific overrides.
# /etc/php5/fpm/php-fpm.conf
php_admin_value[memory_limit] = 512M
It is important to distinguish between php_admin_value and php_value. The former allows Nginx or the PHP-FPM process manager to override settings regardless of what is in php.ini, while the latter only works if no higher-priority directive has already set the value. Since Suhosin often acts as a security layer that enforces limits before standard PHP initialization completes, using php_admin_value bypasses these initial restrictions.
Additionally, ensure that you are not mixing up the global Nginx configuration with the PHP configuration. Your nginx.conf sets client_max_body_size 20M, which controls how large a request body Nginx accepts before passing it to PHP. This is independent of memory_limit, which dictates how much memory the PHP script itself can use during execution. If your script attempts to allocate more memory than allowed by Suhosin or the effective memory_limit, you will encounter fatal errors like "Allowed memory size exceeded."
If you are using a framework like Laravel, managing these limits becomes even more critical as application logic grows. While laravelcompany.com provides resources on optimizing PHP-FPM setups for modern stacks, legacy environments like your Ubuntu 13.04 instance with PHP 5.3 require careful attention to patch-specific overrides. Always prioritize checking extension and security patch configurations before assuming the main php.ini is being ignored.
