Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

502 Bad Gateway nginx/1.15.8 #717

Closed
Flerex opened this issue Jan 28, 2019 · 24 comments
Closed

502 Bad Gateway nginx/1.15.8 #717

Flerex opened this issue Jan 28, 2019 · 24 comments

Comments

@Flerex
Copy link

@Flerex Flerex commented Jan 28, 2019

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?

@mattstauffer

This comment has been minimized.

Copy link
Contributor

@mattstauffer mattstauffer commented Jan 28, 2019

@Flerex 7.3 has been almost unusable; I suggest moving to 7.2.

@drbyte

This comment has been minimized.

Copy link
Contributor

@drbyte drbyte commented Jan 28, 2019

Hmmm ... I've had no issues with 7.3 on a fresh Mojave install.

Maybe I'll wipe this new machine and test again.

@Flerex

This comment has been minimized.

Copy link
Author

@Flerex Flerex commented Jan 28, 2019

@mattdfloyd 7.2 installed, same thing happening.

@drbyte

This comment has been minimized.

Copy link
Contributor

@drbyte drbyte commented Jan 28, 2019

As I understand it, Bad Gateway means Nginx isn't finding the PHP-FPM service to proxy (gateway) the request through.

Common causes:

  • PHP isn't running
  • the valet config isn't finding the valet.sock socket, which is created by the PHP process when it starts
  • the valet nginx configs are pointing to the wrong php version
@florianbouvot

This comment has been minimized.

Copy link

@florianbouvot florianbouvot commented Jan 28, 2019

Did you try this

brew services start php

If it didn’t work, try to reinstall php from source

brew uninstall php
brew install php --build-from-source
valet install
@Flerex

This comment has been minimized.

Copy link
Author

@Flerex Flerex commented Jan 29, 2019

It worked! Thanks @florianbouvot

@aurelianoa

This comment has been minimized.

Copy link

@aurelianoa aurelianoa commented Feb 1, 2019

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 btw

@iqigmbh

This comment has been minimized.

Copy link

@iqigmbh iqigmbh commented Mar 19, 2019

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

@drewroberts

This comment has been minimized.

Copy link

@drewroberts drewroberts commented Apr 12, 2019

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

@araeuchle

This comment has been minimized.

Copy link

@araeuchle araeuchle commented Jun 16, 2019

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 :)

@drbyte

This comment has been minimized.

Copy link
Contributor

@drbyte drbyte commented Jun 16, 2019

I ran brew upgrade && brew update && brew cleanup recently and it upgraded me from 7.3.5 to 7.3.6 and is working fine.
It's been awhile since I bothered with PHP 7.2, so maybe your glitch was in moving from 7.2 to 7.3.

The Bad Gateway message means Nginx can't find a running PHP instance, as determined by having PHP-FPM properly configured to create the valet.sock file so Nginx can use that to send PHP request through. The default valet configs for PHP-FPM work fine on my machine.
If yours aren't working, you can delete your /usr/local/etc/php directory (backups first of course) and then re-install 7.3.

@skakrecha

This comment has been minimized.

Copy link

@skakrecha skakrecha commented Jun 17, 2019

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 cant use the "valet use" it says command use not defined

@drbyte

This comment has been minimized.

Copy link
Contributor

@drbyte drbyte commented Jun 17, 2019

I cant use the "valet use" it says command use not defined

That suggests you're using an old version of Valet. I believe the use command was added in 2.2.0

@josermorales

This comment has been minimized.

Copy link

@josermorales josermorales commented Jun 24, 2019

Fixed it by doing

brew services start --all
@Ahmed-Aboud

This comment has been minimized.

Copy link

@Ahmed-Aboud Ahmed-Aboud commented Jul 1, 2019

a really weird reason that solved it was a missing default value just as i passed it the POST method worked

@ElectroBuddha

This comment has been minimized.

Copy link

@ElectroBuddha ElectroBuddha commented Jul 16, 2019

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

@metallurgical

This comment has been minimized.

Copy link

@metallurgical metallurgical commented Aug 9, 2019

Both @ElectroBuddha and @drewroberts answers did the tricks

@rcordobar19

This comment has been minimized.

Copy link

@rcordobar19 rcordobar19 commented Sep 11, 2019

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

Thank you, it worked

@mugisham

This comment has been minimized.

Copy link

@mugisham mugisham commented Sep 16, 2019

valet unistall
valet install
valet park

these 3 steps worked for me

@abhisheksatre

This comment has been minimized.

Copy link

@abhisheksatre abhisheksatre commented Oct 22, 2019

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

Thank you. it worked

@OliverGrimsley

This comment has been minimized.

Copy link

@OliverGrimsley OliverGrimsley commented Jan 8, 2020

Seems 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):

brew doctor
brew services cleanup
brew list | grep php
brew uninstall --force php@[INSERT VERSIONS]

Re-ran brew doctor and brew services cleanup and brew cleanup and had to manually sudo rm -R [directories] where directories were in usr\local\etc\ then

valet restart
valet parked
valet use php@7.4

Brew is such a PITA. I had to chown a number of directories to fix permissions, rm stuff etc.

@drbyte

This comment has been minimized.

Copy link
Contributor

@drbyte drbyte commented Jan 8, 2020

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 run valet 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:

  • composer global update
  • brew upgrade
    and if homebrew gave me a new major PHP version (ie: 7.4 when I previously had 7.3) then I also run:
  • valet install
@liyansasongko

This comment has been minimized.

Copy link

@liyansasongko liyansasongko commented Feb 7, 2020

Did you try this

brew services start php

If it didn’t work, try to reinstall php from source

brew uninstall php
brew install php --build-from-source
valet install

it worked

@liyansasongko

This comment has been minimized.

Copy link

@liyansasongko liyansasongko commented Feb 7, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
You can’t perform that action at this time.