shankar_giri's avatar

502 Bad Gateway nginx (1.9.7) in Homestead [ Laravel 5 ]

  1. I have "homestead" globally installed.
  2. Also, I did grab laravel/homestead box.
  3. Did edit my Homestead.yaml file to map my folder location and sites location. [ This part is working since I am able to access files locally as well as from virtual box ]
  4. Did named the domain "onestop.dev" for "192.168.10.10" in my "/etc/hosts"
  5. Did fix the document root as well in /etc/nginx/sites-available/onestop.dev

When I try to access onestop.dev, I keep getting 502 Bad Gateway

[ I even asked the same question in stakoverflow. But have not heard anyone answering this ] http://stackoverflow.com/questions/34473185/502-bad-gateway-nginx-1-9-7-in-homestead-laravel-5

0 likes
26 replies
bashy's avatar

Best to ask the question again here. I cba to click on a link and answer it here :)

LarsN's avatar

I had the same problem and did this to remove my three boxes and add fresh:

$ vagrant box remove laravel/homestead --box-version=0.2.6 
$ vagrant box remove laravel/homestead --box-version=0.2.7
$ vagrant box remove laravel/homestead --box-version=0.4
$ composer global remove laravel/homestead
$ composer clear-cache
$ composer global require laravel/homestead
$ vagrant up

1 like
shankar_giri's avatar

@bashy I have done my best to explain what I have done so far. Please let me know if I need to be more detailed.

@LarsN I even tried the way you mentioned - removing laravel/homestead box if any , removed laravel/homestead globally and cleared cache. And, did install laravel/homestead globally. But, still the same issue.

Few to add:

When I restart:

  • Restarting nginx nginx [fail]

tail -f /var/log/nginx/error.log

2015/12/19 15:16:51 [notice] 13493#13493: signal process started

2015/12/19 15:17:58 [notice] 14750#14750: signal process started

2015/12/19 15:21:37 [notice] 21481#21481: signal process started

2015/12/29 22:13:21 [notice] 1835#1835: signal process started

2015/12/29 22:19:50 [notice] 1967#1967: signal process started

2015/12/29 22:20:30 [notice] 1984#1984: signal process started

2015/12/29 22:23:00 [notice] 2154#2154: signal process started

Miguel's avatar
Miguel
Best Answer
Level 1

Hi,

I think that is about a problem in the configuration files using old php 5.6 and the new VM is using php 7.0

It worked for me:

edit homestead.app

sudo nano /etc/nginx/sites-enabled/homestead.app

change line fastcgi_pass for

...
 fastcgi_pass unix:/run/php/php7.0-fpm.sock;
...

restart nginx and php7.0-fpm

sudo service nginx restart
sudo service php7.0-fpm reload
18 likes
shankar_giri's avatar

@Miguel You are my hero :) Thank you so much. I was waiting for this answer for last few days.

1 like
RafaelMello's avatar

I have did all processes as was mentioned here, but for nothing worked for me, anyone has more information?

bashy's avatar

@emman Be warned, this will reset after you do vagrant provision

richard's avatar

I'm experiencing the same problem, but @Miguel answer is not solving my problem

yher136's avatar

It's happens to me the same...

I've changed this...

... fastcgi_pass unix:/run/php/php7.0-fpm.sock; ...

But I'm still have the same answer: 502 Bad Gateway...

teejten's avatar

I am having the same issue for just a simple route

teejten's avatar

nm , I forgot I had a file in the directory that shouldn't be there. Simple typo in a mis-placed file was my problem.

yher136's avatar

@mkwsra Yeah dude! I did solve it successfully! if you input this command "serve xxxx.app /home/user/projects/xxxx/public", surely it will causes conflict, between php 5 mod and php 7 module in nginx, but you can solve editing the config of the site generated in "/etc/nginx/sites-enabled/xxxx.app".

1 like
mkwsra's avatar

@yher136 Uh please don't be sorry and thanks a lot.

My problem was different actually, I was adding $with property for default eager loading, and I was adding it to both USER and comment so my app was going into infinite loop or so.

Thanks again for answering!

gratiafide's avatar

I was getting this error because I had somehow deleted the php7.0-fpm.sock file. Re-installing php7.0 fixed the issue for me:
sudo apt-get install php7.0-fpm

I also had to reinstall mysql:

sudo apt-get install php7.0-mysql

1 like
Ravenberg's avatar

My solution was to actually destroy the homestead box and install it from scratch. When you run the init.sh command you can choose not to override the Homestead.yml file in which all my project mapping where defined. Which is nice.

1 like
smks's avatar

I find this stupid that I have to make an amendment to this line every time I provision the box.

Kovaloff's avatar

sudo service nginx restart sudo service php7.1-fpm reload

did the trick for me

Tiago_nes's avatar

Great job @Miguel i had the exact opposite problem config files were still trying to use php7.1 after i downgraded to php 5.6. I did the exact opposite of your answer and it worked like a charm.

JoshMountain's avatar

I ran into a similar issue recently after upgrading my Homestead box to 7.0.0

The fix ended up being disabling xdebug as apparently there is a compatibility issue with PHP 7.3

Try this in homestead sudo phpdismod xdebug

5 likes

Please or to participate in this conversation.