How to Manage Your php.ini Directives with PHP FPM

Last modified: February 21, 2024


Introduction

This tutorial explains how to manage your php.ini file directives when you enable PHP-FPM. For more information, read our PHP-FPM documentation.

Note:
  • You can edit the php.ini directives at the domain and system level in WHM’s MultiPHP Manager interface (WHM » Home » Software » MultiPHP Manager).
  • cPanel & WHM enables PHP-FPM by default.

Manage the php.ini directives

Confirm that PHP-FPM exists on all of your accounts.

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

  1. Log in to WHM as the root user.
  2. Navigate to WHM’s MultiPHP Manager interface (WHM » Home » Software » MultiPHP Manager).
  3. In the domains table, locate the domain for which to manage the php.ini settings.
  4. Under the PHP-FPM heading, confirm that the toggle is set to On.
Remember:
cPanel & WHM enables PHP-FPM by default.

Create a phpinfo file in the domain’s document root.

You can use the phpinfo files to view a domain’s current PHP settings.

To create this file for the domain, perform the following steps:

  1. SSH in as the root user.
    Note:
    You can also use WHM’s Terminal interface (WHM » Home » Server Configuration » Terminal).
  2. Navigate to the domain’s document root directory.
  3. Create a phpinfo.php file.
  4. With a text editor, add the following information to the file:
    1
    2
    3
    4
    
    <?php
    // Show all information, defaults to INFO_ALL
    phpinfo();
    ?>
  5. Make certain that you perform the following actions:
    • Set the file’s user and group ownership to the cPanel account’s username.
    • Set the file’s permissions to 0644 permissions.
      Note:

      To do this, run the following series of commands:

      1
      2
      
      chmod 0644 /home/username/public_html/phpinfo.php
      chown username.username /home/username/public_html/phpinfo.php
      Where `username` represent's the user's username.
  6. To access the file in your 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.

Review the domain’s php.ini directives.

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

  • Review a domain’s php.ini directives in cPanel’s MultiPHP INI Editor interface (cPanel » Home » Software » MultiPHP INI Editor).
  • Review the global php.ini directives in WHM’s MultiPHP INI Editor interface (WHM » Home » Software » MultiPHP INI Editor).

The system sets the following php.ini directives by default:

1
2
3
4
5
6
7
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

Modify the php.ini directives

Modify the php.ini directives globally

To globally modify the php.ini directives for each PHP version, use WHM’s MultiPHP INI Editor interface (WHM » Home » Software » MultiPHP INI Editor).

To only modify specific php.ini directives for domains with PHP-FPM:

  1. Connect to the server via SSH.
  2. Create the /var/cpanel/ApachePHPFPM directory if it does not already exist.
  3. Create the /system_pool_defaults.yaml file.
  4. With a text editor, add your desired PHP-FPM pools. PHP-FPM pools let you configure websites and applications to run under their own users. For example:
    1
    2
    
    ---
    php_admin_value_memory_limit: { name: 'php_admin_value[memory_limit]', value: 120M }
    Note:
    • This example sets a memory limit of 120 MB.
    • For a complete list of PHP-FPM domain pool directives, read our Configuration Values of PHP-FPM documentation.
  5. Regenerate the PHP-FPM configuration files. To do this, run the following command:
    /usr/local/cpanel/scripts/php_fpm_config --rebuild
  6. Restart Apache and the PHP-FPM services. To do this, run the following commands:
    1
    2
    
    /usr/local/cpanel/scripts/restartsrv_apache_php_fpm
    /usr/local/cpanel/scripts/restartsrv_httpd    

Modify the php.ini directives for an individual domain

To globally modify a domain’s php.ini directives for each PHP version, use cPanel’s MultiPHP INI Editor Editor interface (cPanel » Home » Software » MultiPHP INI Editor).

To only modify specific php.ini directives for a domain:

  1. Connect to the server via SSH.
  2. Create the /var/cpanel/userdata/username/domain.com.php-fpm.yaml file if it does not already exist.
    Note:

    In this example, the username respresents the cPanel user’s username.

  3. With a text editor, add the directives that you want to modify to the file. For example, this file would disable the passthru and system directives:
    1
    2
    3
    
    ---
    _is_present: 1
    php_admin_value_disable_functions: { name: 'php_admin_value[disable_functions]', value: passthru,system }
    This file would enable all directives:
    1
    2
    3
    
    ---
    _is_present: 1
    php_admin_value_disable_functions: { name: 'php_admin_value[disable_functions]', value: none }
    Note:

    For a complete list of PHP-FPM domain pool directives, read our Configuration Values of PHP-FPM documentation.

  4. Regenerate the PHP-FPM configuration files. To do this, run the following command:
/usr/local/cpanel/scripts/php_fpm_config --rebuild
5. Restart Apache and the PHP-FPM services. To do this, run the following commands:
1
2
/usr/local/cpanel/scripts/restartsrv_apache_php_fpm
/usr/local/cpanel/scripts/restartsrv_httpd

Additional Documentation