Report this

What is the reason for this report?

Bad Gateway and php5-fpm.sock fail

Posted on March 7, 2015

I’m totally lost. I had a working droplet, but had to create a new one in conjunction with CloudFlare to shield the IP from DDOS. I took a snapshot of the existing droplet, created a new droplet from the snapshot, set up CloudFlare to point to the IP for the new droplet, and I get Gateway 502 error messages.
Error log shows: [error] 908#0: *38633558 connect() to unix:/var/run/php5-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client

So at Support’s suggestion, I gave command: sudo service php5-fpm restart

But no joy. Same error message and gateway error.

Ran command again, and it returned another process number, but still no joy and same error msg about php5-fpm.sock failure

I don’t know what to do or how else to check anything. I really am new to this and SSH. The droplet shows it’s Ubuntu, if that helps. Heck, I don’t even know what tags to use for this request.

Ideas?



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.

Hi, I’m experiencing the exact same problem, not sure how to fix it. I already restart a couple of times service php5-fpm restart.

the ls -lah /var/run/php5-fpm.sock is returning: www-data www-data 0 Dec 22 22:18 /var/run/php5-fpm.sock

and the status is running.

I already have cloudflare and 5 droplets connected. And I’m getting same error.

This is affecting our current website a lot.

Any help on this?

Thanks

Heya,

A 502 Bad Gateway error typically indicates that the gateway/proxy (in your case, Nginx) received an invalid response from the upstream server it tried to access (which seems to be PHP-FPM in your situation).

The error message you’re seeing suggests that Nginx is attempting to connect to PHP-FPM using a Unix socket at /var/run/php5-fpm.sock, but it can’t establish a connection. This could be due to PHP-FPM not running, the socket file not existing, or permission issues.

Here are some steps to troubleshoot the issue:

  1. Check PHP-FPM Status: Check if PHP-FPM is running:
sudo service php5-fpm status

If it’s not running, try to start it:

sudo service php5-fpm start
  1. Check PHP-FPM Socket File: If PHP-FPM is running, check if the socket file exists at /var/run/php5-fpm.sock. If it doesn’t, there might be a configuration issue.

  2. PHP-FPM Configuration:

    • Verify that the PHP-FPM pool configuration (usually located at /etc/php5/fpm/pool.d/www.conf or similar) has the listen directive set to /var/run/php5-fpm.sock.
    • Ensure the user and group in the PHP-FPM configuration match the user and group that Nginx is running under.
    • After making changes to the configuration, restart PHP-FPM.
  3. Nginx Configuration:

    • Check the Nginx configuration for your site (typically found in /etc/nginx/sites-available/ directory) and ensure that the fastcgi_pass directive points to the correct socket file:
fastcgi_pass unix:/var/run/php5-fpm.sock;
  • After making changes, test the configuration with sudo nginx -t and if successful, reload Nginx: sudo service nginx reload.
  1. File Permissions:

    • Check the permissions of the socket file and ensure that Nginx has permission to read and write to it.
    • The permissions should allow the user that Nginx runs as (usually www-data) to access the socket.
  2. Logs:

    • Check both the Nginx error logs (/var/log/nginx/error.log) and the PHP-FPM logs for any additional information.
    • The PHP-FPM log might give you more insights into why the connection is failing.
  3. Resources:

    • A “Resource temporarily unavailable” error might indicate a resource limit issue. Check the server’s resources (CPU, memory) and consider whether the PHP-FPM pm.max_children setting is too low.
  4. Cloudflare:

    • Make sure that Cloudflare’s IP ranges are whitelisted in your firewall.
    • Verify that there’s no IP conflict between Cloudflare’s settings and your server.

If you have recently migrated your droplet or changed configurations, ensure that all paths and settings are consistent with the new environment. If you keep hitting a wall, consider reaching out to DigitalOcean support again with the latest details and steps you have taken.

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.