Yet another Laravel Valet Http 502 Error Fix

Yet another Laravel Valet Http 502 Error Fix

I've lost 24 hours to fix this problem after I've installed PHP8.0 and worked a while with it, until I've installed XDebug besides it. Removed XDebug again, deleted other PHP versions within brew, uninstalled and installed Valet back countless times, ran valet diagnose and brew doctor several times, done all of the proposed solutions online, but nothing helped to retrieve the website back...

Until..

I started playing with the users running those services. dnsmasq directly gave me the idea that it should be run under the root account, and I thought every other service should be run under the user account that I logged in with. They didn't work under the current user either.

Then after several tries I found the correct users to run those services with.

The final result was:

All services except mysql should run under the root user. mysql should run under the current user.

The command I succeeded the correct configuration:

brew services stop dnsmasq && sudo brew services start dnsmasq
sudo brew services stop mysql && brew services start mysql
brew services stop nginx && sudo brew services start nginx
brew services stop php && sudo brew services start php
brew services stop redis && sudo brew services start redis
brew services stop supervisor && sudo brew services start supervisor

Without sudo prepended to the command, it runs under the current user account, otherwise, it runs under the root account.

I'll leave it here for later reference for everybody, since it's the second time I lost a day to solve this.

Hope it helps.

Note: Yep, that was not the issue. Opcache was blowing it away. Figured that out after doing this:

valet uninstall --force
brew doctor
brew cleanup
composer remove laravel/valet
composer require laravel/valet
valet install
valet start

Everything ran smoothly, until I decided to enable JIT again. The 502 was still there. Once I've disabled it again, it was gone.