PHP7.0-FPM and Nginx don't work using unix sockets

tlito asked:

I have a trouble that is not described in the web. I am using VPS Debian 8 Nginx + PHP7.0-FPM. My server gives php-files in a source code and does not compile them when I configure Nginx and PHP7.0-FPM to use unix sockets (I do it cause I’ve read it works faster then tcp connections).

So what I really do and it does not work:

  1. edit /etc/nginx/fastcgi_params to comment fastcgi_pass parameter to use unix socket file:

all my hosts include this file, so I need to configure own socket in each host file. I do it like this:

  1. edit /etc/nginx/sites-available/ I type fastcgi_pass parameter there
location ~ '\.php$|^/update.php' {
fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
fastcgi_pass      unix:/var/run/php/;
        include             /etc/nginx/fastcgi_params;

        fastcgi_param       SCRIPT_FILENAME     /var/www/$fastcgi_script_name;
        fastcgi_param       DOCUMENT_ROOT       /var/www/;

        fastcgi_param       PHP_ADMIN_VALUE     upload_tmp_dir=/var/www/;
        fastcgi_param       PHP_ADMIN_VALUE     session.save_path=/var/www/;
  1. edit main php7.0-fpm pool file /etc/php/7.0/fpm/pool.d/www.conf to listen socket (but now I cannot understand why i need it here):

    listen = /var/run/php/php7.0-fpm.sock

  2. edit my site’s pool file /etc/php/7.0/fpm/pool.d/ to set up it own socket (so here it is necessary I think):

    listen = /var/run/php/

  3. restart services:

    service nginx restart && service php7.0-fpm restart

so this get my index.php downloading as it is when I visit any site page.

But if I use tcp socket fastcgi_pass; it works fine.

My answer:

What’s going on with the overly complicated location?

location ~ '\.php$|^/update.php' {

I expect that your requests are not actually matching this.

All you really need is:

location ~ \.php$ {

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.