laravel / valet

A more enjoyable local development experience for Mac.
https://laravel.com/docs/valet
MIT License
2.5k stars 690 forks source link

PHP 8.0 gives a 502 Bad Gateway error, there is no valet.sock. #1056

Closed Crinsane closed 3 years ago

Crinsane commented 3 years ago

Clear description of your problem

PHP 8.0 gives a 502 Bad Gateway error, there is no valet.sock.

Expected behavior

When switching between PHP versions, everything should work correctly, but PHP 8.0 is not working

Current behavior

When I'm running Valet on PHP 7.4, everything is working as expected. When I switch to PHP 8.0 (either using PHP Monitor.app, or using valet use php) I get a 502 Bad Gateway error.

I've tried to debug what is going on, and using valet log nginx -f I see this message:

2021/04/29 19:42:18 [crit] 8369#0: *1 connect() to unix:/Users/crinsane/.config/valet/valet.sock failed (2: No such file or directory) while connecting to upstream, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/Users/crinsane/.config/valet/valet.sock:", host: "website.test"

And indeed, when I go to my home directory, and then .config/valet I see there is no valet.sock.

If I switch back to PHP 7.4, valet.sock shows back up again, but it's always gone when switching to PHP 8.0.

I've reinstalled Valet, reinstalled PHP, run valet install 1000 times, but I'm running out of ideas.

Diagnosis

sw_vers
ProductName:   macOS
ProductVersion: 11.2.3
BuildVersion:   20D91
valet --version
Laravel Valet 2.14.1
cat ~/.config/valet/config.json
{
    "tld": "test",
    "paths": [
        "/Users/robgloudemans/.config/valet/Sites",
        "/Users/robgloudemans/Sites"
    ],
    "loopback": "127.0.0.1"
}
cat ~/.composer/composer.json
{
    "require": {
        "laravel/installer": "^4.0",
        "squizlabs/php_codesniffer": "*",
        "laravel/valet": "^2.14"
    }
}
composer global diagnose
Changed current directory to /Users/robgloudemans/.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.squizlabs/php_codesniffer : unbound version constraints (*) 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: OK
Composer version: 2.0.13
PHP version: 8.0.5
PHP binary path: /usr/local/Cellar/php/8.0.5/bin/php
OpenSSL version: OpenSSL 1.1.1k  25 Mar 2021
cURL version: 7.76.1 libz 1.2.11 ssl (SecureTransport) OpenSSL/1.1.1k
zip: extension present, unzip present
composer global outdated
Changed current directory to /Users/robgloudemans/.composer
psr/container 1.1.1 ~ 2.0.1 Common Container Interface (PHP FIG PSR-11)
ls -al /etc/sudoers.d/
total 16
drwxr-xr-x    4 root  wheel   128 Apr  5 23:09 .
drwxr-xr-x  115 root  wheel  3680 Apr 29 19:34 ..
-rw-r--r--    1 root  wheel    80 Apr 28 20:00 brew
-rw-r--r--    1 root  wheel    83 Apr 28 20:00 valet
brew config
HOMEBREW_VERSION: 3.1.4
ORIGIN: https://github.com/Homebrew/brew
HEAD: 94ce3236a517dfae6b492dcb4fd6b726a6175e8f
Last commit: 2 days ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: bbc0d09a1628b9046fdc568b69e2b636aa946ab8
Core tap last commit: 5 minutes ago
Core tap branch: master
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 12
Homebrew Ruby: 2.6.3 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: dodeca-core 64-bit kabylake
Clang: 12.0 build 1205
Git: 2.31.1 => /usr/local/bin/git
Curl: 7.64.1 => /usr/bin/curl
macOS: 11.2.3-x86_64
CLT: 12.4.0.0.1.1610135815
Xcode: 12.5
brew services list
Name      Status  User          Plist
dbus      stopped               
dnsmasq   unknown root          /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
mysql@5.7 started robgloudemans /Users/robgloudemans/Library/LaunchAgents/homebrew.mxcl.mysql@5.7.plist
nginx     error   root          /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
php       unknown root          /Library/LaunchDaemons/homebrew.mxcl.php.plist
php@7.4   unknown root          /Library/LaunchDaemons/homebrew.mxcl.php@7.4.plist
redis     started robgloudemans /Users/robgloudemans/Library/LaunchAgents/homebrew.mxcl.redis.plist
unbound   stopped
brew list --formula --versions | grep -E "(php|nginx|dnsmasq|mariadb|mysql|mailhog|openssl)(@\d\..*)?\s"
dnsmasq 2.85
mysql@5.7 5.7.34
nginx 1.19.10
openssl@1.1 1.1.1k
php 8.0.5
php@7.4 7.4.16_1
brew outdated

