Best PHP-FPM Settings for Better Optimization

By Stermy 4 Min Read

In this Tech (Technology post, Townflex will be sharing with you guys the best way, settings to optimize your site for PHP-FPM.

But before we proceed with Best PHP-FPM Settings for Better Optimization, we will first run you through a quick guide as to what PHP-FPM is, and how to set in up in your WHM panel (Install The Software).

How to Enable PHP-FPM Using WHM

What Is PHP-FPM?

PHP-FPM is an improved PHP handler that uses a pool of workers (per domain) to quickly process PHP scripts. Once the script completes running, PHP-FPM provides the results to Apache to deliver to the visitor’s browser.

We're now on WhatsApp. Click here to join.

This along with strategic caching, results in faster load times during unexpected spikes in traffic. In this guide, you will learn the steps needed to enable PHP-FPM through Web Host Manager (WHM).

Steps/How To Enable PHP-FPM Using WHM

  • Log into WHM, as the root user.
  • In the WHM search bar, type “php“.
  • Click the MultiPHP Manager menu option.
  • Under the section labeled Set PHP Version per Domain find the domain you want to enable PHP-FPM for and click the checkbox to the left of it. Then, select On from the PHP-FPM drop-down menu and click the Apply button.

Congratulations! Now you know how to enable PHP-FPM for your cPanel users’ websites.

PHP-FPM Settings for Better Optimization

After enabling PHP-FPM (PHP-FastCGI Process Manager) on your VPS, you’ll need to know how to restart the PHP-FPM service and modify its settings. Below we cover how to adjust PHP-FPM settings according to traffic load per cPanel account.

Best PHP-FPM Settings Steps

        • Login WHM as Root
        • From the menu, search and select MulitiPHPManager.
        • Select Turn on to enable PHP-FPM for all cPanel accounts. Alternatively, you can select the checkbox beside specific domains at the bottom, choose On from the dropdown menu beside PHP-FPM, and select Apply.
          You can also change the PHP version here instead of in cPanel.

      1

      • Select Pool Options beside the specified domain.
      • Modify PHP-FPM settings for the domain. Below are commonly successful changes according to amount of traffic your VPS receives.

     

Traffic LoadAverageHeavy
Max Children25-3540-60
Process Idle Timeout100100-150
Max Requests200-350400-600

PHP-FPM

Edit Default PHP-FPM Settings

If you have many cPanel accounts, you may prefer to change the default settings for newly created cPanel accounts.

  1. As root, SSH into your server or launch WHM terminal.
  2. Create a system_pool_defaults.yaml file in the /var/cpanel/ApachePHPFPM directory. To do this using nano, type the following:
    nano /var/cpanel/ApachePHPFPM/system_pool_defaults.yamlAdd the following to the new file:php_value_error_reporting: 'E_ALL'
    pm_max_children: 500
    pm_max_requests: 2000
    pm_min_spare_servers: 1
    pm_max_spare_servers: 25
    pm_process_idle_timeout: 150
    php_value_disable_functions: 0

    pm_max_children:
     Max number of child processes
    pm_max_requests: Number of requests a child process executes before respawning.
    pm_min_spare_servers: Minimum idle server processes
    pm_max_spare_servers: Maximum idle server processes
    pm_process_idle_timeout: Time until an idle process is killed in s(econds), m(inutes), m(inutes), h(ours), or d(ays).
    php_value_disable_functions: Functions to disable. This doesn’t overwrite php.ini settings.
  3. Save and exit the file. Using nano, press Control and x for the save prompt before exiting. Press y, then Enter ⤶ to save the file.
  4. Rebuild PHP-FPM using the following command:
    /scripts/php_fpm_config --rebuild
  5. Restart PHP-FPM using the following command:
    /scripts/restartsrv_apache_php_fpm

    Note: You can also restart PHP-FPM from WHM.

Subscribe To Our YouTube Channel Townflex TV

Source: Townflex.com

Share This Article
By Stermy
Follow:
Stermy is one Crazy fan of the word "Internet". Always online to stay informed and keep others updated. #townflex