Lansana's avatar

502 Bad Gateway: nginx 1.9.7, Homestead

I am getting a 502 bad gateway when I try to go to my project.dev site.

When I run "vagrant up", I get this error at the end:

==> default: php5-fpm: unrecognized service
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.

I was looking at this topic to try and find a solution: https://laracasts.com/discuss/channels/general-discussion/502-bad-gateway-nginx-197-in-homestead-laravel-5 -- and it kind of works.. but there are a couple of problems.

  1. In my "/etc/nginx/sites-enabled", there is only a "laravel.app", though my homestead.yaml looks like this:
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox

authorize: ~/.ssh/id_rsa.pub

keys:
    - ~/.ssh/id_rsa

folders:
    - map: ~/Homestead/Projects
      to: /home/vagrant/Sites

sites:
    - map: laravel.app
      to: /home/vagrant/Sites/dream/public
    - map: blog.app
      to: /home/vagrant/Sites/blog/public
    - map: project.dev
      to: /home/vagrant/Sites/project-v1/public


databases:
    - homestead

variables:
    - key: APP_ENV
      value: local

# blackfire:
#     - id: foo
#       token: bar
#       client-id: foo
#       client-token: bar

# ports:
#     - send: 93000
#       to: 9300
#     - send: 7777
#       to: 777
#       protocol: udp

... so it should contain a laravel.app, blog.app and project.dev, right..?

I followed these steps first to fix the 502 gateway error:

  1. First, typed this:
sudo nano /etc/nginx/sites-enabled/laravel.app
  1. Then edited the fastcgi_pass line to this:
 fastcgi_pass unix:/run/php/php7.0-fpm.sock;
  1. Then restart nginx and php7.0-fpm:
sudo service nginx restart
sudo service php7.0-fpm reload

I do that and go to project.dev, as shown as one of the sites in my homestead.yaml, and it removes the 502 bad gateway error at least, but it goes to the laravel.app site instead of the project.dev site.

My hosts file contains all three files and so does the homestead.yaml as shown above, and when I exit the ssh and try running vagrant provision or just try to vagrant up again, it resets the step #2 line back to what it was before, which was giving the error of php5-fpm: unrecognized service.

Anyone know what I am doing wrong or how to solve this?

  1. Why do the three steps not stay saved?
  2. Why is only laravel.app showing in "/etc/nginx/sites-enabled", though I have three sites in hosts and homestead.yaml?
0 likes
6 replies
Lansana's avatar

Someone please help =s can't find a solution to this.

RichardStyles's avatar
Level 11

I had this exact same error & I had an old version of Homestead which was being picked up somewhere along the way.

I ended up removing all versions/copies of Homestead, including my composer global homestead copy. Once this was done, added Homestead back in and worked 1st time.

Lansana's avatar

@RichardStyles Ah, thanks! Just did a "git pull" and it updated the homestead. Now all works fine. I guess it was indeed the outdated Homestead.

Paperjuice's avatar

I had a similar issue, but slightly different : 502 error on every page load, disappearing on page refresh.

Appeared to be an issue with Xdebug, which I could resolve thanks to this thread.

(Windows 10 environment)

In short :

  • Get the vagrant box up and running with vagrant up
  • Log into it with vagrant ssh
  • Access the xdebug config file with sudo vim /etc/php/7.3/mods-available/xdebug.ini
  • Type i to access vim insert mode
  • Comment out the first line by appending ;
  • Type :wq and press enter to write (save) and quit
  • Enter sudo service nginx restart, then sudo service php7.3-fpm restart

Hope it helps someone with a similar problem running into this post!

1 like

Please or to participate in this conversation.