brew tap
heroku/brew
homebrew/core
homebrew/services
ibm-swift/kitura
microsoft/mssql-release
nicoverbruggen/cask
vapor/tap
php -v
PHP 8.0.5 (cli) (built: Apr 29 2021 16:01:35) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.5, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.5, Copyright (c), by Zend Technologies
which -a php
/usr/local/bin/php
/usr/bin/php
php --ini
Configuration File (php.ini) Path: /usr/local/etc/php/8.0
Loaded Configuration File:         /usr/local/etc/php/8.0/php.ini
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/ext-opcache.ini,
/usr/local/etc/php/8.0/conf.d/php-memory-limits.ini
nginx -v
nginx version: nginx/1.19.10
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.1
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
ls: /Users/robgloudemans/.ngrok2: No such file or directory
brew info nginx
nginx: stable 1.19.10 (bottled), HEAD
HTTP(S) server and reverse proxy, and IMAP/POP3 proxy server
https://nginx.org/
/usr/local/Cellar/nginx/1.19.10 (25 files, 2.2MB) *
  Poured from bottle on 2021-04-28 at 19:32:16
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: 52,073 (30 days), 141,533 (90 days), 490,528 (365 days)
install-on-request: 51,948 (30 days), 141,202 (90 days), 484,599 (365 days)
build-error: 0 (30 days)
brew info php
php: stable 8.0.5 (bottled), HEAD
General-purpose scripting language
https://www.php.net/
/usr/local/Cellar/php/8.0.5 (499 files, 77.8MB) *
  Poured from bottle on 2021-04-29 at 19:41:31
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

    
        SetHandler application/x-httpd-php
    

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: 39,645 (30 days), 141,624 (90 days), 623,681 (365 days)
install-on-request: 39,014 (30 days), 139,124 (90 days), 607,774 (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-04-07 at 23:18:35
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: 918,009 (30 days), 2,603,371 (90 days), 8,877,460 (365 days)
install-on-request: 72,097 (30 days), 280,124 (90 days), 1,180,360 (365 days)
build-error: 0 (30 days)
openssl version -a
LibreSSL 2.8.3
built on: date not available
platform: information not available
options:  bn(64,64) rc4(16x,int) des(idx,cisc,16,int) blowfish(idx) 
compiler: information not available
OPENSSLDIR: "/private/etc/ssl"
openssl ciphers
ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-CHACHA20-POLY1305:GOST2012256-GOST89-GOST89:DHE-RSA-CAMELLIA256-SHA256:DHE-RSA-CAMELLIA256-SHA:GOST2001-GOST89-GOST89:AES256-GCM-SHA384:AES256-SHA256:AES256-SHA:CAMELLIA256-SHA256:CAMELLIA256-SHA:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-CAMELLIA128-SHA256:DHE-RSA-CAMELLIA128-SHA:AES128-GCM-SHA256:AES128-SHA256:AES128-SHA:CAMELLIA128-SHA256:CAMELLIA128-SHA:ECDHE-RSA-RC4-SHA:ECDHE-ECDSA-RC4-SHA:RC4-SHA:RC4-MD5:ECDHE-RSA-DES-CBC3-SHA:ECDHE-ECDSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:DES-CBC3-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/local/sbin/php-fpm
/usr/sbin/php-fpm
/usr/local/opt/php/sbin/php-fpm -v
PHP 8.0.5 (fpm-fcgi) (built: Apr 29 2021 16:01:47)
Copyright (c) The PHP Group
Zend Engine v4.0.5, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.5, Copyright (c), by Zend Technologies
sudo /usr/local/opt/php/sbin/php-fpm -y /usr/local/etc/php/8.0/php-fpm.conf --test
[29-Apr-2021 19:50:14] NOTICE: configuration file /usr/local/etc/php/8.0/php-fpm.conf test is successful
ls -al ~/Library/LaunchAgents | grep homebrew
-rw-r--r--   1 robgloudemans  staff   551 Oct 23  2018 homebrew.mxcl.mysql@5.7.plist
-rw-r--r--   1 robgloudemans  staff   571 Apr 28 20:01 homebrew.mxcl.nginx.plist
-rw-r--r--   1 robgloudemans  staff   823 Mar 26  2020 homebrew.mxcl.redis.plist
ls -al /Library/LaunchAgents | grep homebrew

ls -al /Library/LaunchDaemons | grep homebrew
-rw-r--r--   1 root  admin   657 Apr 29 19:42 homebrew.mxcl.dnsmasq.plist
-rw-r--r--   1 root  admin   571 Apr 29 19:46 homebrew.mxcl.nginx.plist
-rw-r--r--   1 root  admin   524 Apr 29 19:46 homebrew.mxcl.php.plist
-rw-r--r--   1 root  admin   636 Apr 29 19:42 homebrew.mxcl.php@7.4.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.
#
nameserver 192.168.1.1
ifconfig lo0
lo0: flags=8049 mtu 16384
    options=1203
    inet 127.0.0.1 netmask 0xff000000 
    inet6 ::1 prefixlen 128 
    inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 
    nd6 options=201
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-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/cupcakecute.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

------
drbyte commented 3 years ago

And indeed, when I go to my home directory, and then .config/valet I see there is no valet.sock. If I switch back to PHP 7.4, valet.sock shows back up again, but it's always gone when switching to PHP 8.0.

When the valet.sock isn't getting created, it's typically because the intended PHP version's config is encountering an error, causing PHP-FPM not to start ... which is why there's no valet.sock file.

drbyte commented 3 years ago

ls -al ~/Library/LaunchAgents | grep homebrew -rw-r--r-- 1 robgloudemans staff 571 Apr 28 20:01 homebrew.mxcl.nginx.plist ls -al /Library/LaunchDaemons | grep homebrew -rw-r--r-- 1 root admin 571 Apr 29 19:46 homebrew.mxcl.nginx.plist

I see you've got Nginx running both as non-root and root. Valet uses root (sudo). To fix this conflict, stop the non-root one with brew services stop nginx.

Crinsane commented 3 years ago

When the valet.sock isn't getting created, it's typically because the intended PHP version's config is encountering an error, causing PHP-FPM not to start ... which is why there's no valet.sock file.

Okay, is there a place where I can find where the configuration is wrong? I didn't change any config, it should be a clean install

I see you've got Nginx running both as non-root and root. Valet uses root (sudo). To fix this conflict, stop the non-root one with brew services stop nginx.

Done

Alanaktion commented 3 years ago

I'm also seeing this issue after updating to PHP 8.0.5, including updating Valet and re-running valet install, also including a full clean reinstall of the latest nignx, php, and valet. From what I'm seeing, the .plist file being generated by brew-services is invalid, with the ProgramArguments being a single string value instead of the array.

When I manually execute the php-fpm binary it actually serves things just fine through Valet's configuration, but starting the FPM service from valet start php or brew services start php fails to start the process.

Crinsane commented 3 years ago

When I manually execute the php-fpm binary it actually serves things just fine through Valet's configuration, but starting the FPM service from valet start php or brew services start php fails to start the process.

Same for me

drbyte commented 3 years ago

On a non-M1 Mac, today I upgraded Homebrew via brew upgrade and it upgraded my installed PHP versions to 8.0.5 and 7.4.18.

Using valet use php@7.4 and valet use php@8.0 to switch between versions works correctly. I've confirmed that PHP is both running and showing correct PHP versions in-app by dumping phpinfo() and checking between switching PHP versions with valet use x.

Today's plist files (/Library/LaunchDaemons/homebrew.mxcl.php@7.4.plist and /Library/LaunchDaemons/homebrew.mxcl.php.plist) appear to be correctly built:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>KeepAlive</key>
    <true/>
    <key>Label</key>
    <string>homebrew.mxcl.php@7.4</string>
    <key>ProgramArguments</key>
    <array>
      <string>/usr/local/opt/php@7.4/sbin/php-fpm</string>
      <string>--nodaemonize</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>WorkingDirectory</key>
    <string>/usr/local/var</string>
    <key>StandardErrorPath</key>
    <string>/usr/local/var/log/php-fpm.log</string>
  </dict>
</plist>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>KeepAlive</key>
    <true/>
    <key>Label</key>
    <string>homebrew.mxcl.php</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/opt/php/sbin/php-fpm</string>
        <string>--nodaemonize</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>StandardErrorPath</key>
    <string>/usr/local/var/log/php-fpm.log</string>
    <key>WorkingDirectory</key>
    <string>/usr/local/var</string>
</dict>
</plist>

Maybe homebrew had a bug for a couple days?

Crinsane commented 3 years ago

I've just uninstall PHP 8.0, removed the plist file. Reinstalled PHP 8.0 again and run valet use php --force and now everything seems to be working fine again. 👍

Thanks a lot