valet: Nginx 502 Bad Gateway

Hi I have try to update php to 8.0 but always there a problem with valet to read the new version and I try to solve it without specific instructions but this time is stucked

Expected behavior

I expect valet to work again and serve my projects

Current behavior

I have tried this command from #920 ➜ ~ sudo /usr/local/opt/php/sbin/php-fpm --test [04-Apr-2021 10:54:58] ERROR: failed to open configuration file ‘/usr/local/etc/php/8.0/php-fpm.conf’: No such file or directory (2) [04-Apr-2021 10:54:58] ERROR: failed to load configuration file ‘/usr/local/etc/php/8.0/php-fpm.conf’ [04-Apr-2021 10:54:58] ERROR: FPM initialization failed

➜ ~ php --ini Configuration File (php.ini) Path: /usr/local/etc/php/8.0 Loaded Configuration File: (none) Scan for additional .ini files in: /usr/local/etc/php/8.0/conf.d Additional .ini files parsed: /usr/local/etc/php/8.0/conf.d/error_log.ini, /usr/local/etc/php/8.0/conf.d/php-memory-limits.ini

➜ ~ brew services list Name Status User Plist dnsmasq unknown root /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist httpd stopped mysql started mohammedalama /usr/local/opt/mysql/homebrew.mxcl.mysql.plist nginx unknown root /Library/LaunchDaemons/homebrew.mxcl.nginx.plist php error root /Library/LaunchDaemons/homebrew.mxcl.php.plist redis started mohammedalama /usr/local/opt/redis/homebrew.mxcl.redis.plist supervisor started mohammedalama /usr/local/opt/supervisor/homebrew.mxcl.supervisor.plist

Output of these steps

Possible solution

Diagnosis

sw_vers
ProductName:	macOS
ProductVersion:	11.1
BuildVersion:	20C69
valet --version
Laravel Valet 2.14.1
cat ~/.config/valet/config.json
{
    "tld": "test",
    "paths": [
        "/Users/mohammedalama/.config/valet/Sites",
        "/Users/mohammedalama/Documents/Work",
        "/Users/mohammedalama/Documents/Code",
        "/Users/mohammedalama/Documents/Code/FrontEnd_Projects",
        "/Users/mohammedalama/Documents/Code/BackEnd_Projects",
        "/Users/mohammedalama/Code/php",
        "/Users/mohammedalama/Code/js"
    ],
    "loopback": "127.0.0.1"
}
cat ~/.composer/composer.json
{
    "require": {
        "laravel/installer": "^4.0",
        "psy/psysh": "@stable",
        "tightenco/lambo": "^0.5.5",
        "laravel/envoy": "^1.6",
        "friendsofphp/php-cs-fixer": "^2.16",
        "beyondcode/expose": "^1.2",
        "laravel/valet": "^2.14"
    }
}
composer global diagnose
Changed current directory to /Users/mohammedalama/.composer
Checking composer.json: WARNING
No license specified, it is recommended to do so. For closed-source software you may use "proprietary" as license.
require.psy/psysh : unbound version constraints (@stable) should be avoided
Checking platform settings: OK
Checking git settings: OK
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com oauth access: OK
Checking disk free space: OK
Checking pubkeys: 
Tags Public Key Fingerprint: 57815BA2 7E54DC31 7ECC7CC5 573090D0  87719BA6 8F3BB723 4E5D42D0 84A14642
Dev Public Key Fingerprint: 4AC45767 E5EC2265 2F0C1167 CBBB8A2B  0C708369 153E328C AD90147D AFE50952
OK
Checking composer version: You are not running the latest snapshot version, run `composer self-update` to update (dca8bd71975910345ed4c3bc11122c11a01f6352 => 91136213d11630d881bf8ff9c0e1df37daf50d22)
Composer version: 2.1-dev+dca8bd71975910345ed4c3bc11122c11a01f6352
PHP version: 8.0.3
PHP binary path: /usr/local/Cellar/php/8.0.3/bin/php
OpenSSL version: OpenSSL 1.1.1j  16 Feb 2021
cURL version: 7.76.0 libz 1.2.11 ssl (SecureTransport) OpenSSL/1.1.1k
zip: extension present, unzip present
composer global outdated
Changed current directory to /Users/mohammedalama/.composer
illuminate/container v6.20.22 ~ v8.35.1 The Illuminate Container package.
illuminate/contracts v6.20.22 ~ v8.35.1 The Illuminate Contracts package.
illuminate/support   v6.20.22 ~ v8.35.1 The Illuminate Support package.
laravel/envoy        v1.6.5   ~ v2.7.0  Elegant SSH tasks for PHP.
php-cs-fixer/diff    v1.3.1   ~ v2.0.2  sebastian/diff v2 backport support for PHP5.6
psr/container        1.1.1    ~ 2.0.1   Common Container Interface (PHP FIG PSR-11)
tightenco/lambo      v0.5.5   ~ v1.0.1  Super-powered 'laravel new' with Laravel and Valet.
ls -al /etc/sudoers.d/
total 16
drwxr-xr-x    4 root  wheel   128 Dec 17 08:04 .
drwxr-xr-x  122 root  wheel  3904 Apr  1 16:13 ..
-rw-r--r--    1 root  wheel    80 Sep 17  2019 brew
-rw-r--r--    1 root  wheel    83 Sep 17  2019 valet
brew config
HOMEBREW_VERSION: 3.0.10
ORIGIN: https://github.com/Homebrew/brew
HEAD: 0ad2564c5f1ddf6f16f707f2861556b80546713c
Last commit: 6 days ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: bff5e515dadc66aba152ce59cdc1e43348288805
Core tap last commit: 48 seconds ago
Core tap branch: master
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 4
Homebrew Ruby: 2.6.3 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: quad-core 64-bit broadwell
Clang: 11.0 build 1103
Git: 2.28.0 => /usr/local/bin/git
Curl: 7.64.1 => /usr/bin/curl
macOS: 11.1-x86_64
CLT: 1103.0.32.59
Xcode: 11.3.1
brew services list
Name       Status  User          Plist
dnsmasq    unknown root          /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
httpd      stopped               
mysql      started mohammedalama /usr/local/opt/mysql/homebrew.mxcl.mysql.plist
nginx      unknown root          /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
php        error   root          /Library/LaunchDaemons/homebrew.mxcl.php.plist
redis      started mohammedalama /usr/local/opt/redis/homebrew.mxcl.redis.plist
supervisor started mohammedalama /usr/local/opt/supervisor/homebrew.mxcl.supervisor.plist
brew list --formula --versions | grep -E "(php|nginx|dnsmasq|mariadb|mysql|mailhog|openssl)(@\d\..*)?\s"
dnsmasq 2.84
mysql 8.0.19
nginx 1.19.8
openssl@1.1 1.1.1k
php 8.0.3
brew outdated
cairo
elixir
erlang
fzf
gcc@6
gh
ghostscript
git
gobject-introspection
graphviz
harfbuzz
heroku/brew/heroku
heroku/brew/heroku-node
httpd
hugo
ilmbase
imagemagick
isl
jasper
libde265
libheif
libmpc
libomp
little-cms2
mas-cli/tap/mas
mycli
mysql
netpbm
openexr
openjpeg
pango
php-cs-fixer
protobuf
python@3.8
redis
shared-mime-info
supervisor
telnet
x265
youtube-dl
zsh
font-hack-nerd-font
brew tap
caskroom/cask
github/gh
heroku/brew
homebrew/cask
homebrew/cask-fonts
homebrew/core
homebrew/services
mas-cli/tap
sambadevi/powerlevel9k
shivammathur/php
php -v
PHP 8.0.3 (cli) (built: Mar  4 2021 20:45:17) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.3, Copyright (c) Zend Technologies
which -a php
/usr/local/opt/php@8.0/bin/php
/usr/bin/php
/usr/local/bin/php
php --ini
Configuration File (php.ini) Path: /usr/local/etc/php/8.0
Loaded Configuration File:         (none)
Scan for additional .ini files in: /usr/local/etc/php/8.0/conf.d
Additional .ini files parsed:      /usr/local/etc/php/8.0/conf.d/error_log.ini,
/usr/local/etc/php/8.0/conf.d/php-memory-limits.ini
nginx -v
nginx version: nginx/1.19.8
curl --version
curl 7.64.1 (x86_64-apple-darwin20.0) libcurl/7.64.1 (SecureTransport) LibreSSL/2.8.3 zlib/1.2.11 nghttp2/1.41.0
Release-Date: 2019-03-27
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS GSS-API HTTP2 HTTPS-proxy IPv6 Kerberos Largefile libz MultiSSL NTLM NTLM_WB SPNEGO SSL UnixSockets
php --ri curl
curl

cURL support => enabled cURL Information => 7.76.0 Age => 8 Features AsynchDNS => Yes CharConv => No Debug => No GSS-Negotiate => No IDN => Yes IPv6 => Yes krb4 => No Largefile => Yes libz => Yes NTLM => Yes NTLMWB => Yes SPNEGO => Yes SSL => Yes SSPI => No TLS-SRP => Yes HTTP2 => Yes GSSAPI => Yes KERBEROS5 => Yes UNIX_SOCKETS => Yes PSL => No HTTPS_PROXY => Yes MULTI_SSL => Yes BROTLI => Yes Protocols => dict, file, ftp, ftps, gopher, gophers, http, https, imap, imaps, ldap, ldaps, mqtt, pop3, pop3s, rtmp, rtsp, scp, sftp, smb, smbs, smtp, smtps, telnet, tftp Host => x86_64-apple-darwin20.3.0 SSL Version => (SecureTransport) OpenSSL/1.1.1k ZLib Version => 1.2.11 libSSH Version => libssh2/1.9.0

Directive => Local Value => Master Value curl.cainfo => no value => no value

~/.composer/vendor/laravel/valet/bin/ngrok version
ngrok version 2.3.35
ls -al ~/.ngrok2
total 8
drwx------    3 mohammedalama  staff    96 Jun 14  2019 .
drwxr-xr-x+ 128 mohammedalama  staff  4096 Apr  4 11:08 ..
-rw-------@   1 mohammedalama  staff    55 Jun 14  2019 ngrok.yml
brew info nginx
nginx: stable 1.19.8 (bottled), HEAD
HTTP(S) server and reverse proxy, and IMAP/POP3 proxy server
https://nginx.org/
/usr/local/Cellar/nginx/1.19.8 (25 files, 2.2MB) *
  Poured from bottle on 2021-04-01 at 17:16:40
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/nginx.rb
License: BSD-2-Clause
==> Dependencies
Required: openssl@1.1, pcre
==> Options
--HEAD
	Install HEAD version
==> Caveats
Docroot is: /usr/local/var/www

The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that nginx can run without sudo.

nginx will load all files in /usr/local/etc/nginx/servers/.

To have launchd start nginx now and restart at login: brew services start nginx Or, if you don’t want/need a background service you can just run: nginx ==> Analytics install: 46,886 (30 days), 129,723 (90 days), 477,076 (365 days) install-on-request: 46,775 (30 days), 129,442 (90 days), 470,164 (365 days) build-error: 0 (30 days)

brew info php
php: stable 8.0.3 (bottled), HEAD
General-purpose scripting language
https://www.php.net/
/usr/local/Cellar/php/8.0.3 (499 files, 77.8MB) *
  Poured from bottle on 2021-04-01 at 17:18:15
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/php.rb
License: PHP-3.01
==> Dependencies
Build: httpd, pkg-config
Required: apr, apr-util, argon2, aspell, autoconf, curl, freetds, gd, gettext, glib, gmp, icu4c, krb5, libffi, libpq, libsodium, libzip, oniguruma, openldap, openssl@1.1, pcre2, sqlite, tidy-html5, unixodbc
==> Options
--HEAD
	Install HEAD version
==> Caveats
To enable PHP in Apache add the following to httpd.conf and restart Apache:
    LoadModule php_module /usr/local/opt/php/lib/httpd/modules/libphp.so
<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

Finally, check DirectoryIndex includes index.php DirectoryIndex index.php index.html

The php.ini and php-fpm.ini file can be found in: /usr/local/etc/php/8.0/

To have launchd start php now and restart at login: brew services start php Or, if you don’t want/need a background service you can just run: php-fpm ==> Analytics install: 47,253 (30 days), 155,891 (90 days), 633,677 (365 days) install-on-request: 46,447 (30 days), 152,972 (90 days), 615,396 (365 days) build-error: 0 (30 days)

brew info openssl
openssl@1.1: stable 1.1.1k (bottled) [keg-only]
Cryptography and SSL/TLS Toolkit
https://openssl.org/
/usr/local/Cellar/openssl@1.1/1.1.1k (8,071 files, 18.5MB)
  Poured from bottle on 2021-03-31 at 15:14:11
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/openssl@1.1.rb
License: OpenSSL
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/openssl@1.1/certs

and run /usr/local/opt/openssl@1.1/bin/c_rehash

openssl@1.1 is keg-only, which means it was not symlinked into /usr/local, because macOS provides LibreSSL.

If you need to have openssl@1.1 first in your PATH, run: echo ‘export PATH=“/usr/local/opt/openssl@1.1/bin:$PATH”’ >> ~/.zshrc

For compilers to find openssl@1.1 you may need to set: export LDFLAGS=“-L/usr/local/opt/openssl@1.1/lib” export CPPFLAGS=“-I/usr/local/opt/openssl@1.1/include”

For pkg-config to find openssl@1.1 you may need to set: export PKG_CONFIG_PATH=“/usr/local/opt/openssl@1.1/lib/pkgconfig”

==> Analytics install: 889,489 (30 days), 2,483,892 (90 days), 8,975,727 (365 days) install-on-request: 75,304 (30 days), 322,680 (90 days), 1,260,940 (365 days) build-error: 0 (30 days)

