Need help to manage php.ini directives with PHP FPM? We can help you.
Here, at Bobcares, we assist several of our customers with this query as part of our Server Management Services.
Today, let us see an effective method our techs suggest in order to manage php.ini directives with PHP FPM.
php.ini directives and PHP FPM
If we want to modify php.ini directives at the domain and system level, we can perform this from WHM’s MultiPHP Manager interface. This is applicable if cPanel & WHM version is 78 or later.
To do that, go to, WHM >> Home >> Software >> MultiPHP Manager
However, changes made through the MultiPHP Manager interface will not reflect, if we enable PHP FPM.
PHP-FPM (FastCGI Process Manager) is fast. If we want to be able to handle lots of requests then we should at least test out PHP-FPM’s performance.
We can think of PHP-FPM as a more advanced/refined version of FCGI, or FastCGI. If we enable PHP FPM, then PHP FPM user pool default values replace the MultiPHP as well as php.ini values.
On the other hand, in cPanel & WHM version 76 and later, PHP-FPM is enabled by default.
How to manage php.ini directives
Moving ahead, we will see an effective method our Support Engineers finds the best fit in order to manage php.ini directives with PHP FPM.
Step 1: Confirm whether PHP-FPM exists on all accounts.
To confirm that PHP-FPM exists, we perform the following steps:
- Log in to WHM as the root user.
- Then navigate to WHM’s MultiPHP Manager interface (WHM >> Home >> Software >> MultiPHP Manager).
- In the Domains table, locate the domain for which to manage php.ini settings.
- Finally, under the PHP-FPM heading, confirm that the toggle is set to On.
Step 2: Create a phpinfo file in the domain’s document root.
We use phpinfo files to view a domain’s current PHP settings. To create this file for the domain, we perform the following steps:
- SSH in as the root user.
Similarly, we can also use WHM’s Terminal interface (WHM >> Home >> Server Configuration >> Terminal). - Then navigate to the domain’s document root directory.
- Now create a phpinfo.php file.
- Then with a text editor, add the following information to the file:
<?php // Show all information, defaults to INFO_ALL phpinfo(); ?>
- We make certain that we perform the following actions:
a) Set the file’s user and group ownership to the cPanel account’s username:chown username.username /home/username/public_html/phpinfo.php
b) Set the file’s permissions to 0644 permissions:
chmod 0644 /home/username/public_html/phpinfo.php
Where username represents the user’s username.
- To access the file in our web browser, navigate to https://example.com/phpinfo.php, where example.com is the domain.
If PHP-FPM exists on the domain, the browser will display FPM/FastCGI as the ServerAPI key’s value.
Step 3: Review the domain’s php.ini directives.
We can review php.ini directives in either of the following interfaces:
- Review a domain’s php.ini directives in cPanel’s MultiPHP Manager interface (cPanel >> Home >> Software >> MultiPHP INI Editor).
- Review the global php.ini directives in WHM’s MultiPHP Manager interface (WHM >> Home >> Software >> MultiPHP INI Editor).
The system sets the following php.ini directives by default:
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/username/public_html”
php_admin_value[error_log] = /home/username/logs/domain_com.php.error.log
php_admin_value[short_open_tag] = on
php_value[error_reporting] = E_ALL & ~E_NOTICE
Step 4: Modify php.ini directives
Step 4. (a): Modify php.ini directives globally
To globally modify php.ini directives for each PHP version, we use WHM’s MultiPHP Manager interface (WHM >> Home >> Software >> MultiPHP INI Editor).
To only modify specific php.ini directives for domains with PHP-FPM:
- Initially, we connect to the server via SSH.
- Then we create the
/var/cpanel/ApachePHPFPM
directory if it does not already exist. - Here, create the
/system_pool_defaults.yaml
file. - With a text editor, we add PHP-FPM pools. PHP-FPM pools configure websites and applications to run under their own users.
For example:php_admin_value_memory_limit: { name: ‘php_admin_value[memory_limit]’, value: 120M }
This example sets a memory limit of 120 MB.
- Then we regenerate the PHP-FPM configuration files. To do this, we run the following command:
/usr/local/cpanel/scripts/php_fpm_config –rebuild
- Finally, restart Apache and the PHP-FPM services. To do this, we run the following commands:
/usr/local/cpanel/scripts/restartsrv_apache_php_fpm /usr/local/cpanel/scripts/restartsrv_httpd
Step 4. (b): Modify php.ini directives for an individual domain
To globally modify a domain’s php.ini directives for each PHP version, we use cPanel’s MultiPHP INI Editor Editor interface (cPanel >> Home >> Software >> MultiPHP INI Editor).
To only modify specific php.ini directives for a domain:
- First, we connect to the server via SSH.
- Then we create the
/var/cpanel/userdata/username/domain.com.php-fpm.yaml
file if it does not already exist. In this example, the username represents the cPanel user’s username. - With a text editor, we add the directives that we want to modify to the file.
For example, this file would disable thepassthru
and system directives:_is_present: 1 php_admin_value_disable_functions: { name: ‘php_admin_value[disable_functions]’, value: passthru,system }
This file would enable all directives:
_is_present: 1 php_admin_value_disable_functions: { name: ‘php_admin_value[disable_functions]’, value: none }
- Regenerate the PHP-FPM configuration files. To do this, we run the following command:
/usr/local/cpanel/scripts/php_fpm_config –rebuild
- Finally, restart Apache and the PHP-FPM services. To do this, we run the following commands:
/usr/local/cpanel/scripts/restartsrv_apache_php_fpm /usr/local/cpanel/scripts/restartsrv_httpd
[Couldn’t manage the directives? We can help you!]
Conclusion
To conclude, if we have a busy site and want to be able to handle lots of requests then we should test out PHP-FPM’s performance. Today we saw how our Support Engineers go about with this query.
0 Comments