laravel / valet

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

Valet 502 Error working with PostgreSQL and MongoDB #1433

Closed monoland closed 11 months ago

monoland commented 1 year ago

Description

502 Bad Gateway

Screenshot 2023-07-22 at 19 00 32

Steps To Reproduce

php artisan session:table php artisan migrate

edit SESSION_DRIVER=database on .env

Diagnosis

sw_vers
ProductName:       macOS
ProductVersion:     13.4.1
ProductVersionExtra:    (c)
BuildVersion:       22F770820d
valet --version
Laravel Valet 4.1.3
cat ~/.config/valet/config.json
{
    "tld": "test",
    "loopback": "127.0.0.1",
    "paths": [
        "/Users/monoland/.config/valet/Sites"
    ]
}
cat ~/.composer/composer.json
{
    "require": {
        "laravel/valet": "^4.1",
        "laravel/installer": "^4.5"
    }
}
composer global diagnose
Changed current directory to /Users/monoland/.composer
Checking composer.json: WARNING
No license specified, it is recommended to do so. For closed-source software you may use "proprietary" as license.
Checking platform settings: OK
Checking git settings: OK git version 2.39.2
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com rate limit: 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.5.8
PHP version: 8.2.8
PHP binary path: /usr/local/Cellar/php/8.2.8/bin/php
OpenSSL version: OpenSSL 3.1.1 30 May 2023
cURL version: 8.2.0 libz 1.2.11 ssl (SecureTransport) OpenSSL/3.1.1
zip: extension present, unzip present, 7-Zip not available
composer global outdated
Changed current directory to /Users/monoland/.composer
Info from https://repo.packagist.org: #StandWithUkraine

Direct dependencies required in composer.json:
Everything up to date

Transitive dependencies not required in composer.json:
Everything up to date
ls -al /etc/sudoers.d/
total 0
drwxr-xr-x   2 root  wheel    64 Jun 15 17:08 .
drwxr-xr-x  80 root  wheel  2560 Jul 22 16:29 ..
brew config
HOMEBREW_VERSION: 4.1.0
ORIGIN: https://github.com/Homebrew/brew
HEAD: ac93842f8d13913f462aedb246cfacd08d6b7f05
Last commit: 3 days ago
Core tap JSON: 22 Jul 12:04 UTC
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 8
Homebrew Ruby: 2.6.10 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: octa-core 64-bit kabylake
Clang: 14.0.3 build 1403
Git: 2.39.2 => /Library/Developer/CommandLineTools/usr/bin/git
Curl: 7.88.1 => /usr/bin/curl
macOS: 13.4.1-x86_64
CLT: 14.3.1.0.1.1683849156
Xcode: N/A
brew services list
Name    Status User File
dnsmasq none            root 
httpd   none                 
nginx   none            root 
php     error  19968    root ~/Library/LaunchAgents/homebrew.mxcl.php.plist
brew list --formula --versions | grep -E "(php|nginx|dnsmasq|mariadb|mysql|mailhog|openssl)(@\d\..*)?\s"
dnsmasq 2.89
nginx 1.25.1_1
php 8.2.8
brew outdated

brew tap
homebrew/services
shivammathur/php
php -v
PHP 8.2.8 (cli) (built: Jul 22 2023 07:18:42) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.8, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.8, Copyright (c), by Zend Technologies
which -a php
/usr/local/bin/php
/usr/local/bin/php
php --ini
Configuration File (php.ini) Path: /usr/local/etc/php/8.2
Loaded Configuration File:         /usr/local/etc/php/8.2/php.ini
Scan for additional .ini files in: /usr/local/etc/php/8.2/conf.d
Additional .ini files parsed:      /usr/local/etc/php/8.2/conf.d/error_log.ini,
/usr/local/etc/php/8.2/conf.d/ext-opcache.ini,
/usr/local/etc/php/8.2/conf.d/php-memory-limits.ini
nginx -v
nginx version: nginx/1.25.1
curl --version
curl 7.88.1 (x86_64-apple-darwin22.0) libcurl/7.88.1 (SecureTransport) LibreSSL/3.3.6 zlib/1.2.11 nghttp2/1.51.0
Release-Date: 2023-02-20
Protocols: dict file ftp ftps gopher gophers http https imap imaps ldap ldaps mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS GSS-API HSTS HTTP2 HTTPS-proxy IPv6 Kerberos Largefile libz MultiSSL NTLM NTLM_WB SPNEGO SSL threadsafe UnixSockets
php --ri curl
curl

cURL support => enabled
cURL Information => 8.2.0
Age => 10
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
ALTSVC => Yes
HTTP3 => No
UNICODE => No
ZSTD => Yes
HSTS => Yes
GSASL => No
Protocols => dict, file, ftp, ftps, gopher, gophers, http, https, imap, imaps, ldap, ldaps, mqtt, pop3, pop3s, rtmp, rtmpe, rtmps, rtmpt, rtmpte, rtmpts, rtsp, scp, sftp, smb, smbs, smtp, smtps, telnet, tftp
Host => x86_64-apple-darwin22.4.0
SSL Version => (SecureTransport) OpenSSL/3.1.1
ZLib Version => 1.2.11
libSSH Version => libssh2/1.11.0

Directive => Local Value => Master Value
curl.cainfo => no value => no value
/usr/local/bin/ngrok version
sudo: /usr/local/bin/ngrok: command not found
ls -al ~/.ngrok2
ls: /Users/monoland/.ngrok2: No such file or directory
brew info nginx
==> nginx: stable 1.25.1 (bottled), HEAD
HTTP(S) server and reverse proxy, and IMAP/POP3 proxy server
https://nginx.org/
/usr/local/Cellar/nginx/1.25.1_1 (26 files, 2.4MB) *
  Poured from bottle using the formulae.brew.sh API on 2023-07-22 at 13:47:05
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/nginx.rb
License: BSD-2-Clause
==> Dependencies
Required: openssl@3, pcre2
==> 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 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:
  /usr/local/opt/nginx/bin/nginx -g daemon off;
==> Analytics
install: 16,199 (30 days), 56,757 (90 days), 75,487 (365 days)
install-on-request: 16,179 (30 days), 56,682 (90 days), 75,380 (365 days)
build-error: 4 (30 days)
brew info php
==> php: stable 8.2.8 (bottled), HEAD
General-purpose scripting language
https://www.php.net/
/usr/local/Cellar/php/8.2.8 (514 files, 81.4MB) *
  Built from source on 2023-07-22 at 14:19:43
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, gmp, icu4c, krb5, libpq, libsodium, libzip, oniguruma, openldap, openssl@3, 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.2/

To restart php after an upgrade:
  brew services restart php
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/php/sbin/php-fpm --nodaemonize
==> Analytics
install: 45,997 (30 days), 162,345 (90 days), 212,607 (365 days)
install-on-request: 42,464 (30 days), 150,312 (90 days), 196,773 (365 days)
build-error: 57 (30 days)
brew info openssl
==> openssl@3: stable 3.1.1 (bottled)
Cryptography and SSL/TLS Toolkit
https://openssl.org/
/usr/local/Cellar/openssl@3/3.1.1_1 (6,495 files, 29.9MB) *
  Poured from bottle using the formulae.brew.sh API on 2023-07-22 at 13:09:08
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/openssl@3.rb
License: Apache-2.0
==> Dependencies
Required: ca-certificates
==> 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@3/certs

and run
  /usr/local/opt/openssl@3/bin/c_rehash
==> Analytics
install: 320,216 (30 days), 696,324 (90 days), 839,331 (365 days)
install-on-request: 40,469 (30 days), 186,475 (90 days), 226,316 (365 days)
build-error: 1,075 (30 days)
openssl version -a
OpenSSL 3.1.1 30 May 2023 (Library: OpenSSL 3.1.1 30 May 2023)
built on: Tue May 30 12:13:24 2023 UTC
platform: darwin64-x86_64-cc
options:  bn(64,64)
compiler: clang -fPIC -arch x86_64 -O3 -Wall -DL_ENDIAN -DOPENSSL_PIC -D_REENTRANT -DOPENSSL_BUILDING_OPENSSL -DNDEBUG
OPENSSLDIR: "/usr/local/etc/openssl@3"
ENGINESDIR: "/usr/local/Cellar/openssl@3/3.1.1_1/lib/engines-3"
MODULESDIR: "/usr/local/Cellar/openssl@3/3.1.1_1/lib/ossl-modules"
Seeding source: os-specific
CPUINFO: OPENSSL_ia32cap=0x7ffaf3bfffebffff:0x29c67af
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: [warn] the "listen ... http2" directive is deprecated, use the "http2" directive instead in /Users/monoland/.config/valet/Nginx/backend.citragroup.test:11
nginx: [warn] the "http2_push_preload" directive is obsolete, ignored in /Users/monoland/.config/valet/Nginx/backend.citragroup.test:17
nginx: [warn] the "listen ... http2" directive is deprecated, use the "http2" directive instead in /Users/monoland/.config/valet/Nginx/backend.simasten.bantenprov.test:11
nginx: [warn] the "http2_push_preload" directive is obsolete, ignored in /Users/monoland/.config/valet/Nginx/backend.simasten.bantenprov.test:17
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/opt/php/sbin/php-fpm -v
PHP 8.2.8 (fpm-fcgi) (built: Jul 22 2023 07:18:46)
Copyright (c) The PHP Group
Zend Engine v4.2.8, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.8, Copyright (c), by Zend Technologies
sudo /usr/local/opt/php/sbin/php-fpm -y /usr/local/etc/php/8.2/php-fpm.conf --test
[22-Jul-2023 19:04:46] NOTICE: configuration file /usr/local/etc/php/8.2/php-fpm.conf test is successful
ls -al ~/Library/LaunchAgents | grep homebrew
-rw-r--r--@  1 monoland  staff   772 Jul 22 13:25 homebrew.mxcl.php.plist
ls -al /Library/LaunchAgents | grep homebrew

ls -al /Library/LaunchDaemons | grep homebrew
-rw-r--r--@  1 root  admin   788 Jul 22 14:22 homebrew.mxcl.dnsmasq.plist
-rw-r--r--@  1 root  admin   679 Jul 22 16:25 homebrew.mxcl.nginx.plist
-rw-r--r--@  1 root  admin   772 Jul 22 14:22 homebrew.mxcl.php.plist
ls -al /Library/LaunchDaemons | grep "com.laravel.valet."

ls -aln /etc/resolv.conf
lrwxr-xr-x  1 0  0  22 Jun 15 17:08 /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 fe80::c0fd:93ff:fee9:73d0%en0
nameserver 192.168.8.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/backend.citragroup.test
---

5:    #listen 127.0.0.1:80; # valet loopback
12:    #listen 127.0.0.1:443 ssl http2; # valet loopback

------

------
~/.config/valet/nginx/backend.simasten.bantenprov.test
---

5:    #listen 127.0.0.1:80; # valet loopback
12:    #listen 127.0.0.1:443 ssl http2; # valet loopback

------
driesvints commented 1 year ago

Hey there,

Can you first please try one of the support channels below? If you can actually identify this as a bug, feel free to open up a new issue with a link to the original one and we'll gladly help you out.

Thanks!

monoland commented 1 year ago

I've been looking for a solution all day in every forum and even reinstalling macOS, if I use SESSION_DRIVER other than database valet was OK

monoland commented 1 year ago

and if anyone has same problem, just switch back to valet v4.1.2 and session_driver=database was runing good. thanks

drbyte commented 1 year ago

@monoland A 502 error reported by Nginx will be recorded in the Nginx server logs, with details about the actual cause of the error. Can you share those details? It will help us confirm whether there's any bug in Valet.

You will probably find those details in /Users/your_username/.config/valet/Log/nginx-error.log

drbyte commented 1 year ago

I've finally had time to test the situation described, and cannot replicate the problem, using both Valet 4.1.2 and 4.1.3. (The change from 4.1.2 to 4.1.3 was extremely minor, and had no relationship to database factors.)

cd ~/Sites
laravel new foo
cd foo
valet open
sed -i '' 's/DB_CONNECTION=mysql/DB_CONNECTION=sqlite/' .env
sed -i '' 's/DB_DATABASE=/#DB_DATABASE=/' .env
touch database/database.sqlite
php artisan session:table
php artisan migrate
valet open
brew services start mariadb
mysqld -uroot -p   ##logged in and created database
sed -i '' 's/DB_CONNECTION=sqlite/DB_CONNECTION=mysql/' .env
sed -i '' 's/\#DB_DATABASE=/DB_DATABASE=/' .env
php artisan migrate:fresh
valet open
djfhe commented 1 year ago

Having the same problem. I was able to reproduce it in a fresh laravel project with postgres. With sqlite and mysql it works fine. mysql and postgres ran in a docker container.

Works fine, when served via artisan serve

Problems also happens on 4.1.2, so probably not a valet problem, but any help is appreciated :)

valet log php-fpm -f --lines=20

