hmsr5a
Last Updated: February 25, 2016
·
17.08K
· rmitchellnet
Kevinbutlerwutdoomastick

Have PHP-FPM Listen On Unix Socket

Here is how you can switch PHP-FPM to listen on a unix socket rather than a TCP socket. For this example I'm also going to show how to make the switch in Nginx.

First, edit the file at /etc/php5/fpm/pool.d/www.conf and find this block:

; The address on which to accept FastCGI requests.
; Valid syntaxes are:
;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific address on
;                            a specific port;
;   'port'                 - to listen on a TCP socket to all addresses on a
;                            specific port;
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
;listen = 127.0.0.1:9000
listen = /var/run/php5-fpm.sock

And make sure the line to listen on the unix socket is not commented out:

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

Let's make some changes in our Nginx configs to tell it to pass requests through the unix socket rather than TCP.

First let's create a file at /etc/nginx/conf.d/ named php5-fpm.conf:

upstream php5-fpm-sock {
    server unix:/var/run/php5-fpm.sock;
}

In our Nginx server config we'll also have to change where to pass PHP requests:

fastcgi_pass php5-fpm-sock;
Say Thanks
Respond
Filed Under