Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Valet 502 Error working with PostgreSQL and MongoDB #1433

Closed
monoland opened this issue Jul 22, 2023 · 101 comments · Fixed by #1452
Closed

Valet 502 Error working with PostgreSQL and MongoDB #1433

monoland opened this issue Jul 22, 2023 · 101 comments · Fixed by #1452
Labels

Comments

@monoland
Copy link

monoland commented Jul 22, 2023

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
<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.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
Copy link
Member

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
Copy link
Author

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
Copy link
Author

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

@drbyte
Copy link
Contributor

drbyte commented Jul 22, 2023

@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
Copy link
Contributor

drbyte commented Jul 23, 2023

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
Copy link

djfhe commented Jul 23, 2023

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
<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:
/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
Copy link
Author

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
Copy link
Author

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

@StringKe
Copy link

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
Copy link

tpetry commented Jul 26, 2023

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

@driesvints driesvints reopened this Jul 26, 2023
@driesvints driesvints added the bug label Jul 26, 2023
@driesvints
Copy link
Member

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
Copy link

faltjo commented Jul 26, 2023

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 Homebrew/homebrew-core#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
Copy link

tpetry commented Jul 26, 2023

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
Copy link
Member

mattstauffer commented Jul 26, 2023

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
Copy link

tpetry commented Jul 26, 2023

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
Copy link

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
Copy link
Member

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

@drbyte
Copy link
Contributor

drbyte commented Jul 26, 2023 via email

@tpetry
Copy link

tpetry commented Jul 26, 2023

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
Copy link
Member

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
Copy link

tpetry commented Jul 26, 2023

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
Copy link
Member

mattstauffer commented Jul 26, 2023

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
Copy link
Contributor

drbyte commented Jul 26, 2023

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
Copy link
Contributor

drbyte commented Jul 26, 2023

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
Copy link
Contributor

drbyte commented Jul 26, 2023

@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
Copy link
Contributor

drbyte commented Jul 26, 2023

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
Copy link

djfhe commented Jul 27, 2023

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

@dbarrerap
Copy link

any update it does not work after restarting my pc work okey with mysql but when connecting postgressql it show 502 gateway timeout

Perhaps unrelated, but this suggestion in issue #315 helped me. And now it all works, PHP 8.0 and 8.2. It gets some hiccups from now and then, but it works

@suman98
Copy link

suman98 commented Sep 2, 2023

@dbarrerap I tried this
#1433 (comment)
it fixed my issue now postgres is working on mine laravel valet

@sulimenko
Copy link

I encountered the same error, but it's not clear to me why script executes well in the local console.

when querying via valet or pure nginx it terminates php with an error: WARNING: [pool valet] child 42090 exited on signal 6 (SIGABRT) after 62.181861 seconds from start

<?php

$host = '127.0.0.1';
$port = '5432';
$dbname = 'base';
$user = 'user';
$password = 'pass';

try {
    $dsn = "pgsql:host=" . $host . ";port=" . $port . ";dbname=" . $dbname . ";user=" . $user . ";password=" . $password . ";";
    $pdo = new PDO($dsn);

    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    $sql = "SELECT * FROM table LIMIT 10";
    $stmt = $pdo->query($sql);

    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
        echo "id: " . $row['id'] . ", Name: " . $row['name'] . "<br>";
    }

    $pdo = null;
} catch (PDOException $e) {
    echo "Error PostgreSQL: " . $e->getMessage();
}
?>

If this is a PHP and macOS problem, why does it work fine from the console?

@drbyte
Copy link
Contributor

drbyte commented Sep 3, 2023

why does it work fine from the console?

PHP has 2 binaries/executables:
The console uses the command-line interface, which uses the php binary/executable.
But nginx, uses php-fpm for all PHP operations.

@sulimenko
Copy link

sulimenko commented Sep 4, 2023

I understand your point, but what prevents PHP developers from taking the PDO internals from cli and replacing them in PHP-FPM.

I also tried to run without PHP-FPM using FastCGI - it doesn't work.

