When you have multilple PHP-FPM pools configured on the server you usually store the configurations under /etc/php-fpm.d. When you have a lot of sites this directory starts looking pretty crowded.
Although when you look inside the typical PHP-FPM pool configuration file you can easily notice that there about only 4 lines that make a difference – everything else is absolutely identical.
Lets take a look at typical PHP-FPM pool configuration file, lets say /etc/php-fpm.d/site1.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
[site1] listen = 127.0.0.1:9006 user = site1 group = site1 listen.allowed_clients = 127.0.0.1 pm = dynamic pm.max_children = 35 pm.start_servers = 5 pm.min_spare_servers = 5 pm.max_spare_servers = 15 pm.max_requests = 150 listen.backlog = -1 pm.status_path = /status request_terminate_timeout = 180s rlimit_files = 131072 rlimit_core = unlimited catch_workers_output = yes env[HOSTNAME] = $HOSTNAME env[TMP] = /dev/shm env[TMPDIR] = /dev/shm env[TEMP] = /dev/shm |
As you can see only first 4 lines are distinguishing the rest is common for all the pools. So we can create configuration include file for the directives that are common for all pools
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
listen.allowed_clients = 127.0.0.1 pm = dynamic pm.max_children = 35 pm.start_servers = 5 pm.min_spare_servers = 5 pm.max_spare_servers = 15 pm.max_requests = 150 listen.backlog = -1 pm.status_path = /status request_terminate_timeout = 180s rlimit_files = 131072 rlimit_core = unlimited catch_workers_output = yes env[HOSTNAME] = $HOSTNAME env[TMP] = /dev/shm env[TMPDIR] = /dev/shm env[TEMP] = /dev/shm |
And place it as /etc/php-fpm.d/params-common and then explicitely include in our PHP-FPM pool config files as follows
1 2 3 4 5 |
[site2] listen = 127.0.0.1:9007 user = site2 group = site2 include = /etc/php-fpm.d/params-common |
The advantage of this approach is that you can quickly adjust various parameters that could affect sites performance with editing just single file.
Before setting this configuration into effect don’t forget to verify the configuration by running
1 |
php-fpm -t |
0 Comments.