Manage PHP.ini Directives with PHP FPM on cpanel can be useful for altering PHP configurations to specific application requirements. When using PHP-FPM alongside cPanel, the process becomes more streamlined and efficient.PHP-FPM (FastCGI Process Manager) significantly elevates PHP performance and provides more granular control over PHP settings. This blog post will take you through the steps for managing php.ini directives on a cPanel server using PHP-FPM.
Prerequisites
- A cPanel account with root access.
- PHP-FPM enabled on your server.
- Basic knowledge of how to use the cPanel interface
1. Enabling PHP-FPM in cPanel
Before managing php.ini directives, ensure PHP-FPM is enabled for your domain:
i. For this, First Log in to WHM
ii. Then, Navigate to MultiPHP Manager and select User Domain settings.
iii. In the domain section, Select your domain and check whether “PHP-FPM” is enabled for the domain, if not then enable it.
2. php.ini File
It is always important to understand the current PHP configuration. You can find the existing php.ini file by creating a PHP info page.
Now, Create a file named phpinfo.php in your web root directory. Here I am using the root directory as: /home/testdomain.com/public_html/
#cd /home/testdomain.com/public_html/
# vim phpinfo.php
Add the following content to the file:
<?php
phpinfo();
?>
After changing the necessary file permissions, Access this file via your web browser (e.g., http://testdomain.com/phpinfo.php).
In the page, Verify that PHP_FPM is active or not.
3. Review and Modify php.ini Directives
You can review the domain’s php.ini directives in cPanel’s MultiPHP INI Editor interface (cPanel » Home » Software » MultiPHP INI Editor).
In WHM, you can review this in (WHM » Home » Software » MultiPHP INI Editor). You can find the system set default php.ini directive there.
For Global Modifications:
First, SSH into your server.
And then look for /var/cpanel/ApachePHPFPM/system_pool_defaults.yaml. If it does not already exist, create it.
To modify the.yaml file, use the following command:
#vim /var/cpanel/ApachePHPFPM/system_pool_defaults.yaml
Add the desired PHP-FPM pools and directives. for example you can set the memory limit of 120 MB by adding the following:
php_admin_value_memory_limit: { name: 'php_admin_value[memory_limit]', value: 120M }
For Modifying specific php.ini directives for a domain,
Create the file /var/cpanel/userdata/username/testdomain.com.php-fpm.yaml, then edit it with a text editor to add the directives you want to modify.
for example, to disable the passthru and system directives, use:
#vim /var/cpanel/userdata/username/testdomain.com.php-fpm.yaml
_is_present: 1
php_admin_value_disable_functions: { name: 'php_admin_value[disable_functions]', value: passthru,system }
To enable all the directives, using the following:
_is_present: 1
php_admin_value_disable_functions: { name: 'php_admin_value[disable_functions]', value: none }
4. Regenerate the configuration and restart the services
After the modifications has been made, Regenerate the php-fpm configuration:
#/usr/local/cpanel/scripts/php_fpm_config --rebuild
Restart the apache and php-fpm services for the changes to take effect:
#/usr/local/cpanel/scripts/restartsrv_apache_php_fpm
#/usr/local/cpanel/scripts/restartsrv_httpd
By following these steps, you can effectively manage your PHP settings, ensuring optimised performance.
If you have any questions or need personalized assistance with “How to Manage PHP.ini Directives with PHP FPM on a cPanel Server” , don’t hesitate to reach out Skynats.