Newly create LEMP stack running PHP-FPM on Ubuntu 14.04 x64. Attempting to access some PHP in my webroot. Browser is showing 502 Bad Gateway and Nginx error log is showing the following (my IP and production IP removed):

TIME [error] 22838#0: *7 connect() failed (111: Connection refused) while connecting to upstream, client: [my personal IP], server: [production server IP], request: "GET / HTTP/1.1", upstream: "fastcgi://", host: "[production server IP]"

To determine if PHP-FPM is running I execute:

ps -waux | grep php5

And I get back in response:

root     22930  0.0  0.4 327432 16324 ?        Ss   10:10   0:00 php-fpm: master process (/etc/php5/fpm/php-fpm.conf) 

How do I determine what port PHP-FPM is running on or why it isn't running on that port? Thank you.

4 Answers 4


Found it:

In order to specify the port number you would need to edit the "listen =" directive in /etc/php5/fpm/pool.d/www.conf however I discovered that it is theoretically more efficient to allow Nginx to communicate over Unix sockets so I swapped



That was the first step...

I then had to replace the following lines in my sites configuration file (sites-available/default):



fastcgi_pass unix:/var/run/php5-fpm.sock;

And now I am up and running.


If your service (not only PHP-FPM) are listening port, you can determine it by typing sudo netstat -lntp:

# sudo netstat -lntp
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0*               LISTEN      1427/mysqld     
tcp        0      0*               LISTEN      1722/memcached  
tcp        0      0   *               LISTEN      642/smbd        
tcp        0      0    *               LISTEN      21315/nginx     
tcp        0      0  *               LISTEN      25078/php-fpm.conf)

where you can see that PHP-FPM process with pid 25078 uses 81 port.


The problem is having more than 1 config file in /etc/php/7.4/fpm/pool.d

   usr@server:/etc/php/7.4/fpm/pool.d$ ls
      www.conf  foor-php-fpm.conf  bar-php-fpm.conf.bak


Step 1: Remove or rename any other .conf files and leave only www.conf

usr@server:/etc/php/7.4/fpm/pool.d$ sudo mv other-php-fpm.conf other-php-fpm.conf.bak2

Step 2: systemctl restart php7.4-fpm.service


user@server:~$ systemctl status php7.4-fpm.service

● php7.4-fpm.service - The PHP 7.4 FastCGI Process Manager
     Loaded: loaded (/lib/systemd/system/php7.4-fpm.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2020-12-31 16:16:22 UTC; 6s ago
       Docs: man:php-fpm7.4(8)
    Process: 381508 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /run/php/php-fpm.sock /etc/php/7.4/fpm/pool.d/www.conf 74 (code=exited, status=0/SUCCESS)
   Main PID: 381487 (php-fpm7.4)
     Status: "Ready to handle connections"
      Tasks: 3 (limit: 4568)
     Memory: 12.1M
     CGroup: /system.slice/php7.4-fpm.service
             ├─381487 php-fpm: master process (/etc/php/7.4/fpm/php-fpm.conf)
             ├─381506 php-fpm: pool www
             └─381507 php-fpm: pool www

This solution applies to php-fpm-7.2 as well.


RHEL 9.1 / default install included PHP:

NGINX fails while installing WordPress

Symptom: nginx[5700]: nginx: [emerg] no port in upstream "php-fpm" in /etc/nginx/default.d/php.conf:15

...in this case, some install instructions on the internet skip the fact that php-fpm must be installed on RHEL 9. It is not included with the provided PHP install. Without that /var/run/php-fpm/www.sock (autocreated by php-fpm is missing. However, installation of the missing php-fpm still leaves the failure occuring.

The default php.conf file in the section:

location ~ .(php|phar)(/.*)?$ {

has a line...

fastcgi_pass php-fpm;

Unfortunately, it needs (in some cases):

fastcgi_pass /var/run/php-fpm/www.sock

In sum, you need php-fpm AND a path clarification for php.conf's fastcgi section to get back to work.

I post this alternate cause of the error in case it helps someone else!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .