valet: 502 Bad Gateway nginx/1.15.8
I’m getting a 502 Bad Gateway nginx/1.15.8 error when trying to enter a .test site. This is on a completely fresh Mojave installation where I just installed with Homebrew php
(7.3.1), nginx
(1.15.8) (among others) and Valet
(2.1.6) through composer. I haven’t modified any default configuration of any of the aforementioned packages. I have run valet install
and valet park
in the folder where my project is at.
Any idea why this is happening?
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 13
- Comments: 49 (9 by maintainers)
Did you try this
If it didn’t work, try to reinstall php from source
Started having this issue after I updated php to v7.3. Tried all of the suggestions, fixed only after I updated valet to the latest version (v2.3.3):
composer global update
valet install
I ran into this issue as well. After doing the commands shared in the other responses, I also had to change back to php 7.2 instead of 7.3 and here’s that command:
valet use php@7.2
More about it here: Laravel Valet PHP Versions
A simple restart of the brew services with sudo in front and an adjacent restart of valet did the job for me:
sudo brew services restart nginx && sudo brew services restart php
valet restart
FYI - “502 Bad Gateway” from Nginx means the PHP proxy is not running, or not found. (Nginx proxies PHP calls to php-fpm by means of the directives in the nginx site conf files.)
So, if you’ve updated your PHP to a new non-minor version (ie: 7.2 up to 7.3, or 7.4 down to 7.3) by just running a
brew upgrade
command, then you’ll need to also runvalet install
to configure that PHP version’s configs for Valet. Otherwise your newly-installed PHP version’s configs won’t know anything about Valet.If you upgrade PHP or switch to new PHP version via the
valet use php@x.x
command then Valet will also do the necessary config updates as part of that switch.My usual workflow (and I normally only use the latest PHP version anyway) is simply the following on a weekly basis:
valet use php@8.1 --force
This worked for me.Upgrading to php 7.4 worked for me.
valet use 7.4
valet unistall valet install valet park
these 3 steps worked for me
As I understand it, Bad Gateway means Nginx isn’t finding the PHP-FPM service to proxy (gateway) the request through.
Common causes:
valet.sock
socket, which is created by the PHP process when it startsSeems every time I update/upgrade brew I have this issue (nginx 1.17.7). Had it again when going to PHP 7.4. Here is what I had to do, not sure if the last thing I did would have worked first, so, the last thing I did was:
valet use php@7.4
Before that, I completely eradicated PHP (note, at least on Catalina, you cannot use sudo in front of brew, or I do not know how):
Re-ran
brew doctor
andbrew services cleanup
andbrew cleanup
and had to manuallysudo rm -R [directories]
where directories were inusr\local\etc\
thenBrew is such a PITA. I had to
chown
a number of directories to fix permissions,rm
stuff etc.Happened to me as well after i upgraded my macos with brew update && brew upgrade
valet use php@7.2 did the trick for me. thanks @drewroberts, you saved me lots of hours 😃
I know this is closed but i had the same issue and i was because some how brew had running an older php version so:
sudo brew services cleanup
and after i restart it worked. i have Mac OSX High Sierra btwbrew services stop php
brew services start php
Fixed.
FYI, Just updated to PHP 7.49 and tried using valet. Got: In PhpFpm.php line 212: Valet doesn’t support PHP version: php@7.49 (try something like ‘php@7.3’ instead)
So, is something to take into consideration.
The following commands worked for me.
valet use php@7.2
composer global update
Both @ElectroBuddha and @drewroberts answers did the tricks
Fixed it by doing
@Flerex 7.3 has been almost unusable; I suggest moving to 7.2.