Bobcares

Manage php.ini directives with PHP FPM – How we do it

by | Dec 30, 2020

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

Manage php.ini directives with PHP FPM

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:

  1. Log in to WHM as the root user.
  2. Then navigate to WHM’s MultiPHP Manager interface (WHM >> Home >> Software >> MultiPHP Manager).
  3. In the Domains table, locate the domain for which to manage php.ini settings.
  4. 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:

  1. SSH in as the root user.
    Similarly, we can also use WHM’s Terminal interface (WHM >> Home >> Server Configuration >> Terminal).
  2. Then navigate to the domain’s document root directory.
  3. Now create a phpinfo.php file.
  4. Then with a text editor, add the following information to the file:
    <?php
    // Show all information, defaults to INFO_ALL
    phpinfo();
    ?>
  5. 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.

  6. 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:

  1. Initially, we connect to the server via SSH.
  2. Then we create the /var/cpanel/ApachePHPFPM directory if it does not already exist.
  3. Here, create the /system_pool_defaults.yaml file.
  4. 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.

  5. Then we regenerate the PHP-FPM configuration files. To do this, we run the following command:
    /usr/local/cpanel/scripts/php_fpm_config –rebuild
  6. 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:

  1. First, we connect to the server via SSH.
  2. 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.
  3. 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 }
  4. Regenerate the PHP-FPM configuration files. To do this, we run the following command:
    /usr/local/cpanel/scripts/php_fpm_config –rebuild
  5. 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.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF