Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!
cPanelResources

Tutorial Managing php.ini directives with PHP-FPM

How to configure PHP values when using PHP-FPM

Tags:
  1. cPanelResources
    Overview
    This resource provides instructions on how to manage php.ini directives when PHP-FPM is installed and enabled as a PHP handler in cPanel & WHM. Background information on how PHP-FPM is implemented with cPanel & WHM is available on our PHP-FPM document. This document includes valuable information about the PHP-FPM filesystem layout, syntax requirements, and the available configuration values.

    Step 1. Verify PHP-FPM is enabled for the domain.
    First, verify PHP-FPM is enabled for a domain by browsing to WHM >> Software >> MultiPHP Manager and finding the domain under the Set PHP Version per Domain section. The PHP-FPM column in the domain’s row will display ON if PHP-FPM is enabled.

    Step 2. Create a PHPINFO file in the domain’s document root.
    PHPINFO files are useful for viewing the current PHP settings on a domain. Use your preferred file management method (SSH, FTP, File Manager) to create a file named phpinfo.php in the domain’s document root (e.g. /home/username/public_html/). The file should contain the following lines:

    Code:
    <?php
    // Show all information, defaults to INFO_ALL
    phpinfo();
    ?>
    Ensure the phpinfo.php file is configured with 0644 permissions. User and group ownership should be set to the corresponding cPanel account’s username. Here's an example of how to do this via the command line:

    Code:
    chmod 0644 /home/username/public_html/phpinfo.php
    chown username.username /home/username/public_html/phpinfo.php
    Once the phpinfo.php file is created, you can open it by accessing domain.tld/phpinfo.php in your web browser. You should see FPM/FastCGI as the Server API value in the output when PHP-FPM is enabled for the domain.

    Step 3. Review the php.ini directives enabled by default with PHP-FPM.
    cPanel & WHM enables the following php.ini directives by default in each domain's PHP-FPM user pool:

    Code:
    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
    These entries take precedence over the values configured using the MultiPHP INI Editor option in cPanel and Web Host Manager. If you intend to modify these specific php.ini directives (allow_url_fopen, log_errors, disable_functions, doc_root, error_log, short_open_tag, or error_reporting), then keep in mind you will need to manually edit PHP-FPM .yaml files using the command line. Information on how to edit the the PHP-FPM .yaml files is available under section B as part of steps 4 and 5 below.

    Step 4. Modify php.ini directives globally.

    A. You can use WHM >> Software >> MultiPHP INI Editor to modify php.ini directives globally for each specific version of PHP. For example, let's say you select ea-php70 as the PHP version, and you modify the memory_limit directive to 99M. Upon saving the change, you should see 99M listed under both the Local Value and Master Value columns in the output when visiting domain.tld/phpinfo.php in your web browser.

    B. PHP-FPM user pool values take precedence over changes made using the MultiPHP INI Editor option in cPanel and Web Host Manager. This is beneficial if you want to configure specific php.ini directives that apply only to domains assigned the PHP-FPM handler. Utilize the following steps to enable default php.ini values that apply to all domains using PHP-FPM:

    1. Use the following command to create the /var/cpanel/ApachePHPFPM directory:

    Code:
    mkdir /var/cpanel/ApachePHPFPM
    2. Use the following command to create the /var/cpanel/ApachePHPFPM/system_pool_defaults.yaml file:

    Code:
    touch /var/cpanel/ApachePHPFPM/system_pool_defaults.yaml
    3. Edit /var/cpanel/ApachePHPFPM/system_pool_defaults.yaml using your preferred command line text editor (e.g. vi, nano). In this example, we want to set the memory_limit value to 120M. Thus, the contents of the /var/cpanel/ApachePHPFPM/system_pool_defaults.yaml file should look exactly like this:

    Code:
    ---
    php_admin_value_disable_functions: { name: 'php_admin_value[memory_limit]', value: 120M }
    
    It's also possible to modify one of the default php.ini directives noted above in Step 3. For instance, here's how /var/cpanel/ApachePHPFPM/system_pool_defaults.yaml should look if you want to replace the default value for the disable_functions directive with passthru,system:

    Code:
    ---
    php_admin_value_disable_functions: { name: 'php_admin_value[disable_functions]', value: passthru,system }
    
    4. Execute the following command to regenerate the PHP-FPM configuration files:

    Code:
    /scripts/php_fpm_config --rebuild
    5. Execute the following commands to restart the Apache and Apache PHP-FPM services:

    Code:
    /scripts/restartsrv_apache_php_fpm
    /scripts/restartsrv_httpd
    6. Open domain.tld/phpinfo.php in your web browser and verify the php.ini directive you modified shows the new value.

    Step 5. Modify php.ini directives for individual domains:

    A. You can use cPanel >> MultiPHP INI Editor to modify php.ini directives individually for domains using PHP-FPM. To do so, select Basic Mode or Editor Mode in cPanel >> MultiPHP INI Editor, and then choose the specific domain from the drop-down field. Next, modify a specific php.ini directive (e.g. memory_limit). Upon saving the change, you should see the new value listed under the Local Value column in the output when visiting domain.tld/phpinfo.php in your web browser.

    B. Individual PHP-FPM user pool values take precedence over changes made using the MultiPHP INI Editor options in cPanel and Web Host Manager, and over the global pool values (configurable using the instructions in step 4 above). Utilize the following steps to enable php.ini values for a specific domain:

    1. Open the corresponding PHP-FPM YAML file for the specific domain using your preferred command line text editor (e.g. vi, nano). EX:

    Code:
    vi /var/cpanel/userdata/username/domain.com.php-fpm.yaml
    Here's how it looks by default:

    Code:
    ---
    _is_present: 1
    2. Modify /var/cpanel/userdata/username/domain.com.php-fpm.yaml to reflect the values for the specific php.ini directives you want to customize. Here's an example of how this file should look if you want to configure passthru,system as the value for the disable_functions directive:

    Code:
    ---
    _is_present: 1
    php_admin_value_disable_functions: { name: 'php_admin_value[disable_functions]', value: passthru,system }
    3. Execute the following command to regenerate the PHP-FPM configuration files:

    Code:
    /scripts/php_fpm_config --rebuild
    4. Execute the following commands to restart the Apache and Apache PHP-FPM services:

    Code:
    /scripts/restartsrv_apache_php_fpm
    /scripts/restartsrv_httpd
    5. Open domain.tld/phpinfo.php in your web browser and verify the php.ini directive you modified shows the new value.

    Caveat - PHP_INI_SYSTEM mode
    PHP assigns php.ini directives with modes that determine the extent to which a directive is changeable. The following PHP documents define these modes and list the mode type for each php.ini directive:

    PHP: Where a configuration setting may be set - Manual
    PHP: List of php.ini directives - Manual

    With this in mind, it's not possible to completely override the php.ini directive values configured in the PHP version's global php.ini file (WHM >> Software >> MultiPHP INI Editor) for directives associated with the PHP_INI_SYSTEM mode, even when directly modifying a PHP-FPM YAML configuration file. For example, let's say the following line is configured for PHP version 7.0 in WHM >> MultiPHP INI Editor >> Editor Mode:

    Code:
    disable_functions = popen,proc_open
    If you were to to setup passthru,system as the value for disable_functions (using option B in Step 5 above), then the actual PHP disabled functions for the domain would include passthru, system, popen, proc_open. Additionally, the PHPINFO output will only display what you've configured in the PHP-FPM YAML file, even though additional PHP functions are disabled. This is an artifact of how PHP and PHP-FPM work as opposed to how each is implemented with cPanel & WHM.

    Questions/Feedback
    If you have questions or feedback about this resource, register an account on the cPanel Forums and open a new thread! We have a team dedicated exclusively to the cPanel Forums to help answer any questions you have.

    Thanks!
    cPanelJesse likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice