Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

warpig's avatar
Level 12

502 Bad Gateway

Im getting a 502 Bad Gateway on my local environment and I dont know how to start checking, where or how it went wrong, any suggestions?

0 likes
8 replies
Braunson's avatar

This likely isn't due to Laravel but due to how you have things setup. If your using Nginx or Apache check their logs and it may give you insight into what's causing the bad gateway.

warpig's avatar
Level 12

This is the error messaged in the log:

2021/01/04 21:05:55 [error] 315#0: *27 connect() to unix:/Users/eduardocoello/.config/valet/valet.sock failed (61: Connection refused) while connecting to upstream, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/Users/eduardocoello/.config/valet/valet.sock:", host: "newport.test"

warpig's avatar
Level 12

Thanks, seems like the problem is starting from here after composer global update:

  Problem 1
    - laravel/homestead[v10.3.0, ..., v10.17.0] require php ^7.1 -> your php version (8.0.0) does not satisfy that requirement.
    - Root composer.json requires laravel/homestead ^10.3 -> satisfiable by laravel/homestead[v10.3.0, ..., v10.17.0].
warpig's avatar
Level 12

Your answer helped me get the ball rolling. Thanks.

warpig's avatar
Level 12

I solved it. Many things had to happen, starting from running composer global update, then valet install and many more runs.

Composer dependencies need a specific version of PHP

Turns out I had updated composer to the latest version (--2) and Laravel didn't liked that, somehow that meant that my dependencies that were using a version of php (7.4) were no longer working because of this action/update (I think php updated to 8.0 version in this process when Composer got the update)

So all in all

  • I had to review which version of php I was using and use that version with brew link [email protected] in my case I had to overwrite, a message pops out telling you how to do this overwrite.
  • After I solved my issues with valet, no longer was I receiving the 502 Gateway message but I had a message from Firefox telling me the connection couldn't be made (or something)
  • After this I started to receive the message that my composer dependencies used a version of PHP 7.4 and I was using a 7.3, this is when I had to run composer self-upgrade 1.10.17
  • Then composer update php --with-all-dependencies

Valuable sources:

1 like
aklemm's avatar

For anyone having this problem more recently: if using Herd, this may be easily fixed by checking the PHP version and making sure it's using the most recent.

1 like

Please or to participate in this conversation.