Laravel valet 502 error when using postgres pgsql driver
I recently faced an issue where my local Laravel installation would stop working when using the pgsql database driver. The error was a pretty obscure 502 NGINX error page - which is always a trigger to investigate the logs.
Quick tip, in Valet you can tail the logs pretty easily:
valet log -f php-fpm
valet log -f nginx
After some digging in the NGINX logs, I noticed it was FPM that stopped responding:
[error] 35039#0: *1 upstream prematurely closed connection while reading response header from upstream
And the FPM logs were pretty bizarre, stating the process was killed using SIGABRT.
WARNING: [pool valet] child 35051 exited on signal 6 (SIGABRT) after 1.472859 seconds from start
NOTICE: [pool valet] child 35063 started
To make things even stranger, using php artisan serve
everything worked as intended.
Luckily, I came across this article explaining the issue is linked to the GSSAPI Encryption, and simply disabling this fixes the issue.

One addendum on Jan's blog: when using an Apple Sillicon Mac, you can find the config files here:
sudo nano /opt/homebrew/etc/php/8.2/php-fpm.d/valet-fpm.conf
Just adding the following line to the valet-fpm.conf file (and running valet restart
) fixes the issue:
env['PGGSSENCMODE'] = disable
No spam, no sharing to third party. Only you and me.