PHP-FPM PHP.ini configuration
As it's not exactly clear from the docs, I want to share my learnings with regards to configuring PHP.ini values when using PHP-FPM.
The good news is that most values can be set using the MultiPHP INI Editor in WHM. Edits made here are reflected in the corresponding local.ini file for the chosen version of PHP:
/opt/cpanel/ea-php[version]/root/etc/php.d/local.ini
Infuriatingly though, some values will not change regardless of the values you enter here or directly in this file, most notably those relating to error reporting. This is because they are controlled by the .conf file for each PHP-FPM pool.
These files are located at:
/opt/cpanel/ea-php[version]/root/etc/php-fpm.d/[domain].conf
Inside these files you will find a number of php.ini values like so:
php_admin_flag[allow_url_fopen] = on
php_admin_flag[log_errors] = on
php_admin_value[disable_functions] = exec,passthru,shell_exec,system
php_admin_value[doc_root] = "/home/[account]/public_html"
php_admin_value[error_log] = /home/[account]/logs/[domain].php.error.log
php_admin_value[error_reporting] = E_ALL & ~E_NOTICE
php_admin_value[short_open_tag] = on
Unfortunately you cannot edit these files directly, as they are generated by cPanel so any changes may be overwritten.
To change them you must edit the corresponding yaml template file, located here:
/var/cpanel/userdata/[account]/[domain].php-fpm.yaml
Inside these files you can set any of the pool directive values listed here:
Configurations Values of PHP-FPM - Documentation - cPanel Documentation
Use the form:
pool_directive_key : value
So for example, to disable notice, warning, strict and deprecated errors:
php_admin_value_error_reporting: E_ALL & ~E_NOTICE & ~E_WARNING & ~E_STRICT & ~E_DEPRECATED
Finally, you will need to get cPanel to rebuild the config files and restart PHP-FPM. To do that run this command:
/scripts/php_fpm_config --rebuild
A word of warning: should you use WHM > MultiPHP Manager to change values for each pool, you will find that cPanel unhelpfully rebuilds the conf files without using your customised yaml templates. This has been reported as a bug to cPanel, hopefully they will fix it in a later release.
Another oddity: it is not possible to change the value of error_reporting at runtime using the PHP function error_reporting() when using PHP-FPM 5.6.x. This DOES work in PHP 7.0 however. I don't know why.
Finally, if anyone knows how to change the default values for each version of PHP, rather than having to edit for each domain, please let me know.
-
A word of warning: should you use WHM > MultiPHP Manager to change values for each pool, you will find that cPanel unhelpfully rebuilds the conf files without using your customised yaml templates. This has been reported as a bug to cPanel, hopefully they will fix it in a later release.
This is handled via internal case EA-5615. You can monitor the Change Logs to see when the resolution is published: Change Logs - Change Logs - cPanel DocumentationAnother oddity: it is not possible to change the value of error_reporting at runtime using the PHP function error_reporting() when using PHP-FPM 5.6.x. This DOES work in PHP 7.0 however. I don't know why.
Could you let us know the full steps you took to change the value?Finally, if anyone knows how to change the default values for each version of PHP, rather than having to edit for each domain, please let me know.
The following document explains how this works: PHP-FPM Code and FileSystem Layout for EasyApache 4 - Documentation - cPanel Documentation Thank you.0 -
? Another oddity: it is not possible to change the value of error_reporting at runtime using the PHP function error_reporting() when using PHP-FPM 5.6.x. This DOES work in PHP 7.0 however. I don't know why. Could you let us know the full steps you took to change the value? Compile Apache (event mpm) + PHP-FPM 5.6 and 7.0 with EA4. Set an account to use PHP-FPM 5.6. Create a file test.php in the webroot of this account, and add this to it: error_reporting(0); phpinfo(); Result: PHP info will report a non-zero value for error_reporting. Switch the account to PHP-FPM 7.0 and you will see error_reporting is set to 0 in PHP info. 0 -
Compile Apache (event mpm) + PHP-FPM 5.6 and 7.0 with EA4. Set an account to use PHP-FPM 5.6. Create a file test.php in the webroot of this account, and add this to it: error_reporting(0); phpinfo(); Result: PHP info will report a non-zero value for error_reporting.
Feel free to open a support ticket using the link in my signature so we can take a closer look at the affected system. You can post the ticket number here so we can update this thread with the outcome. Thank you.0 -
Any news about this? We still have YAML files reset every time.
Hello, There's no update to report at this time, but I will continue to monitor the case and provide updates as they become available. Thank you. Update: This looks to have related to a flaw in how the syntax was entered in the PHP-FPM configuration file. The following warning was added to our0
Please sign in to leave a comment.
Comments
5 comments