502 Bad gateway when following LEMP install on new droplet

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?

Show comments

Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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


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 = 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