openssl version -a
OpenSSL 1.1.1k  25 Mar 2021
built on: Thu Mar 25 21:01:05 2021 UTC
platform: darwin64-x86_64-cc
options:  bn(64,64) rc4(16x,int) des(int) idea(int) blowfish(ptr) 
compiler: clang -fPIC -arch x86_64 -O3 -Wall -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_CPUID_OBJ -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DKECCAK1600_ASM -DRC4_ASM -DMD5_ASM -DAESNI_ASM -DVPAES_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -DX25519_ASM -DPOLY1305_ASM -D_REENTRANT -DNDEBUG
OPENSSLDIR: "/usr/local/etc/openssl@1.1"
ENGINESDIR: "/usr/local/Cellar/openssl@1.1/1.1.1k/lib/engines-1.1"
Seeding source: os-specific
openssl ciphers
TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:DHE-RSA-AES256-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES128-SHA:RSA-PSK-AES256-GCM-SHA384:DHE-PSK-AES256-GCM-SHA384:RSA-PSK-CHACHA20-POLY1305:DHE-PSK-CHACHA20-POLY1305:ECDHE-PSK-CHACHA20-POLY1305:AES256-GCM-SHA384:PSK-AES256-GCM-SHA384:PSK-CHACHA20-POLY1305:RSA-PSK-AES128-GCM-SHA256:DHE-PSK-AES128-GCM-SHA256:AES128-GCM-SHA256:PSK-AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:ECDHE-PSK-AES256-CBC-SHA384:ECDHE-PSK-AES256-CBC-SHA:SRP-RSA-AES-256-CBC-SHA:SRP-AES-256-CBC-SHA:RSA-PSK-AES256-CBC-SHA384:DHE-PSK-AES256-CBC-SHA384:RSA-PSK-AES256-CBC-SHA:DHE-PSK-AES256-CBC-SHA:AES256-SHA:PSK-AES256-CBC-SHA384:PSK-AES256-CBC-SHA:ECDHE-PSK-AES128-CBC-SHA256:ECDHE-PSK-AES128-CBC-SHA:SRP-RSA-AES-128-CBC-SHA:SRP-AES-128-CBC-SHA:RSA-PSK-AES128-CBC-SHA256:DHE-PSK-AES128-CBC-SHA256:RSA-PSK-AES128-CBC-SHA:DHE-PSK-AES128-CBC-SHA:AES128-SHA:PSK-AES128-CBC-SHA256:PSK-AES128-CBC-SHA
sudo nginx -t
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
which -a php-fpm
/usr/sbin/php-fpm
/usr/local/opt/php/sbin/php-fpm -v
PHP 8.0.3 (fpm-fcgi) (built: Mar  4 2021 20:45:30)
Copyright (c) The PHP Group
Zend Engine v4.0.3, Copyright (c) Zend Technologies
sudo /usr/local/opt/php/sbin/php-fpm -y /usr/local/etc/php/8.0/php-fpm.conf --test
[04-Apr-2021 11:09:20] ERROR: failed to open configuration file '/usr/local/etc/php/8.0/php-fpm.conf': No such file or directory (2)
[04-Apr-2021 11:09:20] ERROR: failed to load configuration file '/usr/local/etc/php/8.0/php-fpm.conf'
[04-Apr-2021 11:09:20] ERROR: FPM initialization failed
ls -al ~/Library/LaunchAgents | grep homebrew

ls -al /Library/LaunchAgents | grep homebrew

ls -al /Library/LaunchDaemons | grep homebrew
-rw-r--r--   1 root  admin   657 Apr  4 11:03 homebrew.mxcl.dnsmasq.plist
-rw-r--r--   1 root  admin   571 Apr  4 11:03 homebrew.mxcl.nginx.plist
-rw-r--r--   1 root  admin   628 Apr  4 11:03 homebrew.mxcl.php.plist
ls -al /Library/LaunchDaemons | grep "com.laravel.valet."

ls -aln /etc/resolv.conf
lrwxr-xr-x  1 0  0  22 Jan  1  2020 /etc/resolv.conf -> ../var/run/resolv.conf
cat /etc/resolv.conf
#
# macOS Notice
#
# This file is not consulted for DNS hostname resolution, address
# resolution, or the DNS query routing mechanism used by most
# processes on this system.
#
# To view the DNS configuration used by this system, use:
#   scutil --dns
#
# SEE ALSO
#   dns-sd(1), scutil(8)
#
# This file is automatically generated.
#
search 8.8.4.4 8.8.8.8
nameserver 8.8.8.8
ifconfig lo0
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
	options=1203<RXCSUM,TXCSUM,TXSTATUS,SW_TIMESTAMP>
	inet 127.0.0.1 netmask 0xff000000 
	inet6 ::1 prefixlen 128 
	inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 
	nd6 options=201<PERFORMNUD,DAD>
sh -c 'echo "------\n/usr/local/etc/nginx/valet/valet.conf\n---\n"; cat /usr/local/etc/nginx/valet/valet.conf | grep -n "# valet loopback"; echo "\n------\n"'
------
/usr/local/etc/nginx/valet/valet.conf
---

3: #listen VALET_LOOPBACK:80; # valet loopback

------

sh -c 'for file in ~/.config/valet/dnsmasq.d/*; do echo "------\n~/.config/valet/dnsmasq.d/$(basename $file)\n---\n"; cat $file; echo "\n------\n"; done'
------
~/.config/valet/dnsmasq.d/tld-com.conf
---

