5

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.

2
  • You mean like in global section? Commented Dec 7, 2015 at 16:13
  • If I just add pm configuration at the end of the main "php-fpm.conf" file, it is not included. I get the process manager is missing (static, dynamic or ondemand). I guess that's because that's a "per pool" type of setting. Commented Dec 7, 2015 at 16:31

1 Answer 1

11

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.

4
  • any idea why it doesn't work on php-fpm7.2? I get: ERROR: [/etc/php-fpm-7.2.d/common.conf:1] unknown entry 'user' Commented Nov 7, 2018 at 16:13
  • 1
    @NizarBlond according to current documentation user is still a valid entry: php.net/manual/en/install.fpm.configuration.php. So I guess something else must be wrong in your configuration file. Commented Nov 8, 2018 at 8:30
  • I was trying to override it inside pool config but included file seems not to get overriden. Any ideas? Commented Feb 11, 2021 at 22:26
  • @Baterka only a guess, but if you want to override something which is already defined in the common config, you should put the include directive at the top and THEN add the overrides. Honestly, I never tested that. Let us know how it works out for you so we can extend the answer accordingly. Commented Feb 12, 2021 at 10:05

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.