DEV Community

Aubrey Portwood
Aubrey Portwood

Posted on • Updated on

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

Please see comments for some important updates!


Screenshot on how to do this.

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 e.g. 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 setup to make this easy with valet@7 which makes sure my system continues to run 8.1.

Oldest comments (1)

Collapse
 
aubreypwd profile image
Aubrey Portwood

Okay, so this doesn't seem to be necessary anymore now that I ran into:

laravel.com/docs/9.x/valet#per-sit...

Apparently you can use valet isolate php@x.x to tell a specific site to use a specific version without modifying your system php version.

Now to go delete a bunch of unnecessary aliases!