Report this

What is the reason for this report?

502 Bad gateway when following LEMP install on new droplet

Posted on August 8, 2016

On a new droplet I have been working through the tutorial “How To Install Linux, Nginx, MySQL, PHP (LEMP stack) in Ubuntu 16.04” and am stuck with the php test failing with a 502 bad gateway. I have gone thru several times and can find no errors. Can anyone point me in the right direction?



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

I got some ips blocking my sites, bad gateway error, seems they’re coming from Rusia, China and so on. I have to restart my fpm several times to have my apps up and running. is there any issue with fpm in droplets?

Edit the file /etc/php/7.0/fpm/pool.d/www.conf

And uncomment or add the following lines.

listen.owner = www-data
listen.group = www-data
listen.mode = 0660

If you are running Nginx as a different user, change www-data to that user. By default it will run as www-data.

You may have to delete the file /var/run/php/php7.0-fpm.sock if it exists.

Now run the commands below.

sudo service nginx restart
sudo service php7.0-fpm restart

For those reading post 2022 (Aug) looking for a solution. This issue occurred with NGINX Ubuntu 22.x and the solution was: reinstall/update php from the console:

apt install php8.1-fpm php-mysql

Source: https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-22-04#step-3-installing-php

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.