Laravel homestead 502 bad gateway
Asked Answered
P

10

13

Everytime i go to my project I get a 502 bad gateway. When I refresh, the page works.. If I click a link to another page I get 502 bad gateway again. After the refresh the page loads. What could be the problem here.

Homestead.yaml

---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox

authorize: c:/Users/MyNameHere/.ssh/id_rsa.pub

keys:
    - c:/Users/MyNameHere/.ssh/id_rsa

folders:
    - map: c:/Users/MyNameHere/Desktop/sites
      to: /home/vagrant/code

sites:
    - map: spa.test
      to: /home/vagrant/code/spa/public

databases:
    - homestead

Got the latest version for virtualbox and vagrant.

My spa folder contains the newest version laravel.

Pesthole answered 27/1, 2019 at 12:38 Comment(0)
M
25

Login to Laravel Homestead Server with PuTTY and Private Key File.

then...

cd /etc/php/7.4/mods-available 

sudo nano xdebug.ini

Comment out the first line

;zend_extension=xdebug.so
xdebug.remote_enable = 0
xdebug.remote_connect_back = 1
xdebug.remote_port = 9000
xdebug.max_nesting_level = 512

Then restart PHP-FPM

sudo service php7.4-fpm restart
Mutism answered 29/9, 2020 at 15:4 Comment(3)
mine has been running before but when i went back 1 week later its now showing 502 bad gateway. this solved my issue. thanks!Orthogenesis
Note that sometimes all you need to do is sudo service php7.4-fpm restart. Especially if your config was okay before, but now it is not, a simple fpm restart may fix it. Found out, because I use xdebug, so didn't want to disable the extension.Shearwater
Thank you. That helped me.Crespo
E
8

Had the same issue with the latest version of homestead.

After digging in log files and then github issues for homestead, I found this this.

There's an issue with xdebug that they're waiting for a fix for. The solution is to disable xdebug or use php 7.2. I opted for the latter. In that case, make the following change in your homestead.yaml and then running vagrant reload --provision will fix this.

sites:
- map: spa.test
  to: /home/vagrant/code/spa/public
  php: "7.2"
Eisegesis answered 28/1, 2019 at 21:47 Comment(2)
Haha didn't know there was answer for this here .I searched it day and fix on my own. But few min after posting my answer I found this.Sadiras
vagrant provision solves the problem for one time, on next boot you have to again re-provision the machine though.Clymer
H
2

I was having the same problem and I couldn't change the PHP version or disable xdebug, but I could and did change for the Apache server.

sites:
    - map: spa.test
      to: /home/vagrant/code/spa/public
      type: "apache"
Headcloth answered 2/7, 2020 at 16:39 Comment(0)
M
2

I had a similar issue, got the 502 error. Refreshing the browser or reloading the virtual machine had no effect.

I solved disabling the Xdebug. Found the solution here: https://christattum.com/disabling-xdebug-in-laravel-homestead/

On prompt:

cd /etc/php/7.4/mods-available 
sudo vi xdebug.ini

Commented all the lines of the file with ;

Motherhood answered 30/7, 2020 at 12:49 Comment(0)
W
2

Run the vagrant reload --provision command to the Homestead file in the virtual machine, and then after vagrant up, enter with vagrant ssh. Your problem will be solved :)

Wehrmacht answered 2/10, 2020 at 14:27 Comment(1)
This actually worked for me in my own caseLucilelucilia
L
0

You can change your ip post adress and write 127.0.0.1 in your host file. You can enter it by adding 8000 next to the project name in the search engine.

For example spa.test:8000 and then running vagrant reload --provision will fix this.

Ladner answered 2/10, 2020 at 14:36 Comment(0)
W
0

I lost 3 days trying to solve the same issue.

My mistake was to have defined in my host file something like:

127.0.0.1 spa.test

The solution is to add instead, the same IP you specified in Homestead.yaml.

192.168.10.10 spa.test
  • to /etc/host (In case of Mac)
  • to C:\Windows\System32\drivers\etc\hosts (in case of Windows)

Even if you have multiple hosts defined in your global Homestead.yaml file. For instance

folders:
    - map: /Users/davidecasiraghi/Projects/my_laravel_project
      to: /home/vagrant/code/my_laravel_project    
    - map: /Users/davidecasiraghi/Projects/spa
      to: /home/vagrant/code/spa  
      
sites:
    - map: my_laravel_project.test
      to: /home/vagrant/code/my_laravel_project/public
    - map: spa.test
      to: /home/vagrant/code/spa/public

Then in the host file:

192.168.10.10 spa.test
192.168.10.10 my_laravel_project.test

Then when you will do vagrant up you will be able to access to both of them.

Wiggler answered 30/11, 2020 at 21:44 Comment(0)
L
0

For me this was related to Xdebug, which doesn't seem to yet be compatible with PHP 7.3.

To continue using 7.3, you can turn Xdebug off with

sudo phpdismod xdebug

restart php service

sudo service php7.3-fpm reload
Lysander answered 21/2, 2021 at 13:48 Comment(0)
G
0

For Chinese, if you are using Clash for Windows, then edit "Bypass Domain".

It's not relevant to this question, but Google lead me here,

Guanabana answered 11/2, 2022 at 5:57 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Wino
S
0

Do this inside your Homestead VM vagrant ssh Check your php version

$ php -v

Edit your website config file

$ sudo nano /etc/nginx/sites-available/<laravel.app>

line

fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;

change according to your php version

mine was php8.2-fpm.sock; then I change it to php8.1-fpm.sock; press ctrl+x to save, then

$ sudo service nginx restart
$ sudo service php<ver>-fpm restart

reload the page

Scopolamine answered 11/1, 2023 at 10:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.