``` [23-Jul-2023 23:30:30] WARNING: [pool valet] child 57272 exited on signal 6 (SIGABRT) after 44.809516 seconds from start [23-Jul-2023 23:30:30] NOTICE: [pool valet] child 57458 started [23-Jul-2023 23:30:32] WARNING: [pool valet] child 57458 exited on signal 9 (SIGKILL) after 1.773915 seconds from start [23-Jul-2023 23:30:32] NOTICE: [pool valet] child 57463 started [23-Jul-2023 23:30:33] WARNING: [pool valet] child 57463 exited on signal 6 (SIGABRT) after 1.098928 seconds from start [23-Jul-2023 23:30:33] NOTICE: [pool valet] child 57471 started [23-Jul-2023 23:30:34] WARNING: [pool valet] child 57471 exited on signal 6 (SIGABRT) after 0.927223 seconds from start [23-Jul-2023 23:30:34] NOTICE: [pool valet] child 57479 started [23-Jul-2023 23:30:41] WARNING: [pool valet] child 57479 exited on signal 6 (SIGABRT) after 6.795968 seconds from start [23-Jul-2023 23:30:41] NOTICE: [pool valet] child 57508 started [23-Jul-2023 23:30:57] WARNING: [pool valet] child 57508 exited on signal 6 (SIGABRT) after 15.500840 seconds from start [23-Jul-2023 23:30:57] NOTICE: [pool valet] child 57594 started [23-Jul-2023 23:30:58] WARNING: [pool valet] child 57594 exited on signal 9 (SIGKILL) after 1.113476 seconds from start [23-Jul-2023 23:30:58] NOTICE: [pool valet] child 57603 started [23-Jul-2023 23:30:58] WARNING: [pool valet] child 57603 exited on signal 6 (SIGABRT) after 0.830134 seconds from start [23-Jul-2023 23:30:58] NOTICE: [pool valet] child 57611 started [23-Jul-2023 23:30:59] WARNING: [pool valet] child 57611 exited on signal 6 (SIGABRT) after 0.694385 seconds from start [23-Jul-2023 23:30:59] NOTICE: [pool valet] child 57619 started [23-Jul-2023 23:31:00] WARNING: [pool valet] child 57619 exited on signal 6 (SIGABRT) after 0.576138 seconds from start [23-Jul-2023 23:31:00] NOTICE: [pool valet] child 57624 started ```

valet log nginx -f --lines=10

``` 2023/07/23 23:30:30 [error] 50639#0: *77 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/Users/danielthoma/.config/valet/valet.sock:", host: "foo.test" 2023/07/23 23:30:32 [error] 50639#0: *77 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/Users/danielthoma/.config/valet/valet.sock:", host: "foo.test" 2023/07/23 23:30:33 [error] 50639#0: *77 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/Users/danielthoma/.config/valet/valet.sock:", host: "foo.test" 2023/07/23 23:30:34 [error] 50639#0: *77 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/Users/danielthoma/.config/valet/valet.sock:", host: "foo.test" 2023/07/23 23:30:41 [error] 50639#0: *77 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/Users/danielthoma/.config/valet/valet.sock:", host: "foo.test" 2023/07/23 23:30:57 [error] 50639#0: *77 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/Users/danielthoma/.config/valet/valet.sock:", host: "foo.test" 2023/07/23 23:30:58 [error] 50639#0: *77 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/Users/danielthoma/.config/valet/valet.sock:", host: "foo.test" 2023/07/23 23:30:58 [error] 50639#0: *77 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/Users/danielthoma/.config/valet/valet.sock:", host: "foo.test" 2023/07/23 23:30:59 [error] 50639#0: *77 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/Users/danielthoma/.config/valet/valet.sock:", host: "foo.test" 2023/07/23 23:31:00 [error] 50639#0: *77 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/Users/danielthoma/.config/valet/valet.sock:", host: "foo.test" ```

sw_vers
ProductName:       macOS
ProductVersion:     13.4.1
ProductVersionExtra:    (c)
BuildVersion:       22F770820d
valet --version
Laravel Valet 4.1.3
cat ~/.config/valet/config.json
{
    "tld": "test",
    "loopback": "127.0.0.1",
    "paths": [
        "/Users/danielthoma/.config/valet/Sites",
        "/Users/danielthoma/git/clickbar",
        "/Users/danielthoma/git/konaktiva",
        "/Users/danielthoma/git/private"
    ]
}
cat ~/.composer/composer.json
{
    "require": {
        "laravel/installer": "^4.4",
        "laravel/valet": "^4.1",
        "tightenco/takeout": "^2.4"
    }
}
composer global diagnose
Changed current directory to /Users/danielthoma/.composer
Checking composer.json: WARNING
No license specified, it is recommended to do so. For closed-source software you may use "proprietary" as license.
Checking platform settings: OK
Checking git settings: OK git version 2.41.0
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com rate limit: OK
Checking disk free space: OK
Checking pubkeys: FAIL
Missing pubkey for tags verification
Missing pubkey for dev verification
Run composer self-update --update-keys to set them up
Checking composer version: OK
Composer version: 2.5.8
PHP version: 8.2.8
PHP binary path: /opt/homebrew/Cellar/php/8.2.8/bin/php
OpenSSL version: OpenSSL 3.1.1 30 May 2023
cURL version: 8.2.0 libz 1.2.11 ssl (SecureTransport) OpenSSL/3.1.1
zip: extension present, unzip present, 7-Zip not available
composer global outdated
Changed current directory to /Users/danielthoma/.composer
Legend:
! patch or minor release available - update recommended
~ major release available - update possible

Direct dependencies required in composer.json:
Everything up to date

Transitive dependencies not required in composer.json:
guzzlehttp/psr7  1.9.1 ~ 2.5.0 PSR-7 message implementation that also provid...
psr/http-message 1.1   ~ 2.0   Common interface for HTTP messages
ls -al /etc/sudoers.d/
total 0
drwxr-xr-x   2 root  wheel    64 Jun 15 12:08 .
drwxr-xr-x  80 root  wheel  2560 Jul 16 14:28 ..
brew config
HOMEBREW_VERSION: 4.1.0
ORIGIN: https://github.com/Homebrew/brew
HEAD: ac93842f8d13913f462aedb246cfacd08d6b7f05
Last commit: 4 days ago
Core tap origin: https://github.com/Homebrew/homebrew-core
Core tap HEAD: eb3088f5a5ebd859a4999f1d1f2403b9e6f88126
Core tap last commit: 5 months ago
Core tap branch: master
Core tap JSON: 23 Jul 21:39 UTC
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 8
Homebrew Ruby: 2.6.10 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: octa-core 64-bit arm_firestorm_icestorm
Clang: 14.0.3 build 1403
Git: 2.41.0 => /opt/homebrew/bin/git
Curl: 7.88.1 => /usr/bin/curl
macOS: 13.4.1-arm64
CLT: 14.3.1.0.1.1683849156
Xcode: N/A
Rosetta 2: false
brew services list
Name          Status User File
dnsmasq       none            root 
meilisearch   none                 
nginx         none            root 
openvpn       none                 
php           started         root ~/Library/LaunchAgents/homebrew.mxcl.php.plist
php@8.1       none                 
postgresql@14 none                 
stripe-mock   none                 
unbound       none
brew list --formula --versions | grep -E "(php|nginx|dnsmasq|mariadb|mysql|mailhog|openssl)(@\d\..*)?\s"
dnsmasq 2.87 2.89 2.88 2.86
nginx 1.25.1_1 1.25.1
openssl@1.1 1.1.1u
php 8.1.12 8.2.7 8.2.8 8.2.6 8.1.3_1 8.2.7_1 8.1.7 8.1.10 8.1.11 8.2.3 8.2.4 8.2.5 8.2.7_2 8.1.10_1 8.1.5
php@8.1 8.1.21 8.1.14_1
brew outdated

