22

I have a simple project with directory structure

I am setting up nginx config for my drupal site, and for the fastcgi_pass I have been using 127.0.0.1:9000 but I want to use a unix socket as suggested in this conf:

 # PHP 7 socket location.
   fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;

but I can't find php/php7.0-fpm.sock;

I have the following path in my centos distro

/var/run/php-fpm/php-fpm.pid
hidar
  • 5,449
  • 15
  • 46
  • 70

5 Answers5

26

Check the php-fpm config where the socket will be created with:

$ cat /etc/php/7.0/fpm/pool.d/www.conf

Look for listen, for example:

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

php-fpm creates the socket file after you started the process.

sudo service php7.0-fpm stop
sudo service php7.0-fpm start

Check the directory if socket file was created:

$ cd /run/php && ls -la

emotality
  • 12,795
  • 4
  • 39
  • 60
BenRoob
  • 1,662
  • 5
  • 22
  • 24
21

First check if php-fpm is running on your system, for doing this you could use pgrep for example:

# pgrep -fa php-fpm
5666 php-fpm: master process (/etc/php-fpm.conf)
5667 php-fpm: pool www
5668 php-fpm: pool www
5669 php-fpm: pool www
5670 php-fpm: pool www
5671 php-fpm: pool www

In this case, it shows is up and running and using the configuration file /etc/php-fpm.conf. Before checking the configuration file and trying to check for the listen = directive you could quickly look into /proc/net/unix for example:

# grep php /proc/net/unix

Which may return something like:

ffff8800bfb2f400: 00000002 00000000 00010000 0001 01 28561 /tmp/php-fpm.sock

In this case, it shows that the path for the php-fpm socket is located in /tmp/php-fpm.sock the one could be verified by checking the conf in /etc/php-fpm.d/www.conf in this case being: listen= /tmp/php-fpm.sock

In case you don't get any result and php-fpm is up and running, by checking the configuration you may find that is using the defaults by listing on a TCP socket:

listen = 127.0.0.1:9000

Something you could change to listen on a Unix socket like your suggested conf:

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

In some Linux distros normally this is used:

listen.owner = www-data
listen.group = www-data
listen.mode = 0660

After modifying your configuration don't forget to restart the services systemctl restart php-fpm. To check that the socket has been created you could do:

$ file /var/run/php/php7.0-fpm.sock

If socket exists if should print out something like this:

/var/run/php/php7.0-fpm.sock: socket
nbari
  • 25,603
  • 10
  • 76
  • 131
  • Just to get it right and clear, what is the difference to the other answer? Ok, different paths in centOS. But what else? I thought, I've read somewhere, that it is not recommended to point the socket to /tmp because of security reasons. – BenRoob Aug 01 '18 at 09:42
  • 2
    @BenRoob mainly focus on finding the location of the socket on a running system something that can be useful also when debugging – nbari Aug 01 '18 at 12:58
  • 1
    @BenRoob The currently top voted answer fails to address the case when the configuration uses IP:PORT over a socket, in which case the file obviously would not exist. – SeinopSys Aug 04 '18 at 13:53
  • Much better than accepted, millions thanks :) "sudo vim /etc/php-fpm.d/www.conf" and got "listen = /run/php-fpm/www.sock" so added "fastcgi_pass unix:/run/php-fpm/www.sock;" in nginx instead "fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock" – Nono Feb 05 '21 at 18:49
2

you can see it by running

$ ss --unix |grep 'php' 
Breign
  • 146
  • 8
1

It is likely that an older libpcre3 is installed and satisfies the dependency in the php7.0 package, but only the newer library package provides pcre_jit_stack_free.

If this is the case, do an apt-get install libpcre3, and you’re good to go.

Ref.: https://github.com/oerdnj/deb.sury.org/issues/372

I hope this helps you.

rahul singh Chauhan
  • 323
  • 1
  • 4
  • 15
0

Use this:

cat /etc/php/7.0/fpm/pool.d/www.conf | grep 'listen ='

Output example: listen = /run/php/php7.2-fpm.sock

Or for universal php vesions:

cat /etc/php/$(php -r "echo PHP_VERSION;" | grep --only-matching --perl-regexp "7.\d+")/fpm/pool.d/www.conf | grep 'listen ='