address=/.com/127.0.0.1 listen-address=127.0.0.1



~/.config/valet/dnsmasq.d/tld-test.conf

address=/.test/127.0.0.1 listen-address=127.0.0.1

------

sh -c 'for file in ~/.config/valet/nginx/*; do echo "------\n~/.config/valet/nginx/$(basename $file)\n---\n"; cat $file | grep -n "# valet loopback"; echo "\n------\n"; done'
------
~/.config/valet/nginx/altahalufgrouptest.test
---

3: #listen 127.0.0.1:80; # valet loopback 10: #listen 127.0.0.1:443 ssl http2; # valet loopback 54: #listen 127.0.0.1:60; # valet loopback



~/.config/valet/nginx/blog.test

3: #listen 127.0.0.1:80; # valet loopback 10: #listen 127.0.0.1:443 ssl http2; # valet loopback 54: #listen 127.0.0.1:60; # valet loopback



~/.config/valet/nginx/dev.test

3: #listen 127.0.0.1:80; # valet loopback 10: #listen 127.0.0.1:443 ssl http2; # valet loopback 54: #listen 127.0.0.1:60; # valet loopback



~/.config/valet/nginx/tailors_doctors.test

3: #listen 127.0.0.1:80; # valet loopback 10: #listen 127.0.0.1:443 ssl http2; # valet loopback 54: #listen 127.0.0.1:60; # valet loopback



~/.config/valet/nginx/test–chatbot.test

3: #listen 127.0.0.1:80; # valet loopback 10: #listen 127.0.0.1:443 ssl http2; # valet loopback 54: #listen 127.0.0.1:60; # valet loopback



~/.config/valet/nginx/travel_planet.test

3: #listen 127.0.0.1:80; # valet loopback 10: #listen 127.0.0.1:443 ssl http2; # valet loopback 54: #listen 127.0.0.1:60; # valet loopback



~/.config/valet/nginx/volcano.test

3: #listen 127.0.0.1:80; # valet loopback 10: #listen 127.0.0.1:443 ssl http2; # valet loopback 54: #listen 127.0.0.1:60; # valet loopback



~/.config/valet/nginx/wp-test.test

3: #listen 127.0.0.1:80; # valet loopback 10: #listen 127.0.0.1:443 ssl http2; # valet loopback 54: #listen 127.0.0.1:60; # valet loopback

------

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (6 by maintainers)

Most upvoted comments

Ok got it working!

Here is my command history. Remove all php traces and the walk through the install guide https://laravel.com/docs/8.x/valet#installation

Maybe this happened because I skipped the brew install php Or my php stuff was stained by https://github.com/weprovide/valet-plus

10319  sudo rm -rf /usr/local/Cellar/php
10320  sudo rm -rf /usr/local/Cellar/php*
10321  valet use php@7.4
10322  brew uninstall php@7.4
10325  sudo rm -rf /usr/local/etc/php
10326  brew uninstall php@7.4
10327  brew install php
10332  composer global update laravel/valet
10333  valet install
10334  valet use php@8.0
10335  valet use php@7.4
10336  valet use php@8.0

The Nginx “502 Bad Gateway” (almost) always means PHP isn’t running properly. Most of the time the logs will say valet.sock not found, which confirms PHP isn’t running properly. This (almost) always means you’ve got conflicting versions running.

If you look at the LaunchAgents output, you’ll see that you have all of Valet’s services starting as local user … but then valet needs to (and automatically does) run all those as root. But since you’ve manually started all the services as non-root the processes are clashing and permissions don’t match and thus files aren’t found properly, so you get all these weird symptoms.

Run:

valet stop
brew services stop dnsmasq
brew services stop nginx
brew services stop php@7.4
valet restart dnsmasq
valet start

And then stop starting dnsmasq/nginx/php (of any version) without sudo. In fact, best not to use any brew commands with those apps, but rather use valet commands instead.