After all basic steps of apt install NGINX and PHP on my local (not a server) fresh UBUNTU 18 LTS, localhost is good but basic phpinfo.php script not works: "502 Bad Gateway"

I need all simple and plug-and-play.. Changed /etc/nginx/sites-available/default to

# Default server configuration
server {
        listen 80 default_server;
        listen [::]:80 default_server;
        root /var/www/html;
        index index.php index.html index.htm index.nginx-debian.html;
        server_name _;
        location / {
                try_files $uri $uri/ =404;
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
               fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
               include fastcgi_params;
        location ~ /\.ht {
                deny all;


  • PHP 7.2
  • nginx 1.14


  • sudo chown -R $USER:$USER /var/www; sudo chmod -R 755 /var/www
  • (tested sudo chown -R www-data:www-data /var/www but no error changes)

sudo tail /var/log/nginx/error.log shows

*... 1 connect() to unix:/var/run/php/php7.0-fpm.sock failed (2: No such file or directory) while connecting to upstream, client:, server: _, request: "GET /phpinfo.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock:", host: "localhost"

  • Check if php-fpm creates a socket at location /var/run/php/php7.0-fpm.sock and check if socket is enabled in /etc/php/7.0/fpm/pool.d/www.conf file. The line listen = /run/php/php7.0-fpm.sock should be UNcommented. – Michal Przybylowicz Jul 26 '19 at 17:57
  • 1
    Hi @MichalPrzybylowicz, thanks the suggestion (I see only later sorry). Well, see solution, we not need to change etc/php/7.*/fpm/pool.d/www.conf, it was only a NGINX-script (sites-available) error (at script we can call "php7.2" socket instead "php7.0") – Peter Krauss Jul 26 '19 at 18:30

sudo tail /var/log/nginx/error.log shows ".. unix:/var/run/php/php7.0-fpm.sock...", so we think "... php7.0, is it?".

The standard NGINX suggest to use (uncomment) fastcgi_pass... that is very sensitive to the version. Need a comment there (!). But this solution is not ideal, need to control the PHP port (more configs - is it?)...

So changing the 7.0 of the file sites-available/default, at line fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; to 7.2, solved the problem.

  • Known issue in 18.04's packages, but not SRU-fixable currently on its own. Fixed in later package versions. – Thomas Ward Jul 26 '19 at 17:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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