54

I'm running Wordpress with: Nginx + PHP-FPM + APC + W3 Total Cache + PageSpeed.

After 3 days researching and configuring, I succeeded to make it work. I configured PHP-FPM to run via 127.0.0.1:9000. But now I want to configure via Socket.

The problem is that I can't find the socket path in my server. I just found /var/run/php-fpm/php-fpm.pid, but php-fpm.sock was not there.

Running whereis php-fpm the output is:

php-fpm: /usr/sbin/php-fpm /etc/php-fpm.d /etc/php-fpm.conf /usr/share/man/man8/php-fpm.8.gz

But there isn't any php-fpm.sock there.

How can I find php-fpm.sock?

My specs:

  • Amazon Micro EC2
  • Linux version 3.4.48-45.46.amzn1.x86_64 Red Hat 4.6.3-2 (I think it's based on CentOS 5)
  • PHP 5.3.26 (fpm-fcgi)
Machavity
  • 30,841
  • 27
  • 92
  • 100
Márcio
  • 753
  • 1
  • 6
  • 12
  • Just as an FYI, `Linux version 3.4.48-45.46.amzn1.x86_64` or similar is [Amazon Linux](https://aws.amazon.com/amazon-linux-ami/). It's based on CentOS, and is compatible with those packages, but is not quite the same thing. – Machavity Jul 26 '17 at 14:40
  • `grep '^listen' /etc/php/7.2/fpm/pool.d/www.conf` – mpen Nov 10 '19 at 01:00

6 Answers6

75

I know this is old questions but since I too have the same problem just now and found out the answer, thought I might share it. The problem was due to configuration at pool.d/ directory.

Open

/etc/php5/fpm/pool.d/www.conf

find

listen = 127.0.0.1:9000

change to

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

Restart both nginx and php5-fpm service afterwards and check if php5-fpm.sock already created.

Freedom_Ben
  • 11,247
  • 10
  • 69
  • 89
Fath
  • 859
  • 6
  • 4
  • Everything was telling me to change to 127.0.0.1:9000 this finally told me the right way and the file was created and everything worked :) – Simon Pollard Jun 10 '16 at 14:26
  • 1
    I don't have such folder `/etc/php5/fpm/pool.d/www.conf`... I have PHP7 installed, not 5 – vsync Apr 29 '18 at 18:46
  • 2
    found the answer somewhere else! You do **not** need to change the line `listen = 127.0.0.1:9000` at all!!!! i have php7 and you simply should use `fastcgi_pass 127.0.0.1:9000;` in your server config file – vsync Apr 29 '18 at 19:23
  • @vsync LOL, are you sure about this? I have been on the same misery for ages. Everyone is saying to change the `www.conf` but I can't find where the `..fpm.sock` file is located. are you sure? – entegra Jul 17 '19 at 13:37
  • @entegra - I don't remember anymore, my last comment is over a year old, sorry – vsync Jul 28 '19 at 15:11
  • For RHEL, CentOS, and other RPM distributions, try: `/etc/php-fpm.d/www.conf` – J.W.F. May 14 '20 at 20:12
  • It works on php 7.4 for me, i think it should work for every other versions `listen = /var/run/php{version}-fpm.sock` – ramons03 Feb 21 '21 at 13:32
  • After the change, i discovered the need of multiple listeners, this [configuration](https://www.digitalocean.com/community/tutorials/how-to-host-multiple-websites-securely-with-nginx-and-php-fpm-on-ubuntu-14-04) helped me. – ramons03 Feb 21 '21 at 13:47
22

I faced this same issue on CentOS 7 years later

Posting hoping that it may help others...

Steps:

FIRST, configure the php-fpm settings:

-> systemctl stop php-fpm.service

-> cd /etc/php-fpm.d

-> ls -hal (should see a www.conf file)

-> cp www.conf www.conf.backup (back file up just in case)

-> vi www.conf

-> :/listen = (to get to the line we need to change)

-> i (to enter VI's text insertion mode)

-> change from listen = 127.0.0.1:9000 TO listen = /var/run/php-fpm/php-fpm.sock

-> Esc then :/listen.owner (to find it) then i (to change)

-> UNCOMMENT the listen.owner = nobody AND listen.group = nobody lines

-> Hit Esc then type :/user = then i

-> change user = apache TO user = nginx

-> AND change group = apache TO group = nginx

-> Hit Esc then :wq (to save and quit)

-> systemctl start php-fpm.service (now you will have a php-fpm.sock file)

SECOND, you configure your server {} block in your /etc/nginx/nginx.conf file. Then run:systemctl restart nginx.service

FINALLY, create a new .php file in your /usr/share/nginx/html directory for your Nginx server to serve up via the internet browser as a test.

-> vi /usr/share/nginx/html/mytest.php

-> type o

-> <?php echo date("Y/m/d-l"); ?> (PHP page will print date and day in browser)

-> Hit Esc

-> type :wq (to save and quite VI editor)

-> open up a browser and go to: http://yourDomainOrIPAddress/mytest.php (you should see the date and day printed)

specialk1st
  • 1,717
  • 21
  • 20
  • Thank you very much this worked for me. However I also had to change the `listen.owner` and `listen.group` from `nobody` to `nginx` otherwise this will result (13 permission denied) – Selvesan Malakar Jun 05 '22 at 09:42
13

Check the config file, the config path is /etc/php5/fpm/pool.d/www.conf, there you'll find the path by config and if you want you can change it.

EDIT:
well you're correct, you need to replace listen = 127.0.0.1:9000 to listen = /var/run/php5-fpm/php5-fpm.sock, then you need to run sudo service php5-fpm restart, and make sure it says that it restarted correctly, if not then make sure that /var/run/ has a folder called php5-fpm, or make it listen to /var/run/php5-fpm.sock cause i don't think the folder inside /var/run is created automatically, i remember i had to edit the start up script to create that folder, otherwise even if you mkdir /var/run/php5-fpm after restart that folder will disappear and the service starting will fail.

Mohammad AbuShady
  • 40,884
  • 11
  • 78
  • 89
  • In my "www.conf" was configured "listen = 127.0.0.1:9000". There aren't any sockt path... If I config "/var/run/php-fpm/php-fpm.sock" in that file, and put this patsh in "nginx.conf" I get "Bad Gatway" (I think it's because the "/var/run/php-fpm/php-fpm.sock" is not there) – Márcio Jul 10 '13 at 17:46
  • 2
    The folder `/var/run/php-fpm/` was already created. But the only file inside that folder was `php-fpm.pid`. I created an empty file called `php-fpm.sock` configure nginx and php-fpm, but without success. I think the problem is that I don't have the `.sock` file. But how can I get it? – Márcio Jul 10 '13 at 22:06
  • 1
    ok let me make something clear, the sock file isn't some file that you create, when the service is started successfully it creates the file, did you try to start the service like i said? try running `sudo service php5-fpm status` it probably would say that it isn't running, did you check the error log to see why it isn't starting ? – Mohammad AbuShady Jul 10 '13 at 22:33
  • Yeah... the service is up. I can see Nginx connecting with PHP-FPM using 'top'. But the problem is that even starting the service it didn't created the '.sock'. I'm using Amazon Micro (CentOS 5), don't know if something is different there – Márcio Jul 11 '13 at 12:05
  • Instead of listen = /var/run/php5-fpm/php5-fpm.sock this listen = /var/run/php5-fpm.sock solved the problem for me. – Sinan Eldem Nov 27 '13 at 10:24
  • This still doesn't solve the problem. Could someone clarify what series of paths need to exist where? – PKHunter Sep 05 '15 at 02:37
  • what exactly is your "problem", what is your setup, what is your distro, instead of downvoting a working answer for someone else try asking your own question with your own config – Mohammad AbuShady Sep 06 '15 at 08:50
  • you just saved me a shit load of trouble, thanks. i had to create the `php-fpm` dir inside `/srv/http/run` in my case – blamb Jan 23 '16 at 01:04
8

Solved in my case, i look at

sudo tail -f /var/log/nginx/error.log

and error is php5-fpm.sock not found

I look at sudo ls -lah /var/run/

there was no php5-fpm.sock

I edit the www.conf  

sudo vim /etc/php5/fpm/pool.d/www.conf

change

listen = 127.0.0.1:9000

for

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

and reboot

Mdev
  • 81
  • 1
  • 2
0

When you look up your php-fpm.conf

example location:
cat /usr/src/php/sapi/fpm/php-fpm.conf

you will see, that you need to configure the PHP FastCGI Process Manager to actually use Unix sockets. Per default, the listen directive` is set up to listen on a TCP socket on one port. If there's no Unix socket defined, you won't find a Unix socket file.

; 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 IPv4 address on
;                            a specific port;
;   '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
;                            a specific port;
;   'port'                 - to listen on a TCP socket to all IPv4 addresses on a
;                            specific port;
;   '[::]:port'            - to listen on a TCP socket to all addresses
;                            (IPv6 and IPv4-mapped) 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
kaiser
  • 21,817
  • 17
  • 90
  • 110
0

I encounter this issue when I first run LEMP on centos7 refer to this post.

I restart nginx to test the phpinfo page, but get this

http://xxx.xxx.xxx.xxx/info.php is not unreachable now.

Then I use tail -f /var/log/nginx/error.log to see more info. I find is the php-fpm.sock file not exist. Then I reboot the system, everything is OK.

Here may not need to reboot the system as Fath's post, just reload nginx and php-fpm.

restart php-fpm

reload nginx config

Community
  • 1
  • 1
LF00
  • 27,015
  • 29
  • 156
  • 295