From GoBlueMich Wiki
Jump to navigation Jump to search

FPM on cPanel

cPanel Docs on FPM

  • EA4 and FPM

  • Table of values supported by cPanel

User Level Changes

Required files

Use the following required files only if you wish to run PHP-FPM:


This file controls a specific domain's pool.

First, it uses the built-in default values, then the system_pool_defaults values, and lastly, generates the [domain].conf file.


Optional files

Use the following optional files only if you wish to to change the default parameters:


This file contains system level settings.

The system also uses this file to generate the /opt/cpanel/ea-php?/root/etc/php-fpm.conf file.


The systems uses this file to generate each domain's pool.

For example, the /opt/cpanel/ea-php5?/root/etc/php-fpm.d/[domain].conf domain.


The system does not require the presence of these files to run since the built-in defaults enable the PHP-FPM to run sufficiently. Within these files you include different directives from the built-in values.


  • After making changes, rebuild the conf files from the yaml files then restart PHP-FPM. Can rebuild for a single domain or all.
/usr/local/cpanel/scripts/php_fpm_config (--domain=$DOMAIN) 
/scripts/restartsrv apache_php_fpm

Tuning child processes for PHP-FPM

Borrowed from:

  • Problem:

The following warning message appears in the logs:

[26-Jul-2012 09:49:59] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 8 idle, and 58 total children [26-Jul-2012 09:50:00] WARNING: [pool www] server reached pm.max_children setting (50), consider raising it

It means that there are not enough PHP-FPM processes.

  • Solution:

We need to calculate and change these values based on the amount of memory on the system:

pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35

- the following command will help us to determine the memory used by each (PHP-FPM) child process:

ps -ylC php-fpm --sort:rss

The RSS column shows non-swapped physical memory usage by PHP-FPM processes in kilo Bytes.


[root@host ~]# ps -ylC php-fpm --sort:rss
S     0   8610      1  0  80   0 30820 112916 ep_pol ?       00:00:00 php-fpm
S  1001   8618   8610  0  80   0 63464 139269 skb_re ?       00:00:04 php-fpm
S  1001   8620   8610  1  80   0 69756 142428 skb_re ?       00:00:05 php-fpm
S  1001   8622   8610  1  80   0 71352 142370 skb_re ?       00:00:05 php-fpm
S  1001   8619   8610  1  80   0 75012 141427 skb_re ?       00:00:06 php-fpm
S  1001   8621   8610  1  80   0 77128 141345 skb_re ?       00:00:06 php-fpm

On an average each PHP-FPM process took ~64MB of RAM on my machine.

Appropriate value for pm.max_children can be calculated as:

pm.max_children = Total RAM dedicated to the web server / Max child process size

If a server has 8GB of RAM, so:

pm.max_children = 6144MB / 64MB = 96

I left some memory for the system to breath. You need to take into account any other services running on the machine while calculating memory usage.

I’ve changed the settings as follow:

pm.max_children = 96
pm.start_servers = 0
pm.min_spare_servers = 5
pm.max_spare_servers = 30
pm.max_requests = 100000

Please note that very high values does not mean necessarily anything good.

You can check an average memory usage by single PHP-FPM process with this handy command:

ps --no-headers -o "rss,cmd" -C php-fpm | awk '{ sum+=$1 } END { printf ("%d%s\n", sum/NR/1024,"M") }'


[root@host ~]# ps --no-headers -o "rss,cmd" -C php-fpm | awk '{ sum+=$1 } END { printf ("%d%s\n", sum/NR/1024,"M") }'