Manage php.ini directives with PHP FPM - How to do it ?



Are you trying to manage php.ini directives with PHP FPM ?

This guide is for you.


The “FPM” part in PHP stands for “Fast Process Manager”, which is just a fancy way of saying that the PHP running on a server isn't a single process, but rather some PHP processes that are spawned, controller, and killed off by this FPM process manager.

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform PHP related configuration tasks.

In this context, we will look into the steps to manage php.ini directives with PHP FPM.


More about 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 ?

Let us apply the following tips to manage php.ini directives with PHP FPM.


1. Confirm whether PHP-FPM exists on all accounts.

To confirm that PHP-FPM exists, we perform the following steps:

i. Log in to WHM as the root user.

ii. Then navigate to WHM’s MultiPHP Manager interface (WHM >> Home >> Software >> MultiPHP Manager).

iii. In the Domains table, locate the domain for which to manage php.ini settings.

iv. Finally, under the PHP-FPM heading, confirm that the toggle is set to On.


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:

i. SSH in as the root user.

Similarly, we can also use WHM’s Terminal interface (WHM >> Home >> Server Configuration >> Terminal).

ii. Then navigate to the domain’s document root directory.

iii. Now create a phpinfo.php file.

iv. Then with a text editor, add the following information to the file:

<?php
// Show all information, defaults to INFO_ALL
phpinfo();
?>

v. 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.

vi. 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.


3. Review the domain’s php.ini directives.

We can review php.ini directives in either of the following interfaces:

i. Review a domain’s php.ini directives in cPanel’s MultiPHP Manager interface (cPanel >> Home >> Software >> MultiPHP INI Editor).

ii. 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


4. Modify php.ini directives

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:

i. Initially, we connect to the server via SSH.

ii. Then we create the /var/cpanel/ApachePHPFPM directory if it does not already exist.

iii. Here, create the /system_pool_defaults.yaml file.

iv. 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.

v. Then we regenerate the PHP-FPM configuration files. To do this, we run the following command:

/usr/local/cpanel/scripts/php_fpm_config –rebuild

vi. 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


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:

i. First, we connect to the server via SSH.

ii. 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.

iii. With a text editor, we add the directives that we want to modify to the file.

For example, this file would disable the passthru 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 }

iv. Regenerate the PHP-FPM configuration files. To do this, we run the following command:

/usr/local/cpanel/scripts/php_fpm_config –rebuild

v. 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 Apache directives Configuration? We can help you!]


Conclusion

This article will guide you on how to manage PHP-FPM for a busy site and want to be able to handle lots of #requests.


Related Post


Keep In Touch

We hope to hear from you.

Accept File Type: jpg,jpeg,png,txt,pdf,doc,docx