In this post, let’s take a look at the option for setting a php_value when using PHP‑FPM.
.user.ini Files
The first option for setting php_value
s is to use .user.ini files. For the Magento project in question this was just a matter of dropping a .user.ini in the root next to index.php and .htaccess with the following example.
error_reporting = E_ALL & ~E_NOTICE
This works quite well and is the top answer to the Stack Overflow question “Equivalent of php_value under Apache + php-fpm “
Note that there is some caching at play with .user.ini files, so you might not see your changes right away. From the PHP documentation…
user_ini.cache_ttl
controls how often user INI files are re-read. The default is 300 seconds (5 minutes).
PHP-FPM conf Files
Another place ```php_value````s can be set is within PHP-FPM conf files. The default www.conf
file explains how this works…
; Additional php.ini defines, specific to this pool of workers. These settings
; overwrite the values previously defined in the php.ini. The directives are the
; same as the PHP SAPI:
; php_value/php_flag - you can set classic ini defines which can
; be overwritten from PHP call 'ini_set'.
; php_admin_value/php_admin_flag - these directives won't be overwritten by
; PHP call 'ini_set'
; For php_*flag, valid values are on, off, 1, 0, true, false, yes or no.
A couple things here are interesting…
- Notice the language ‘These settings overwrite the values previously defined in the php.ini’. This includes
.user.ini
, so ifphp_value
s are set in PHP-FPM conf files,.user.ini
overrides don’t work. - Also, notice the language ‘these directives won’t be overwritten by PHP call ‘ini_set’’. In other words there’s no way to override settings defined via
php_admin_value
andphp_admin_flag
.
In order adjust error_reporting
through a PHP-FPM conf file I’d create a new file named e.g. 99-user.conf
with the following example :
php_value[error_reporting] = E_ALL & ~E_NOTICE
The .htaccess Option
There is an .htaccess
option outlined in another answer to the “Equivalent of php_value under Apache + php-fpm” Stack Overflow question.
The following example can be added to .htaccess…
SetEnv PHP_VALUE "error_reporting = 2039"
However, this has a major limitation in that you can only set one PHP_VALUE
this way, because if you tried to to do…
SetEnv PHP_VALUE "error_reporting = 2039"
SetEnv PHP_VALUE "post_max_size = 16M"
…the second line would override the PHP_VALUE
environment variable value from the first line, preventing the first line from actually working.