Troubleshooting PHP-FPM and Nginx: 502 Bad Gateway Issue on Ubuntu / Debian / Mint

September 10, 2016 | By the+gnu+linux+evangelist.

Solving PHP-FPM and NGINX: 502 Bad Gateway Error on Linux

The Step-by-step Troubleshooting shows you How to Solve the PHP-FPM and NGINX: 502 Bad Gateway Issue on Linux Ubuntu/Debian-based Systems.

Usually this Misbehavior is due to an Improper Ownership of the NGINX Server

Troubleshooting PHP-FPM and NGINX: 502 Bad Gateway Issue on Ubuntu / Debian / Mint - Featured
  1. Give the Right Permissions to NGINX.

    sudo usermod -a -G www-data nginx
  2. Set to Listen FastCgi on 127.0.0.1:9000.

    cat /etc
    ginx/conf.d/default.conf

    Confronts with:

    server {
    listen 80 default_server;
    listen [::]:80 default_server;
    
    root /var/www/html;/nindex index.php index.html index.htm;
    
    server_name YOURIPADDRESS;
    
    # pass the PHP scripts to FastCGI server at /var/run/php5-fpm.sock
    location ~ ^/index\.php(/|$) {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;/ninclude fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_param  HTTPS              off;
    }
    
    }
    

    And then:

    cat /etc/apache2/conf-available/php5-fpm.conf

    Setting the Host parameter as below:

    
    AddHandler php5.fcgi .php
    Action php5.fcgi /php5.fcgi
    Alias /php5.fcgi /usr/lib/cgi-bin/php5.fcgi
    FastCgiExternalServer /usr/lib/cgi-bin/php5.fcgi -host 127.0.0.1:9000 -pass-header Authorization -idle-timeout 3600
    
    Require all granted
    
      
    
  3. Finally, Restart php5-fpm & nginx Services.

    sudo service php5-fpm restart && sudo service nginx restart

QuickChic Theme • Powered by WordPress