How to run your system PHP at 8.x & Laravel Valet at 7.x

Please see comments for some important updates!

Screenshot

Valet, when told to use a specific version of PHP (using valet use) symlinks $HOME/.config/valet/valet.sock (on macOS) to a specific version of PHP installed on your system. If you use valet use, unfortunately, it switches this symlink and your system PHP version.

But all you need to do is (with Homebrew) use brew unlink php && brew link php@8.1 --force --overwrite to tell your system to use PHP 8.1.x. That does not tell Valet what version to use; valet use does.

If you use, for example, valet use php@7.4, you can simply use brew unlink php && brew link php@8.1 --force --overwrite to re-link your system back to using PHP 8. If you look at $HOME/.config/valet/valet.sock, you will notice it’s still symlinked to valet74.sock, and you can confirm with, e.g., phpinfo().

It’s a bit of a hack, but it works for me.

Take a look at some aliases I have set up to make this easy with valet@7, which ensures my system continues to run 8.1.