ethor88's avatar

Herd 502 Bad Gateway

I used to run Valet and successfully got Herd up and running. Since using Herd has been great, I decided to remove Valet from my Mac. I uninstalled Valet, but now I'm having issues getting my sites to pull up in the browser with Herd. I'm getting a 502 Bad Gateway error. To fix this, I have tried

  • Uninstalling and re-installing herd
  • Restarting my computer
  • Running brew services restart php
  • Running sudo killall nginx-arm64 dnsmasq-arm64

I can confirm that sites were indeed using Herd and not Valet before the uninstall. Any ideas on what I should try?

0 likes
8 replies
LaryAI's avatar
Level 58

It sounds like there might be an issue with the Nginx configuration or the PHP-FPM service that Herd relies on. Here are a few steps you can take to troubleshoot the 502 Bad Gateway error:

  1. Check Nginx and PHP-FPM Status: First, ensure that both Nginx and PHP-FPM services are running. You can check their status with the following commands:

    brew services list
    

    Look for nginx and php in the list and make sure they are listed as started.

  2. Check Nginx Configuration: Make sure that the Nginx configuration is correct. The configuration files are usually located in /usr/local/etc/nginx/ or /etc/nginx/. Look for any syntax errors or misconfigurations, especially in the server block that handles your Herd sites.

    You can test the Nginx configuration with:

    nginx -t
    

    If you find any errors, fix them and then restart Nginx:

    brew services restart nginx
    
  3. Check PHP-FPM Configuration: Verify that PHP-FPM is configured correctly and is listening on the correct socket or port. The configuration file for PHP-FPM is typically located at /usr/local/etc/php/7.x/php-fpm.d/www.conf (replace 7.x with your PHP version).

    Look for the listen directive and make sure it matches the configuration in your Nginx server block for the fastcgi_pass directive.

  4. Check Error Logs: Review the error logs for both Nginx and PHP-FPM to see if there are any relevant error messages that can help you identify the problem.

    Nginx error log:

    tail -f /usr/local/var/log/nginx/error.log
    

    PHP-FPM error log (the path may vary depending on your PHP version):

    tail -f /usr/local/var/log/php-fpm.log
    
  5. Permissions and Ownership: Ensure that the permissions and ownership of your web files and directories are correct. Nginx and PHP-FPM need to have the appropriate permissions to access and serve your files.

  6. Clear Nginx Cache: If you're using caching with Nginx, try clearing the cache to see if that resolves the issue.

  7. Reinstall Herd: If none of the above steps work, you might want to try reinstalling Herd. Make sure to follow the official installation instructions carefully.

If after trying all these steps you're still facing issues, it might be helpful to provide more specific information about your setup, such as the Nginx server block configuration and any error messages you're seeing in the logs, so that others can help you troubleshoot further.

ethor88's avatar

I was able to find the command herd restart, and that ran as expected (after restarting my terminal). However, the site still didn't work. I went into Herd and made the site secure, and for some reason that made the site work. I'm guessing something was cached, but I hope this helps someone else that might be having the same issue.

2 likes
AlexElementarteilchen's avatar

Ran into the same problem with Herd 1.5 and a new laravel 11 project.

The nginx error log said: connect() to unix:/Users/alex/Library/Application Support/Herd/herd.sock failed

In the Herd GitHub issues I found the suggestion to change the PHP version from 8.3 to 8.2 in Herd and that solved the bad gateway problem.

(could also switch back to 8.3 - so it's not a PHP version problem. Seems like something is maybe not properly cleaned up or initialised)

12 likes
MrMoto9000's avatar

Switching versions didn't do it for me. It's just another bug in Herd (and the reason why everyone stopped using things like WAMP in the first place -- they always had these sorts of problems, another bit of software to go wrong).

For me I quit Herd completely and loaded it up again -- 502 error gone. (Yes, this just happened to me, all these years later. Why-oh-why did I take a chance and buy a licence? Ugh)

Behram Khattak's avatar

Same error just happend to me, the 502 Bad Gateway Error nginx/1.25.4.

  1. Restarted Herd (no luck)
  2. No information in Nginx logs
  3. Changed the main PHP version on the Laravel Herd that will be running for all of the apps. (Resolved)

For me, the 3rd option resolved this issue, but I didn't know why this issue happend.

I think you have to make the Laravel Herd app run the latest PHP version whenever a new version is available, and then set specific PHP versions for your apps accordingly.

issamlk's avatar

Maybe it could've been useful if we seen logs to the issue, but both nginx logs and php-fpm logs have nothing useful this could be happening for 1000000 reason.. and every click on the herd app is showing herd pro it feel like the app fighting you instead of helping..

Please or to participate in this conversation.