Configuring php-fpm

This guide does not attempt to provide a complete detailed instruction on how to configure php-fpm, but rather give a few pointers on things you should change after a fresh installation. I will assume you have the default php5-fpm.conf file that comes with the dotdeb php5.3 installation.

php5-fpm.conf

This file contains settings relating to the FastCGI porcess manager and its processes.

One of the main advantages with using nginx is the ability to use unix sockets instead of TCP sockets. To make php-fpm listen to a unix socket, change the line

listen = 127.0.0.1:9000

to

listen = /var/run/php5-fpm.sock

By default, php-fpm is configured to run in dynamic mode. This means that php-fpm itself can decide how many processes to run at any given time, depending on the number of requests it get.

You can set it to static, or modify the number of child processes created on startup, the maximum amount of children, and the number of spare servers by changing these lines:

; Choose how the process manager will control the number of child processes.
; Possible Values:
;   static  - a fixed number (pm.max_children) of child processes;
;   dynamic - the number of child processes are set dynamically based on the
;             following directives:
;             pm.max_children      - the maximum number of children that can
;                                    be alive at the same time.
;             pm.start_servers     - the number of children created on startup.
;             pm.min_spare_servers - the minimum number of children in 'idle'
;                                    state (waiting to process). If the number
;                                    of 'idle' processes is less than this
;                                    number then some children will be created.
;             pm.max_spare_servers - the maximum number of children in 'idle'
;                                    state (waiting to process). If the number
;                                    of 'idle' processes is greater than this
;                                    number then some children will be killed.
; Note: This value is mandatory.
pm = dynamic

; The number of child processes to be created when pm is set to 'static' and the
; maximum number of child processes to be created when pm is set to 'dynamic'.
; This value sets the limit on the number of simultaneous requests that will be
; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
; CGI.
; Note: Used when pm is set to either 'static' or 'dynamic'
; Note: This value is mandatory.
pm.max_children = 50

; The number of child processes created on startup.
; Note: Used only when pm is set to 'dynamic'
; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
pm.start_servers = 20

; The desired minimum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.min_spare_servers = 5

; The desired maximum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.max_spare_servers = 35

You can enable logging of slow requests for debugging purposes by uncommenting and editing this line:

;slowlog = log/$pool.log.slow

There are more settings you should check out, especially chrooting php.

This entry was posted in System administration and tagged , , , . Bookmark the permalink.

2 Responses to Configuring php-fpm

  1. Sergey says:

    listen = /var/run/php5-fpm.sock

    I have no such a file php5-fpm.sock
    I got only php-fpm.pid there. How to set this socket

    • The socket will be created by php-fpm automatically.

      Enter your desired path (make sure you have write access), restart php-fpm and it should be there.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>