brew tap
homebrew/bundle
homebrew/cask
homebrew/cask-fonts
homebrew/cask-versions
homebrew/core
homebrew/services
nicoverbruggen/cask
oven-sh/bun
stripe/stripe-cli
stripe/stripe-mock
traildb/judy
php -v
PHP 8.2.8 (cli) (built: Jul  6 2023 10:57:44) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.8, Copyright (c) Zend Technologies
    with Xdebug v3.2.1, Copyright (c) 2002-2023, by Derick Rethans
    with Zend OPcache v8.2.8, Copyright (c), by Zend Technologies
which -a php
/opt/homebrew/bin/php
php --ini
Configuration File (php.ini) Path: /opt/homebrew/etc/php/8.2
Loaded Configuration File:         /opt/homebrew/etc/php/8.2/php.ini
Scan for additional .ini files in: /opt/homebrew/etc/php/8.2/conf.d
Additional .ini files parsed:      /opt/homebrew/etc/php/8.2/conf.d/99-memprof.ini,
/opt/homebrew/etc/php/8.2/conf.d/99-xdebug.ini,
/opt/homebrew/etc/php/8.2/conf.d/error_log.ini,
/opt/homebrew/etc/php/8.2/conf.d/ext-opcache.ini,
/opt/homebrew/etc/php/8.2/conf.d/php-memory-limits.ini
nginx -v
nginx version: nginx/1.25.1
curl --version
curl 7.88.1 (x86_64-apple-darwin22.0) libcurl/7.88.1 (SecureTransport) LibreSSL/3.3.6 zlib/1.2.11 nghttp2/1.51.0
Release-Date: 2023-02-20
Protocols: dict file ftp ftps gopher gophers http https imap imaps ldap ldaps mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS GSS-API HSTS HTTP2 HTTPS-proxy IPv6 Kerberos Largefile libz MultiSSL NTLM NTLM_WB SPNEGO SSL threadsafe UnixSockets
php --ri curl
curl

cURL support => enabled
cURL Information => 8.2.0
Age => 10
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
ALTSVC => Yes
HTTP3 => No
UNICODE => No
ZSTD => Yes
HSTS => Yes
GSASL => No
Protocols => dict, file, ftp, ftps, gopher, gophers, http, https, imap, imaps, ldap, ldaps, mqtt, pop3, pop3s, rtmp, rtmpe, rtmps, rtmpt, rtmpte, rtmpts, rtsp, scp, sftp, smb, smbs, smtp, smtps, telnet, tftp
Host => aarch64-apple-darwin22.4.0
SSL Version => (SecureTransport) OpenSSL/3.1.1
ZLib Version => 1.2.11
libSSH Version => libssh2/1.11.0

Directive => Local Value => Master Value
curl.cainfo => no value => no value
/opt/homebrew/bin/ngrok version
sudo: /opt/homebrew/bin/ngrok: command not found
ls -al ~/.ngrok2
ls: /Users/danielthoma/.ngrok2: No such file or directory
brew info nginx
==> nginx: stable 1.25.1 (bottled), HEAD
HTTP(S) server and reverse proxy, and IMAP/POP3 proxy server
https://nginx.org/
/opt/homebrew/Cellar/nginx/1.25.1 (23 files, 2.4MB)
  Built from source
/opt/homebrew/Cellar/nginx/1.25.1_1 (26 files, 2.4MB) *
  Poured from bottle using the formulae.brew.sh API on 2023-06-29 at 09:37:25
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/nginx.rb
License: BSD-2-Clause
==> Dependencies
Required: openssl@3, pcre2
==> Options
--HEAD
    Install HEAD version
==> Caveats
Docroot is: /opt/homebrew/var/www

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

nginx will load all files in /opt/homebrew/etc/nginx/servers/.

To 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:
  /opt/homebrew/opt/nginx/bin/nginx -g daemon off;
==> Analytics
install: 15,746 (30 days), 56,605 (90 days), 75,889 (365 days)
install-on-request: 15,727 (30 days), 56,531 (90 days), 75,784 (365 days)
build-error: 4 (30 days)
brew info php
==> php: stable 8.2.8 (bottled), HEAD
General-purpose scripting language
https://www.php.net/
/opt/homebrew/Cellar/php/8.1.3_1 (510 files, 81.6MB)
  Built from source
/opt/homebrew/Cellar/php/8.1.5 (510 files, 81.6MB)
  Built from source
/opt/homebrew/Cellar/php/8.1.7 (510 files, 81.7MB)
  Built from source
/opt/homebrew/Cellar/php/8.1.10 (510 files, 81.7MB)
  Built from source
/opt/homebrew/Cellar/php/8.1.10_1 (510 files, 81.7MB)
  Built from source
/opt/homebrew/Cellar/php/8.1.11 (510 files, 81.6MB)
  Built from source
/opt/homebrew/Cellar/php/8.1.12 (510 files, 81.6MB)
  Built from source
/opt/homebrew/Cellar/php/8.2.3 (517 files, 83.3MB)
  Built from source
/opt/homebrew/Cellar/php/8.2.4 (516 files, 83.3MB)
  Built from source
/opt/homebrew/Cellar/php/8.2.5 (517 files, 83.4MB)
  Built from source
/opt/homebrew/Cellar/php/8.2.6 (517 files, 83.4MB)
  Built from source
/opt/homebrew/Cellar/php/8.2.7 (517 files, 83.4MB)
  Built from source
/opt/homebrew/Cellar/php/8.2.7_1 (517 files, 83.4MB)
  Built from source
/opt/homebrew/Cellar/php/8.2.7_2 (517 files, 83.4MB)
  Built from source
/opt/homebrew/Cellar/php/8.2.8 (520 files, 83.5MB) *
  Poured from bottle using the formulae.brew.sh API on 2023-07-11 at 13:09:28
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, gmp, icu4c, krb5, libpq, libsodium, libzip, oniguruma, openldap, openssl@3, 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 /opt/homebrew/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:
    /opt/homebrew/etc/php/8.2/

To restart php after an upgrade:
  brew services restart php
Or, if you don't want/need a background service you can just run:
  /opt/homebrew/opt/php/sbin/php-fpm --nodaemonize
==> Analytics
install: 44,803 (30 days), 161,631 (90 days), 213,623 (365 days)
install-on-request: 41,303 (30 days), 149,638 (90 days), 197,731 (365 days)
build-error: 60 (30 days)
brew info openssl
==> openssl@3: stable 3.1.1 (bottled)
Cryptography and SSL/TLS Toolkit
https://openssl.org/
/opt/homebrew/Cellar/openssl@3/3.1.1_1 (6,495 files, 28.4MB) *
  Poured from bottle using the formulae.brew.sh API on 2023-06-29 at 09:36:57
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/openssl@3.rb
License: Apache-2.0
==> Dependencies
Required: ca-certificates
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /opt/homebrew/etc/openssl@3/certs