server {
    listen 127.0.0.1:80;
    server_name php.test;

    root /Users/alexey/site/php;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    charset utf-8;
    client_max_body_size 128M;

    access_log off;

    location ~.php$ {
      include fastcgi_params;
      fastcgi_pass "unix:/Users/alexey/.config/valet/valet.sock";
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

I changed plist: OBJC_DISABLE_INITIALIZE_FORK_SAFETY = YES
PHP: 7.4.33
Laravel Valet: 4.1.4
nginx: 1.25.2
M1 macOS 12.5 (21G72)
Kernel: Darwin 21.6.0

@ZacharyDuBois
Copy link

ZacharyDuBois commented Sep 5, 2023

Was having issues with route model binding (both Implicit and explicit) where I'd either get the 502 error or Laravel would initialize a blank instance of a model instead of looking up the existing one. This only occurred if Valet was serving the site. If I used the built in php artisan serve everything worked as expected.

Updating /Library/LaunchDaemons/homebrew.mxcl.php.plist and adding the OBJC_DISABLE_INITIALIZE_FORK_SAFETY environment variable fixed this. This is also a major issue with Rails/Sinatra + Puma and various Python frameworks too.

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

Thank you so much for reminding me that this issue causes a lot of havoc @askdkc !

@danielcommesse
Copy link

Found a solution here: Homebrew/homebrew-core#137431 (comment)

@drbyte
Copy link
Contributor

drbyte commented Sep 7, 2023

@danielcommesse wrote: Found a solution here: Homebrew/homebrew-core#137431 (comment)

Note that for Valet, the .conf filename would be different. Valet uses the php-fpm pool defined in /usr/local/etc/php/8.2/php-fpm.d/valet-fpm.conf (and during install, deletes/renames the default www.conf file to prevent conflicts)

@suman98
Copy link

suman98 commented Sep 10, 2023

[10-Sep-2023 17:27:02] WARNING: [pool valet] child 8482 exited on signal 9 (SIGKILL) after 16.588784 seconds from start
[10-Sep-2023 17:27:02] NOTICE: [pool valet] child 8504 started

I am getting this error for laravel valet with postgres
Any solution

@efureev
Copy link

efureev commented Sep 28, 2023

I'm getting this errors with PG without Valet.

Working through localhost (127.0.0.1:port) - normal (`./artisan serve):
Снимок экрана 2023-09-29 в 02 15 49

But working through nginx & domain (e.g. example.com) - failed on Creating PDO connection:

$dbh = new \PDO('pgsql:dbname=dbname;host=127.0.0.1', $user, $password);
Снимок экрана 2023-09-29 в 02 16 58

Code the same!
Снимок экрана 2023-09-29 в 02 18 28

PHP: 8.2.11
OS: MacOs 14
PG: 14

@ThunderBirdsX3
Copy link

@efureev
Guys, I try a lot of possible ways from comments. Finally it work.

Here solution, But I'm not sure which one make it work. Or all of them.

Add this code to /usr/local/etc/php/8.2/php-fpm.d/valet-fpm.conf

env['PGGSSENCMODE'] = disable

Add this code to /usr/local/Cellar/php/8.2.11/homebrew.mxcl.php.plist

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

Then valet restart

@efureev
Copy link

efureev commented Sep 29, 2023

@ThunderBirdsX3 thx! but I'm helped following:
At file: /usr/local/etc/php/8.2/php-fpm.d/www.conf add lines:

env['PGGSSENCMODE'] = disable
env['LC_ALL'] = C

And restart php. It works fine.

@lewislarsen
Copy link

lewislarsen commented Oct 1, 2023

My path is slightly different with it being /opt/homebrew/Cellar/php/8.2.11 but the changes to homebrew.mxcl.php.plist fixed my 502 Bad Gateway problems.

(#1433 (comment) Lifesaver!)

Thanks for this again! I had fixed it on my machine a few months ago but had to reinstall Valet and it all fell apart.

@driesvints
Copy link
Member

Is anyone willing to PR a fix?

drbyte added a commit to drbyte/valet that referenced this issue Oct 9, 2023
Many have reported that these changes "do" help the problem.
And yet many others have reported that they make no difference.

Closes laravel#1433

This PR is merely a bandage for a broader problem that exists in the PHP build for MacOS. See the issue referenced above for discussion and links to Homebrew and PHP repository discussions. The problem is not in Homebrew, but in the PHP build published by the PHP core.
Chime in on the PHP discussion if you want to stir up more active participation for a proper fix, telling them that you're a Mac user encountering the fork segfaults (they won't care whether you're using Valet, but they will recognize if you mention Homebrew).
@caturseptian
Copy link

Homebrew/homebrew-core#137431 (comment)

thanks!

@steinmb
Copy link

steinmb commented Oct 15, 2023

Ref - Homebrew/homebrew-core#137431 (comment)

This worked for me: Add the following lines to your /usr/local/etc/php/<PHPVERSION>/php-fpm.d/www.conf Example /usr/local/etc/php/8.4/php-fpm.d/www.conf

;Signal 11 workaround
env['PGGSSENCMODE'] = disable
env['LC_ALL'] = C

And restart your effected PHP service, or test in running it directly: /usr/local/opt/php@8.4/sbin/php-fpm --nodaemonize

Needed this on all mine PHP versions, to make it work:

  • PHP 7.4
  • PHP 8.0
  • PHP 8.1
  • PHP 8.2
  • PHP 8.3
  • PHP 8.4

@Dillonsmart
Copy link

Success here as well, using this: #1433 (comment)

So, a quick summary:

Our issue seems to be with how macOS has, lately, put tighter restrictions on multithreading, and that seems to be relevant only when Homebrew PHP is connecting to Postgres and Mongo. I don't know why yet but it's related to something updated by Homebrew, not Valet.

The (temporary) fix

The temporary solution is to update your Homebrew PHP configuration.

Find the config file (it'll be named homebrew.mxcl.php.plist and it'll be in your Homebrew location, /usr/local/ or /etc/homebrew, under the folder Cellar/php/8.2.8, assuming you're on PHP 8.2.8).

Edit that file and add the following:

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

You'll add this directly under this line:

	<key>RunAtLoad</key>
	<true/>

Now run valet restart and try again.

If that doesn't fix it, let's do a little more cleanup.

* Run `brew services stop php` to make sure you're not running PHP as your individual user (it should run as root)

* Delete any `homebrew.mxcl.php.plist` files that are in `~/Library/LaunchAgents` (this is the list of launch agents for your individual user)

* Delete the `php82` sock file (`~/.config/valet/valet82.sock`) and then `valet install` again

Try again. That should fix it for everyone, according to our debugging so far here.

What's next?

I'd love for us to figure out why this problem is happening, but it does seem a bit daunting.

The second part of this answer worked for me! Thanks for sharing!

@driesvints
Copy link
Member

Closing this since a PR is up. Thanks all.

@zhangzhecomiru
Copy link

on my mac, the file location of Homebrew is in

/opt/homebrew/Cellar/php@7.3/7.3.33_8

try this if you can not find in /usr/local/ or /etc/homebrew

@rismailov
Copy link

If you're using Homebrew and this solution doesn't fix the issue for you, please make sure you're modifying homebrew.mxcl.php.plist file in the active php directory.

What I mean by that is, in my case, I had the following file structure:
/opt/homebrew/Cellar:
    php/
        8.0/
        8.1/
        8.2/ <----- this is the php version I use, so I figured it's there. but this package is not the active one
        etc...
    php@8.1/
    php@8.2/ <--------- this is the active package and this is where I needed to modify the .plist file

Those extra packages were created when I was trying to switch and link the php versions. As silly as it sounds, I've lost a few hours on this one and hopefully it will help someone.

@muzidudu
Copy link

muzidudu commented Jan 2, 2024

好的伙计们!使用我报告的这些信息,我找到了解决此问题的方法。

(我假设,哟都运行了,php版本是8.2.8)brew upgrade

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

像这样更改文件的内容: https://gist.github.com/askdkc/28480a0af1301993d92187920abec3bc`homebrew.mxcl.php.plist`

然后运行

valet restart

现在,PostgreSQL一切正常!

thx for ur help

@sashko-guz
Copy link

sashko-guz commented Feb 21, 2024

Hey guys.

If any other comment didnt fix your issue;

you can add next lines in /opt/homebrew/etc/php/8.2/php-fpm.d/valet-fpm.conf and restart laravel valet

Ref - Homebrew/homebrew-core#137431 (comment)

This worked for me: Add the following lines to your /usr/local/etc/php/<PHPVERSION>/php-fpm.d/www.conf Example /usr/local/etc/php/8.4/php-fpm.d/www.conf

;Signal 11 workaround
env['PGGSSENCMODE'] = disable
env['LC_ALL'] = C

And restart your effected PHP service, or test in running it directly: /usr/local/opt/php@8.4/sbin/php-fpm --nodaemonize

Needed this on all mine PHP versions, to make it work:

  • PHP 7.4
  • PHP 8.0
  • PHP 8.1
  • PHP 8.2
  • PHP 8.3
  • PHP 8.4

@drbyte
Copy link
Contributor

drbyte commented Feb 21, 2024

The workaround/fix is already built-in to Valet since v4.6.0. See #1452

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.