3

Currently have a 502 Bad Gateway Error on my Centos 6.8 Server.

    2017/01/30 23:57:31 [crit] 26911#0: *1 connect() to unix:/var/run/php/php7.0-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 192.168.0.15, server: 192.168.0.$

I checked whether the directory existed and it doesn't. The closest I could find to the folder was /var/run/php-fpm, which only contains php-fpm.pid.

1
  • 4
    php-fpm needs to actually be running. Jan 30, 2017 at 13:21

2 Answers 2

5

Here are the steps to troubleshoot this issue:

  1. Check if php-fpm is running:

    sudo service php-fpm status
    sudo service php7-php-fpm status # use this if you are using remi PHP 7
    
  2. Check for the listen directive in php-fpm’s www.conf configuration file:

    grep -Ri listen /etc/php/7.0/fpm/pool.d/www.conf 
    grep -Ri listen /etc/opt/remi/php70/php-fpm.d # for remi
    
  3. Make sure your nginx fastcgi_pass directive matches your listen directive.

0

For me the setup process is this, after installing nginx from the nginx.org repo:

mkdir -p /var/www/public_html
chown -R nginx:nginx /var/www/public_html
restorecon -rv /var/www
yum install php-fpm
sed -i 's@listen = 127.0.0.1:9000@listen = /var/run/php-fpm/php-fpm.sock@' /etc/php-fpm.d/www.conf
sed -i 's@;listen.owner = [email protected] = nobody@' /etc/php-fpm.d/www.conf
sed -i 's@;listen.group = [email protected] = nobody@' /etc/php-fpm.d/www.conf
sed -i 's@user = apache@user = nginx@' /etc/php-fpm.d/www.conf
sed -i 's@group = apache@group = nginx@' /etc/php-fpm.d/www.conf
systemctl start php-fpm.service
systemctl enable php-fpm.service

Then your host config should be something like:

server
{
    listen 443 ssl;

    root /var/www/public_html;
    index index.php;

    location ~ \.php$
    {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

Then restart nginx and there you go.

You must log in to answer this question.

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