I'm encounter an error on my laravel installations on my computer. On certain calls (with payloads, with bearer token, ecc.) i recieve a "502 Bad Gateway" error. This is my configuration:
MacOS
Valet 4.3.0
PHP 8.0
Laravel 8.12
If i create a test route with a simple string print api call works. But if i use standard call with Request and Response nginx of Valet log this error:
[error] 6601#0: *1 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: ...
I didn't change anythings of my laravel source code in the meanwhile, but probably changed somethings in my configuration.
Anyone can help me to suggest some other checks?
I probably found the moment when I starting got this error: when I installed [email protected] via "brew install php". This command install php 8.2.x and a lot of packages.
This is because I found the App fails when attempt to login and a php package stuck somewhere (I googled a lot so this is a supposition...).
Do you know how to remove php 8.2 and all its packages? I usually use 8.0.x and php.7.4.x for older projects.
Ok, found where app crashes in a 502 error. When I perform an Eloquent function. So it's limited to those actions. So, to recap my situation:
My Laravel version is 8.12.
If I try the same function (e.g.: Card::find(1)) in thinker session it works perfectly
if a try a test API call (eg.: a simple test call with a string as response) it works perfectly
if I navigate su app via browser it works perfectly
if I try a Api call to a function of a controller where I have to perform an Eloquent query (e.g.: Card::find(1)) it responds with a 502 Bad Gateway error (with Nginx log "upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server:").
@kerranm unfortunately not yet... it's very frustrating, because in computer where I din't update composer, Nginx and valet, everything works yet... and in other computer can't resolve, also trying to downgrade to older versions of each packages of the stack...
I finally found a solution to my problem, and I want to share to anyone can be fall to this pit (@kerrnm):
In /usr/local/etc/php/8.2/php-fpm.d/www.conf after the following:
; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from
; the current environment.
; Default Value: clean env
;env[HOSTNAME] = $HOSTNAME
;env[PATH] = /usr/local/bin:/usr/bin:/bin
;env[TMP] = /tmp
;env[TMPDIR] = /tmp
;env[TEMP] = /tmp
Add an environment variable like this:
env['PGGSSENCMODE'] = disable
Then restart php. This will work even after a reboot.