2

I want to set only one listening unix socket for all php-fpm pools, but fpm requires them to be different.

Production server has 2GB ram and I noticed that it is running out of RAM, adding more websites spawn more fpm processes. I am the only user on this server, so i don't need to limit resources per pool just want to set common config settings for all.

One domain pool as follows:

  [domain.com]
    user = www
    group = www
    listen = /tmp/domain.com-php-fpm.sock
    security.limit_extensions = .php .html

   ;Resources
   pm = dynamic
   pm.max_children = 9
   pm.start_servers = 3
   pm.min_spare_servers = 2
   pm.max_spare_servers = 4
   pm.process_idle_timeout = 60s
   request_terminate_timeout = 30s
   pm.max_requests = 300

   ;Log errors
   catch_workers_output = yes
   php_flag[display_errors]   = on
   php_admin_value[error_log] = /var/log/www/domain.com/php-error.log

   ;Base dirs
   php_admin_value[open_basedir] = /usr/local/www/domain.com
   php_admin_value[upload_tmp_dir] = /usr/local/www/domain.com/tmp 
   php_admin_value[session.save_path] = /usr/local/www/domain.com/tmp

Another pool is the same, except domain name. So then if I set same listening socket for both pools it doesn't work

# php-fpm --test
[12-Sep-2013 22:27:01] ERROR: [pool domain.com] unable to set listen address as it's already used in another pool 'domain2.com'
[12-Sep-2013 22:27:01] ERROR: failed to post process the configuration
[12-Sep-2013 22:27:01] ERROR: FPM initialization failed

And if set different sockets, it works, but each pool spawn minimum 3 process. (Sure, this is not an output from real server, just simulated same behavior).

# ps aux | grep php-fpm
root   1349   0.0  0.9 161376 18320 ??  Ss   10:34PM   0:00.02 php-fpm: master process (/usr/local/etc/php-fpm.conf) (php-fpm)
www    1350   0.0  0.9 161336 18292 ??  S    10:34PM   0:00.00 php-fpm: pool domain2.com (php-fpm)
www    1351   0.0  0.9 161336 18292 ??  S    10:34PM   0:00.00 php-fpm: pool domain2.com (php-fpm)
www    1352   0.0  0.9 161336 18292 ??  S    10:34PM   0:00.00 php-fpm: pool domain2.com (php-fpm)
www    1353   0.0  0.9 161336 18292 ??  S    10:34PM   0:00.00 php-fpm: pool domain.com (php-fpm)
www    1354   0.0  0.9 161336 18292 ??  S    10:34PM   0:00.00 php-fpm: pool domain.com (php-fpm)
www    1355   0.0  0.9 161336 18292 ??  S    10:34PM   0:00.00 php-fpm: pool domain.com (php-fpm)

My intention is to keep running 3 php-fpm processes for all pools.

Demontager
  • 73
  • 1
  • 2
  • 8
  • If you only need one pool, why are you running more than one? – Michael Hampton Sep 12 '13 at 20:13
  • Because i guess this is only way to separate php scripts by using php_admin_value[open_basedir] value. That means if one website hacked, they can't move up and infect others. Another thing is per website logs. If it possible, could you please share such config with one pool ? – Demontager Sep 12 '13 at 20:30
  • OK, so you really do need separate pools. They must have separate sockets; you can't get around this. – Michael Hampton Sep 12 '13 at 20:31
  • That's i afraid the most, so sad. Let's assume i may live without per website logs and same time need to chroot each website. Is anything could I try ? I never tried these following options, maybe they can help -; ;chroot = ;chdir = /var/www – Demontager Sep 12 '13 at 20:44
  • What are you trying to do?! I can't think of any real reason to even attempt this. – Michael Hampton Sep 12 '13 at 20:58
  • See i have some experience in setting nginx as frontend and apache as backend on one server and in such case i may chroot every website in apache vhost config using basedir value and moreover i may adjust similiar to nginx's "pm.*" apache's StartServers, MinSpareThreads, MaxSpareThreads, ThreadLimit, ThreadsPerChild, MaxClients, MaxRequestsPerChild values and they will be applied for all websites. – Demontager Sep 12 '13 at 21:08
  • You would change the `PM = dynamic` option to `PM= static` and statically assign the resources. You currently have 9 php-fpm pools on start up (if all have the same config as above) and it can potentially grow to 27! There really is no reason to use the dynamic option if you already know the limit of your hardware. – AWippler May 16 '16 at 03:17

1 Answers1

1

You can have each nginx server block point at same socket and in the /etc/nginx/fastcgi_params there are the lines:

fastcgi_param   DOCUMENT_URI        $document_uri;
fastcgi_param   DOCUMENT_ROOT       $document_root;

These will cause the document root from your nginx server block to be passed through to php-fpm.

server {
    root /var/www/<%= @title %>/public;
    ...
}

You should then omit the line php_admin_value[open_basedir] = /usr/local/www/domain.com from your php-fpm pool config file.

I believe nginx can do a similar thing to change the log, session and uploads directory, or you can change the error, session and upload handler in php to log to a relative path based on your document root.