Solution – 502 Bad Gateway on Homestead
Setting up homestead for windows is a big pain even for intermediate developers and very frustrating for new developers. Recently I run into this 502 Bad Gateway while setting up a new project on my new windows PC and after hours of digging and surfing the internet, I have two working solutions to this problem. If you’re facing the same error, then use any one of these solutions to resolve your problem.
Solution One: Disable Xdebug
This is the first Solution I came across on StackOverflow. Yes and as always StackOverflow is the first place to reach for help, although I usually reach out to laracast.com first before StackOverflow and then S-Techmax Forum.
Here is what to do to fix this error using this solution
- Boot up your VM using Vagrant up
- Vagrant ssh
- The run this code
sudo phpdismod xdebug.
Solution Two: Switch to using Apache
Another solution I tried and the problem was resolve is configuring my site on Homestead.Yaml to use Apache instead of Nginx.
- If your machine is running then run Vagrant Halt to power off
- Open the Homestead.yaml file and add this line of code to your site settings. type: “apache” so now it should look like this:
sites: - map: homestead.test to: /home/vagrant/learn/public type: "apache"
3. Run Vagrant up and everything should be fix.
Solution Three: Return to using PHP 7.2
Some folks on Github said this worked for them but on my machine, I had no luck with this solution. This should act as your last resort, that is if you dont want to disable xdebug and dont want to use apache.
Here is how your site configuration should look after making this change
sites: - map: example.test to: /home/vagrant/code/public php: "7.2"