Nginx + PHP5-FPM – Bad Gateway Error

Posted on June 24, 2014 by Destry Hines

Server Crash

Yesterday I updated a bunch of programs on one of my Ubuntu servers and brought the server crashing to a stop. After the upgrade there were several problems and it took me 4 hours to figure out what was going wrong. I couldn’t have done it without a ton of help from my friend Duke.

Here were the symptoms:

  • The web server was running because I could get to static HTML pages and images but I could not hit PHP pages.
  • PHP pages would return a Bad Gateway Error.
  • The PHP5-FPM service would not start

Here were the fixes that needed to be done:

http://stackoverflow.com/questions/10470109/error-502-in-nginx-php5-fpm

Changed it from unix socket to TCP socket so it’s now listening on 127.0.0.1:7777

One of the things that helped troubleshoot the problem was to look in the Nginx error logs (/var/log/nginx/error.log) to see this:

2014/06/23 14:56:05 [crit] 3328#0: *43 connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream, client: 141.148.121.119, server: www.domainname.com, request: “GET / HTTP/1.1”, upstream: “fastcgi://unix:/var/run/php5-fpm.sock:”, host: “www.domainname.com”, referrer: “http://www.domainname.com/”

This is just a summary so in the future we have a reference. Hopefully it will help others with similar problems.