27

I am getting a 502 Bad Gateway on my Laravel projects running Laravel valet.

I have tried many of the solutions online and with no success. i.e. https://gist.github.com/adamwathan/6ea40e90a804ea2b3f9f24146d86ad7f

At the moment the error I see is 502 bad gateway and an error in my command line when running valet install is an error when it gets to the updating PHP configuration. It gives the following error:

Warning: file_get_contents(/usr/local/etc/php/7.3/php-fpm.d/www.conf): failed to open stream: No such file or directory in /Users/username/.composer/vendor/laravel/valet/cli/Valet/Filesystem.php on line 112

Warning: file_get_contents(/usr/local/etc/php/7.3/php-fpm.d/www.conf): failed to open stream: No such file or directory in /Users/username/.composer/vendor/laravel/valet/cli/Valet/Filesystem.php on line 125

Has anybody had similar issues?

Thanks

Md Mazedul Islam Khan
  • 5,318
  • 4
  • 40
  • 66
JMD
  • 327
  • 1
  • 5
  • 7

13 Answers13

71

If you're anyone like me who're seeing 502 Bad Gateway while using Laravel Valet after updating it composer global update to the latest version, you most probably forgot to run valet install command. Laravel Valet requires (in most cases) to run valet install command after updating to the latest version.

Md Mazedul Islam Khan
  • 5,318
  • 4
  • 40
  • 66
  • 2
    This is the actual answer to the user's question above and is a much better first step in diagnosing this problem than the accepted answer, which works because of the last step in the process. – mrpritchett Feb 10 '21 at 15:10
41

in most cases running valet install will solve the issue.

Maen
  • 725
  • 7
  • 10
18

Had the same symptoms after updating to php 7.3 and then installing a new Laravel project.

It appears that brew install php73 doesn't install php-fpm

Solution is to uninstall php

brew uninstall php73 
brew uninstall php72
brew uninstall php71 ... whatever versions you have
brew uninstall --force php

Now reinstall php

brew install php --build-from-source

I encountered permission errors mkdir: /usr/local/etc/php/7.3/php-fpm.d: Permission denied so sudo chown -R: <yourusercode> /usr/local/etc/php fixed that and then brew install php --build-from-source again. Once it builds php 7.3 successfully reinstall valet:

valet install
Dave Robertson
  • 431
  • 3
  • 6
10

None of the above answers worked for me, but found the solution here: https://janostlund.com/2019-06-20/502-bad-gateway-laravel-valet

~/.config/valet/Log/nginx-error.log shows:

[error] 17423#0: *1 upstream sent too big header while reading response header from upstream [...]

Solved by adding two lines to http in /usr/local/etc/nginx/nginx.conf

http {
  fastcgi_buffers 16 16k;
  fastcgi_buffer_size 32k;
  
  //...
}

and then running valet restart

Emre Koc
  • 1,481
  • 10
  • 18
8

I solved this by doing:

php -v

PHP 8.0.1 (cli) (built: Jan 8 2021 09:07:02) ( NTS ) Copyright (c) The PHP Group Zend Engine v4.0.1, Copyright (c) Zend Technologies with Zend OPcache v8.0.1, Copyright (c), by Zend Technologies

followed by:

valet use php@8.0 --force

Unlinking current version: php Linking new version: php@8.0 Updating PHP configuration... Restarting php... Restarting nginx... Valet is now using php@8.0.

Valet seemed to be confused over which PHP it was using.

agm1984
  • 15,500
  • 6
  • 89
  • 113
2

In my case I reinstalled different version of php. I just run

valet install

and it worked fine.

Nijat Mursali
  • 930
  • 1
  • 8
  • 20
1

I ran into the same problem with Laravel 8. Both Valet and Expose seemed to work, but the webpage always gave a 502 response.

The solution I found when I updated composer and tried to reinstall Valet was that Valet didn't know which version of php to use.

To fix this, use the following command to tell valet which version of php to use.

valet use php@7.4
Hessel
  • 33
  • 3
1

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

Source: laravel/valet github issues

bar5um
  • 843
  • 1
  • 9
  • 21
1

Well, normally "valet install" solves the issue but for me it was different. For my case, I was using valet isolate for a different project with different PHP versions. So, I have to do the binding process again.

I did,

  1. valet install
  2. valet isolate php@7.1 (Here you have to use the selected version)

this solves the issue for me.

opqclick
  • 11
  • 4
0

I had the same problem. I solved it by upgrading mariadb. brew upgrade mariadb

0

Following the config above, but put it in the file.

~/.valet/Nginx/all.conf

  fastcgi_buffers 16 16k;
  fastcgi_buffer_size 32k;

This did catch on all the sites "Im use Valet plus"

0

If the valet restart or valet install didn't work, try to change the PHP version.

valet use php@7.4

Or

valet isolate php@7.4
Mostafa Soufi
  • 645
  • 10
  • 17
0

My nginx-error.log file was full of messages like this

*3 connect() to unix:/home/oakbox/.valet/valet.sock failed (2: No such file or directory) while connecting to upstream, client: 127.0.0.1

It took me too long to figure out that php-fpm was running, but that Nginx could not 'see' that socket. Look in your Nginx configuration file for the line that starts with

        fastcgi_pass unix:/home/oakbox/.valet/valet.sock;

And then look to see if that socket actually exists. In my setup, an update of my system moved my default PHP installation from version 8.1 to 8.2. The actual socket file was renamed from valet.sock to valet82.sock.

I edited my Nginx configuration files to point to the real location of the socket

        fastcgi_pass unix:/home/oakbox/.valet/valet82.sock;

A restart of Nginx and my 502 Bad Gateway went away.