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

5 Answers 5

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

8
  • Where is located in ubutnu? Aug 19, 2017 at 19:44
  • 1
    I only see php7.0-fpm.pid file Aug 19, 2017 at 19:45
  • 1
    I am running several ubuntus. Default path (I've never changed this): /var/run/php/php7.0-fpm.sock. But again it is depending on the config value and this file should be created if php-fpm is starte.
    – BenRoob
    Aug 19, 2017 at 19:56
  • But there is only one file php7.0-fpm.pid Aug 19, 2017 at 20:13
  • 1
    lol i can understand why Ben gave up! XD yasar did you come right?
    – emotality
    Mar 22, 2018 at 17:46
21
+25

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
4
  • 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 1, 2018 at 9: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 1, 2018 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 4, 2018 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 5, 2021 at 18:49
2

you can see it by running

$ ss --unix |grep 'php' 
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.

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 ='

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.