and run
  /opt/homebrew/opt/openssl@3/bin/c_rehash
==> Analytics
install: 322,150 (30 days), 702,232 (90 days), 848,810 (365 days)
install-on-request: 36,559 (30 days), 185,673 (90 days), 226,328 (365 days)
build-error: 1,076 (30 days)
openssl version -a
OpenSSL 1.1.1t  7 Feb 2023
built on: Mon Feb 13 23:21:47 2023 UTC
platform: darwin64-arm64-cc
options:  bn(64,64) rc4(int) des(int) idea(int) blowfish(ptr) 
compiler: arm64-apple-darwin20.0.0-clang -D_FORTIFY_SOURCE=2 -isystem /opt/homebrew/Caskroom/miniconda/base/include -mmacosx-version-min=11.1 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -isystem /opt/homebrew/Caskroom/miniconda/base/include -fdebug-prefix-map=/var/folders/nz/j6p8yfhx1mv_0grj5xl4650h0000gp/T/abs_ccl4lztlvr/croot/openssl_1676330477401/work=/usr/local/src/conda/openssl-1.1.1t -fdebug-prefix-map=/opt/homebrew/Caskroom/miniconda/base=/usr/local/src/conda-prefix -fPIC -arch arm64 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -isystem /opt/homebrew/Caskroom/miniconda/base/include -fdebug-prefix-map=/var/folders/nz/j6p8yfhx1mv_0grj5xl4650h0000gp/T/abs_ccl4lztlvr/croot/openssl_1676330477401/work=/usr/local/src/conda/openssl-1.1.1t -fdebug-prefix-map=/opt/homebrew/Caskroom/miniconda/base=/usr/local/src/conda-prefix -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_CPUID_OBJ -DOPENSSL_BN_ASM_MONT -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DKECCAK1600_ASM -DVPAES_ASM -DECP_NISTZ256_ASM -DPOLY1305_ASM -D_REENTRANT -DNDEBUG -D_FORTIFY_SOURCE=2 -isystem /opt/homebrew/Caskroom/miniconda/base/include -mmacosx-version-min=11.1
OPENSSLDIR: "/opt/homebrew/Caskroom/miniconda/base/ssl"
ENGINESDIR: "/opt/homebrew/Caskroom/miniconda/base/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 /opt/homebrew/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /opt/homebrew/etc/nginx/nginx.conf test is successful
which -a php-fpm
/opt/homebrew/sbin/php-fpm
/opt/homebrew/opt/php/sbin/php-fpm -v
PHP 8.2.8 (fpm-fcgi) (built: Jul  6 2023 10:57:47)
Copyright (c) The PHP Group
Zend Engine v4.2.8, Copyright (c) Zend Technologies
    with Xdebug v3.2.1, Copyright (c) 2002-2023, by Derick Rethans
    with Zend OPcache v8.2.8, Copyright (c), by Zend Technologies
sudo /opt/homebrew/opt/php/sbin/php-fpm -y /opt/homebrew/etc/php/8.2/php-fpm.conf --test
[23-Jul-2023 23:39:39] NOTICE: configuration file /opt/homebrew/etc/php/8.2/php-fpm.conf test is successful
ls -al ~/Library/LaunchAgents | grep homebrew
-rw-r--r--   1 danielthoma  staff   586 Mar 24  2022 homebrew.mxcl.php.plist
ls -al /Library/LaunchAgents | grep homebrew

ls -al /Library/LaunchDaemons | grep homebrew
-rw-r--r--   1 root  admin   797 Jul 23 23:04 homebrew.mxcl.dnsmasq.plist
-rw-r--r--   1 root  admin   685 Jul 23 23:04 homebrew.mxcl.nginx.plist
-rw-r--r--   1 root  admin   781 Jul 23 23:04 homebrew.mxcl.php.plist
ls -al /Library/LaunchDaemons | grep "com.laravel.valet."

