Php – Include common configuration in several php5-fpm pools

PHPphp-fpmweb-server

Shortly: how can I include the same settings across several php-fpm pools without repeating them for each pool?

Details

In php5-fpm there are global directives and per pool directives. In all examples and documentation, each pool has all required settings, e.g.

[www]
user = $pool
group = $pool
listen = 127.0.0.1:9001
listen.owner = $pool
listen.group = $pool
pm = ondemand
pm.max_children = 5
pm.process_idle_timeout = 30s
chdir = /var/www/$pool

[www2]
user = $pool
group = $pool
listen = 127.0.0.1:9002
listen.owner = $pool
listen.group = $pool
pm = ondemand
pm.max_children = 5
pm.process_idle_timeout = 30s
chdir = /var/www/$pool

As you can see, most of the configuraton is the same, so I wonder if there is a way to put that configuration in a place where all pools can implicitly or explictly include them.

Just putting them at the bottom of the [Global] section is not working.

Thank you for any suggestion.

Best Answer

After trials and errors, I found that you can safely use the include directive to, well, include settings :-)

I created an additional /etc/php5/fpm/common.conf file:

user = $pool
group = $pool
listen.owner = $pool
listen.group = $pool
pm = ondemand
pm.max_children = 5
pm.process_idle_timeout = 30s
chdir = /var/www/$pool

And now all my pools can be as simple as this:

[www]
listen = 127.0.0.1:9001
include = /etc/php5/fpm/common.conf

[www2]
listen = 127.0.0.1:9002
include = /etc/php5/fpm/common.conf

Additional notes:

  • yes, you have to specify the full path to the common file, because current path for fpm process is NOT the pool.d folder

  • yes, all interpolation is done, so $pool becomes www or www2 at runtime

Hope this could be also useful to someone else.