2

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:
#fastcgi_pass 127.0.0.1:9000; 

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/example.com I type fastcgi_pass parameter there
location ~ '\.php$|^/update.php' { fastcgi_split_path_info ^(.+?\.php)(|/.*)$; fastcgi_pass unix:/var/run/php/example.com.php7.0-fpm.conf; include /etc/nginx/fastcgi_params; fastcgi_param SCRIPT_FILENAME /var/www/example.com/www$fastcgi_script_name; fastcgi_param DOCUMENT_ROOT /var/www/example.com/www; fastcgi_param PHP_ADMIN_VALUE upload_tmp_dir=/var/www/example.com/tmp/upload; fastcgi_param PHP_ADMIN_VALUE session.save_path=/var/www/example.com/tmp/sessions; } 
  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/example.com.conf to set up it own socket (so here it is necessary I think):

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

  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 127.0.0.1:9000; it works fine.

2
  • do not know why my question has no answers that help me. all my server configs are here tlito.ru/node/697 please what is wrong? Commented Sep 7, 2016 at 23:30
  • I have the same problem, and the video for some reason tells to use 127.0.0.1:9000; instead of /var/run/php/php7.0-fpm.sock I wonder why? Commented Dec 3, 2018 at 1:27

3 Answers 3

3

It looks like you have the wrong filename for fastcgi_pass it should be:

fastcgi_pass unix:/var/run/php/example.com.php7.0-fpm.sock; 

Make sure that php-fpm is running and that the socket file exists and has the correct permissions for nginx to access the file. If you have selinux installed and enforcing, you might also need to check its logs to see if it is blocking nginx from accessing the file.

On php-fpm's side, each of those configuration files in pool.d is a separate pool of PHP executables and each needs its own socket. www.conf is not a "main" configuration file, it's a completely separate pool of processes and should be disabled/removed if you are not using it. With both pools configured to use the same socket, there is certainly a conflict here.

3
  • I don't believe this is what's going on. If he had a problem with this, he would be getting 502 Bad Gateway errors. Commented Sep 7, 2016 at 0:03
  • I had 502 errors when I configured wrong filename, it was, yes, but now it is not. Commented Sep 7, 2016 at 7:01
  • I've made 777 permissions for socket file and it's owner and group is www-data - this user is in nginx.conf Commented Sep 7, 2016 at 23:27
2

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$ { 
3
  • I tried. did not help Commented Sep 7, 2016 at 23:27
  • You'll need to post the complete server block, then. Commented Sep 8, 2016 at 0:24
  • here tlito.ru/node/697 Commented Sep 8, 2016 at 10:03
0

Unix sockets have permissions

The socket connecting php and nginx is created by php7.2-fpm service in accordance with the config

sudo nano /etc/php/7.2/fpm/pool.d/www.conf 

this file has

listen = /run/php/php7.2-fpm.sock listen.owner = www-data listen.group = www-data 

once you start/restart this service

sudo systemctl restart php7.2-fpm.service 

it creates a file that represents a socket with the specified owner and group

ls -la /run/php 

BUT Nginx is using another user by default, you can veify it in

sudo nano /etc/nginx/nginx.conf 

user nginx;

Now it is up to you, how you want to adjust permissions. Either give more permissions to you socket file, or change a listening user, or change nginx user... you pick your answer.

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.