ls -aln /etc/resolv.conf
lrwxr-xr-x  1 0  0  22 Jun 15 12:08 /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 fritz.box
nameserver 1.1.1.1
nameserver 8.8.8.8
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/opt/homebrew/etc/nginx/valet/valet.conf\n---\n"; cat /opt/homebrew/etc/nginx/valet/valet.conf | grep -n "# valet loopback"; echo "\n------\n"'
------
/opt/homebrew/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/*
---

cat: /Users/danielthoma/.config/valet/nginx/*: No such file or directory

------
monoland commented 1 year ago

this my nginx error log

2023/07/24 07:06:16 [error] 1957#0: *2 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: backend.citragroup.test, request: "GET / HTTP/2.0", upstream: "fastcgi://unix:/Users/monoland/.config/valet/valet.sock:", host: "backend.citragroup.test"

monoland commented 1 year ago

@djfhe my-problem appear when I install redis on my-machine

StringKe commented 1 year ago

I had the same problem and found some differences in my debugging

Illuminate\Foundation\Http\Kernal.sendRequestThroughRouter Pipeline.then

in artisan server

CleanShot 2023-07-26 at 15 54 58@2x

in valet CleanShot 2023-07-26 at 15 56 42@2x

tpetry commented 1 year ago

Having the same problem. The error only happens when a PostgreSQL query is executed. I did not use the session driver.

driesvints commented 1 year ago

We'll need a clear way to reproduce this one otherwise it's gonna be a shot in the dark at figuring out how to solve it.

faltjo commented 1 year ago

I also struggled with this for the last days and was not able to resolve it. All laravel projects which were using pgsql resulted in 502 and the error message mentioned here. It may have something to do with https://github.com/Homebrew/homebrew-core/issues/137431. Even though the fix mentioned there did not work for me and the SIGABRT did not show up in php-fpm.log on my side.

My current 'workaround' is to use Herd, since pgsql extension was included there recently. Apparently their php build does not include the gettext method.

tpetry commented 1 year ago

Sure, it is straightforward to reproduce: https://github.com/tpetry/laravel-valet-bug-1433

The only change to a stock Laravel installation is that the / route executes a PostgreSQL query.

php artisan serve

works perfectly!

valet link

fails with nginx 502 error, no information in php-fpm error log.

2023/07/26 16:21:17 [error] 28667#0: *16 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/Users/tpetry/.config/valet/valet.sock:", host: "valet-1433.test"
mattstauffer commented 1 year ago

I'm working on getting Postgres working on my local machine after a while of not using it; will test as soon as I have it running.

Update: Running Postgres.app on Valet 4.1.0 renders the app with no problems.

I ran composer global update laravel/valet and now I'm on Valet 4.1.3. No problems.

So this isn't a core Valet issue, as I think we're all assuming.

I'm going to assume it's some dependency that y'all have a newer version of than me. Let me work on updating them all bit by bit.

Possible things that have been mentioned:

I don't have any m2 machines so if it's that I'll need help. I'm going to update all my dependencies and see if I can possibly trigger this; if not, I'll install Herd and see if it causes the problem; if not, M2 is my next angle.

tpetry commented 1 year ago

I am on an M1 machine and haven't installed Herd yet.

Laravel Valet: 4.1.3
PHP: 8.2.8
nginx: 1.25.1
alfonsobries commented 1 year ago

Same issue, even tried in a fresh m2 machine (nothing installed other than valet and neccessary stuff to run a Laravel project), on a fresh laravel project it fails once I set the database driver to pgsql, dame nginx logs as the ones pointed in other comments

mattstauffer commented 1 year ago

OK, @tpetry has disproved the Herd hypothesis and the M2 hypothesis. Let's see what else we can find out...

drbyte commented 1 year ago

Is it specific to a certain php or nginx version?

tpetry commented 1 year ago

I guess that the problem started after brew updated my dependencies. But I am not sure. I hadn't been developing for some days and the day I started to develop again I've installed a new brew package - which updated everything.

Again, just a guess.

mattstauffer commented 1 year ago

I'm running on a pre-m1 iMac; I'll run these tests on my m1 laptop again later.

I ran brew upgrade several times to make sure I was entirely up to date; still no problem.

I'm currently on PHP 8.2.8, Valet 4.1.3, and nginx 1.25.1, same as @tpetry, but can't repro the problem.

@tpetry What tool are you using to install your Postgres? I'm using postgres.app, but maybe if I use the same one you're using that'll help us be in better parity?

To be clear, what I'm testing is:

tpetry commented 1 year ago

I am using a PG 14 version of StackBricks. But the Postgres version shouldn't be the problem. Because for a PG issue the laravel.log should have some information - but that is empty.

mattstauffer commented 1 year ago

Update: I tried all these same steps on my m1 laptop, same inability to reproduce.

... until I restarted my computer! Now I can reproduce! Let me try restarting my non-m1.... yep. So.. it's not m1 related either.

Update homebrew, restart computer, suddenly seeing the problem. Now let's dive into why...

drbyte commented 1 year ago

While it's unknown here yet which "upstream" host/phase is actually the "delay" or causing the "disconnect", perhaps (even just temporarily for troubleshooting) adjusting the nginx config may help expose more errors in other logs:

Add new file: /usr/local/etc/nginx/servers/temp_fastcgi_settings.conf (edit: adjust the path if you're on M1 or M2, it's in the /opt/homebrew/etc/ subtree) containing:

# The following settings can be adjusted for your environment

#### Connections and Responses to Upstream may be impacted by upstream hosts

# If connection can't be made within this timeframe, connection is closed; default 60s, max 75s.
fastcgi_connect_timeout 75s;

# If no responses are read for this length of time, connection is closed. Default 60s
fastcgi_read_timeout 360s;

# Determines whether the connection with a FastCGI server should be closed when a client closes the connection without waiting for a response. Default is off.
fastcgi_ignore_client_abort on;

# https://gist.github.com/magnetikonline/11312172#determine-fastcgi-response-sizes
# http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html

... and valet restart

drbyte commented 1 year ago

In the reports above I've observed that the number "before" the "upstream prematurely closed" varies. So far it's *2, *77, *16. I'm not sure if that's significant:

[error] 1957#0: *2 upstream prematurely closed connection
[error] 50639#0: *77 upstream prematurely closed connection
[error] 28667#0: *16 upstream prematurely closed connection

EDIT: after digging into nginx source, I'm pretty sure 1957#0: *2 refers to pid#tid: *connectionid from nginx internals ... so the *xx value is not particularly helpful here because we probably can't identify it easily.

However, if the pid matches a process running on the Mac which is operating as user instead of as root then perhaps that's a clue to the LaunchAgents topic I posted about in the post below. But of course it's harder to research in hindsight especially after reboots and service-restarts etc.

drbyte commented 1 year ago

@monoland FYI, in your valet diagnose output it shows you've got PHPFPM running both as root and as your non-root user. That'll potentially create conflicts (may or may not be related to this Issue directly though).

Check the following again:

ls -al ~/Library/LaunchAgents | grep homebrew
ls -al ~/Library/LaunchDaemons | grep homebrew

You don't want a PHP process running in LaunchAgents. Only in LaunchDaemons.

To fix that, simply run (without sudo): brew services stop php (to stop the homebrew.mxcl.php.plist service shown in that LaunchAgents directory). (Doing it with sudo would do the LaunchDaemons, but Valet handles that itself for Valet-specific services.) Calling brew services stop [name] will stop the service and remove the LaunchAgent file so that it also doesn't restart on login.

drbyte commented 1 year ago

I notice the same LaunchAgents issue for @djfhe in his valet diagnose output as well: duplicate PHP processes running both as root and non-root, simultaneously. To fix, do the same as I posted above.

Due to the pattern showing for both, I wonder: Does that solve the reported issue?

djfhe commented 1 year ago

Stopped LaunchAgents (ls -al ~/Library/LaunchAgents | grep homebrew is empty now) and added your config.

While it's unknown here yet which "upstream" host/phase is actually the "delay" or causing the "disconnect", perhaps (even just temporarily for troubleshooting) adjusting the nginx config may help expose more errors in other logs:

Add new file: /usr/local/etc/nginx/servers/temp_fastcgi_settings.conf (edit: adjust the path if you're on M1 or M2, it's in the /opt/homebrew/etc/ subtree) containing:

# The following settings can be adjusted for your environment

#### Connections and Responses to Upstream may be impacted by upstream hosts

# If connection can't be made within this timeframe, connection is closed; default 60s, max 75s.
fastcgi_connect_timeout 75s;

# If no responses are read for this length of time, connection is closed. Default 60s
fastcgi_read_timeout 360s;

# Determines whether the connection with a FastCGI server should be closed when a client closes the connection without waiting for a response. Default is off.
fastcgi_ignore_client_abort on;

# https://gist.github.com/magnetikonline/11312172#determine-fastcgi-response-sizes
# http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html

... and valet restart

Sadly the problem still persists and there are no new entries logged.

valet log php-fpm -f

``` [27-Jul-2023 09:21:00] NOTICE: [pool valet] child 48027 started [27-Jul-2023 09:21:00] WARNING: [pool valet] child 48025 exited on signal 6 (SIGABRT) after 0.691368 seconds from start [27-Jul-2023 09:21:00] NOTICE: [pool valet] child 48029 started [27-Jul-2023 09:21:00] WARNING: [pool valet] child 48027 exited on signal 6 (SIGABRT) after 0.593855 seconds from start [27-Jul-2023 09:21:00] NOTICE: [pool valet] child 48031 started [27-Jul-2023 09:21:01] WARNING: [pool valet] child 48029 exited on signal 9 (SIGKILL) after 0.642601 seconds from start [27-Jul-2023 09:21:01] NOTICE: [pool valet] child 48033 started [27-Jul-2023 09:21:01] WARNING: [pool valet] child 48031 exited on signal 9 (SIGKILL) after 0.732587 seconds from start [27-Jul-2023 09:21:01] NOTICE: [pool valet] child 48035 started [27-Jul-2023 09:21:02] WARNING: [pool valet] child 48033 exited on signal 6 (SIGABRT) after 0.797574 seconds from start [27-Jul-2023 09:21:02] NOTICE: [pool valet] child 48037 started ```

valet log nginx -f

``` 2023/07/27 09:20:59 [error] 47904#0: *4 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/Users/danielthoma/.config/valet/valet.sock:", host: "foo.test" 2023/07/27 09:20:59 [error] 47904#0: *4 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/Users/danielthoma/.config/valet/valet.sock:", host: "foo.test" 2023/07/27 09:21:00 [error] 47904#0: *4 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/Users/danielthoma/.config/valet/valet.sock:", host: "foo.test" 2023/07/27 09:21:00 [error] 47904#0: *4 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/Users/danielthoma/.config/valet/valet.sock:", host: "foo.test" 2023/07/27 09:21:00 [error] 47904#0: *4 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/Users/danielthoma/.config/valet/valet.sock:", host: "foo.test" 2023/07/27 09:21:01 [error] 47904#0: *4 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/Users/danielthoma/.config/valet/valet.sock:", host: "foo.test" 2023/07/27 09:21:01 [error] 47904#0: *4 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/Users/danielthoma/.config/valet/valet.sock:", host: "foo.test" 2023/07/27 09:21:02 [error] 47904#0: *4 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/Users/danielthoma/.config/valet/valet.sock:", host: "foo.test" ```

valet status

``` Checking status... Valet status: Healthy +--------------------------------------+----------+ | Check | Success? | +--------------------------------------+----------+ | Is Valet fully installed? | Yes | | Is Valet config valid? | Yes | | Is Homebrew installed? | Yes | | Is DnsMasq installed? | Yes | | Is Dnsmasq running? | Yes | | Is Dnsmasq running as root? | Yes | | Is Nginx installed? | Yes | | Is Nginx running? | Yes | | Is Nginx running as root? | Yes | | Is PHP installed? | Yes | | Is linked PHP (php) running? | Yes | | Is linked PHP (php) running as root? | Yes | | Is valet.sock present? | Yes | +--------------------------------------+----------+ ```

Versions:

Laravel Valet: 4.1.3
PHP: 8.2.8
nginx: 1.25.1
askdkc commented 1 year ago

I tried to fresh install macOS on my M1 MacBook Air and hopefully this problem gets solved, but no help.

Here is what I did:

Reinstall macOS

boot mac in rescue mode, and clean install macOS.

Setup Laravel Environment

Install homebrew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Install php and Laravel Valet

brew update
brew install php
brew install composer
brew install postgresql

composer global require laravel/installer
composer global require laravel/valet

mkdir -p ~/Sites
cd ~/Sites
valet install
valet park

laravel new laravel

Create PostgreSQL DB

createdb laravel

Change .env to use PostgreSQL

DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=laravel
DB_USERNAME=username
DB_PASSWORD=

For testing use Laravel Breeze

composer require laravel/breeze --dev
php artisan breeze:install blade

php artisan migrate

Access Top Page

Open your browser and access to : http://laravel.test <- This works fine.

Now, try to register a user from Breeze register menu, then it throws a 502 error.

If you switch your db from PostgreSQL to sqlite or MySQL, it works just fine.

Other Environment

I have another Intel iMac, so I also tested with it. Before running the commands below, Valet was working without any problem.

brew update && brew upgrade then composer g update && valet install && valet restart

Now, using PostgreSQL throws 502.

I guess there is something wrong with homebrew packages, not Valet itself, but not sure.

We can use previous or older version of Valet by editing ~/.composer/composer.json like this:

"laravel/valet": "^4.1" -> "laravel/valet": "4.0.0"

Then run composer g update this will change Valet version (back to 4.0.0 in this case), but when I access to Laravel Project, it still throws 502 error. If this is related to Valet recent changes, this shouldn't be happening.

So, it must be related to brew package updates, either php or nginx?

djfhe commented 1 year ago

Wenn enabling

catch_workers_output = yes

in /out/homebrew/etc/php/8.2/php-fpm.d/valet-fpm.conf

i get additional error output:

[27-Jul-2023 09:49:38] NOTICE: ready to handle connections
[27-Jul-2023 09:49:48] WARNING: [pool valet] child 54119 said into stderr: "objc[54119]: +[__NSPlaceholderDate initialize] may have been in progress in another thread when fork() was called."
[27-Jul-2023 09:49:48] WARNING: [pool valet] child 54119 said into stderr: "objc[54119]: +[__NSPlaceholderDate initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug."
[27-Jul-2023 09:49:48] WARNING: [pool valet] child 54119 exited on signal 6 (SIGABRT) after 9.676681 seconds from start
[27-Jul-2023 09:49:48] NOTICE: [pool valet] child 54693 started
[27-Jul-2023 09:50:29] WARNING: [pool valet] child 54120 said into stderr: "objc[54120]: +[__NSPlaceholderDate initialize] may have been in progress in another thread when fork() was called."
[27-Jul-2023 09:50:29] WARNING: [pool valet] child 54120 said into stderr: "objc[54120]: +[__NSPlaceholderDate initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug."
[27-Jul-2023 09:50:29] WARNING: [pool valet] child 54120 exited on signal 6 (SIGABRT) after 50.322856 seconds from start
[27-Jul-2023 09:50:29] NOTICE: [pool valet] child 54703 started

no clue what that means haha

faytranevozter commented 1 year ago

im facing the same problem with postgres in db connection. my issue is same as this stackoverflow question

it works on php artisan serve but not in valet

askdkc commented 1 year ago

OK folks! Using this info reported by @djfhe I found the work around for this problem.

(I assume, yo all run brew upgrade and php version is 8.2.8)

vi /opt/homebrew/Cellar/php/8.2.8/homebrew.mxcl.php.plist

change the content of homebrew.mxcl.php.plist file like this: https://gist.github.com/askdkc/28480a0af1301993d92187920abec3bc

Then run

valet restart

Now everything working perfectly fine with PostgreSQL!!

SanderMuller commented 1 year ago

I also have this issue since upgrading brew and valet (PHP 8.2.8, and noticeably OpenSSL 1.1 to 3), but with mongodb instead of postgres. The application works well, until I access a page that uses mongo, then I get the same 502 nginx/fastcgi abort segvault.

php artisan serve also works for me, but not valet.

djfhe commented 1 year ago

Interesting, i tried the same, by adding

fastcgi_param OBJC_DISABLE_INITIALIZE_FORK_SAFETY YES;

to the ngninx config, but that didn't work for me. Your solution does @askdkc, thanks!

drbyte commented 1 year ago

Does this problem only happen on Ventura?

Screen Shot 2023-07-27 at 11 56 01 AM
djfhe commented 1 year ago

i'm on venture:

image
mattstauffer commented 1 year ago

Does this problem only happen on Ventura?

Nope, I'm on Monterey.

mattstauffer commented 1 year ago

I tried @askdkc's suggestion and it didn't solve the issue, but it seems like that may at least be partially a solution, since there are at least two people who said it fixed it for them.

SanderMuller commented 1 year ago

I tried @askdkc's suggestion and it didn't solve the issue, but it seems like that may at least be partially a solution, since there are at least two people who said it fixed it for them.

It also didn't fix it for me (neither did the OBJC_DISABLE_INITIALIZE_FORK_SAFETY config change)

drbyte commented 1 year ago

If the homebrew plist file edit didn't solve it for you, check whether the change is reflected in the /Library/LaunchDaemons version of the file. If not, then manually sudo brew services restart php and check the file again. If that doesn't work, first sudo brew services stop php, and then valet start. That should copy the file from the homebrew master location into the LaunchDaemons dir and include the change when restarting the service.

Hopefully that helps...

subdesign commented 1 year ago

Same here. 502 error, "upstream prematurely closed connection while reading response header from upstream" in the nginx error log. I don't use Postgres , and session driver is not database, and has Monterey. I "mirrored" my projects to a new M1 Pro from my old Macbook 2015, the only difference is the old machine has Valet 3.3.2, the new 4.1.3 . But, some of my projects are working, the others get 502, but all files, composer and node versions are the same. This is why I guess the new Valet version has strange behaviour. Next try I'll force 3.3.2 to install and see what happens. What do you think?

drbyte commented 1 year ago

I guess the new Valet version has strange behaviour

I'm pretty sure this is a homebrew package issue, not specific to Valet's internals. The challenge is figuring out "what" specifically.

So, reverting back to an older Valet version won't solve the problem, since you're probably using recent Homebrew package versions, and downgrading those is actually kinda complicated.

subdesign commented 1 year ago

So, reverting back to an older Valet version won't solve the problem, since you're probably using recent Homebrew package versions, and downgrading those is actually kinda complicated.

Totally right, nothing changed in a good way after reverting back to 3.3.2.

askdkc commented 1 year ago

@mattstauffer @SanderMuller

related with https://github.com/laravel/valet/issues/1433#issuecomment-1653957428

Please make sure you don't have homebrew.mxcl.php.plist in ~/Library/LaunchAgents <- This is inside of your home directory

Only place you want homebrew.mxcl.php.plist to exist is /Library/LaunchDaemons <- This is top level /Library

If you find homebrew.mxcl.php.plist in ~/Library/LaunchAgents, remove it and then reboot your Mac. And try this step again.

https://github.com/laravel/valet/issues/1433#issuecomment-1653419658

SanderMuller commented 1 year ago

@mattstauffer @SanderMuller

related with #1433 (comment)

Please make sure you don't have homebrew.mxcl.php.plist in ~/Library/LaunchAgents <- This is inside of your home directory

Only place you want homebrew.mxcl.php.plist to exist is /Library/LaunchDaemons <- This is top level /Library

If you find homebrew.mxcl.php.plist in ~/Library/LaunchAgents, remove it and then reboot your Mac. And try this step again.

#1433 (comment)

I only have homebrew.mxcl.php.plist in /Library/LaunchDaemons, not in /Library/LaunchAgents or ~/Library/LaunchAgents

askdkc commented 1 year ago

@SanderMuller

Interesting. Did you run brew upgrade? Which php version are you using? 8.2.8?

Try directly change /Library/LaunchDaemons/homebrew.mxcl.php.plist then without doing anything, just reboot your Mac. See how it goes?

SanderMuller commented 1 year ago

@SanderMuller

Interesting. Did you run brew upgrade? Which php version are you using? 8.2.8?

Yes, it all worked fine until I upgraded everything to try and debug an unrelated issue. Before upgrade I ran PHP 8.2.3, OpenSSL 1.1, outdated Valet After upgrade I run PHP 8.2.8, OpenSSL 3, latest Valet

Did brew upgrade, reinstalled valet (uninstall force, valet install)

FYI my issue is not with postgress, we don't use that. But I get exactly the same issue with mongodb. All my applications work fine, except for one which uses mongodb, and that application works fine except for pages where mongodb is actually queried.

Try directly change /Library/LaunchDaemons/homebrew.mxcl.php.plist then without doing anything, just reboot your Mac. See how it goes?

I have done this, but it has no effect.

askdkc commented 1 year ago

@SanderMuller

Oh, I thought you were having trouble with PostgreSQL. My bad.

If it's related with homebrew, you might try adding

<key>EnvironmentVariables</key>
<dict>
    <key>OBJC_DISABLE_INITIALIZE_FORK_SAFETY</key>
    <string>YES</string>
</dict>

to your mongodb start up script.

tychoengberink commented 1 year ago

This is what i did. Thanks to @askdkc for the first part!

vi /opt/homebrew/Cellar/php/8.2.8/homebrew.mxcl.php.plist Change the content of homebrew.mxcl.php.plist file like this: https://gist.github.com/askdkc/28480a0af1301993d92187920abec3bc

Remove old socket rm -rf /Users/<USERNAME>/.config/valet/valet82.soc Reinstall socket valet install

This fixed 8.2.8 for me. It also fixes older versions (8.1.21) on which I had 502 errors.

Also update the plist file, remove the soc file for each version. When done with each version. Run valet install

I assume php-fpm crashes when using extensions. When I disable my database credentials I get an connection exception but when I enable them, I get 502 errors.

php-fpm logs: [27-Jul-2023 17:23:15] WARNING: [pool valet] child 66302 exited on signal 9 (SIGKILL) after 1.389545 seconds from start [27-Jul-2023 17:23:15] NOTICE: [pool valet] child 66325 started

nginx logs: 2023/07/27 17:25:43 [error] 66354#0: *10 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1

I have no plist files in /Library/LaunchAgents and the ones /Library/LaunchDaemons/ matches the ones I edited

SanderMuller commented 1 year ago

@SanderMuller

Oh, I thought you were having trouble with PostgreSQL. My bad.

If it's related with homebrew, you might try adding

<key>EnvironmentVariables</key>
<dict>
    <key>OBJC_DISABLE_INITIALIZE_FORK_SAFETY</key>
    <string>YES</string>
</dict>

to your mongodb start up script.

Thank you for being so helpful!

MongoDB php extensions is installed via PECL, not homebrew (not available via homebrew). I'm using an external mongo server (Atlas) Would you have any idea where I would have to add the OBJC_DISABLE_INITIALIZE_FORK_SAFETY env variable in this case?

askdkc commented 1 year ago

@SanderMuller

Usually it should be this line in your mongodb plist :

・・・
<key>RunAtLoad</key>
<true/>
   ↑ UNDER THIS LINE
<key>EnvironmentVariables</key>
・・・