Skip to content

Switching between PHP versions with Laravel Valet

Since PHP8 was released we’ve started upgrading all our projects to PHP 8, the things we can do with attributes, union types, and other new features made us desire to do this upgrade as quickly as possible.

But sometimes you’ve got to work on an older project. When you want to switch between PHP versions in your terminal and Laravel Valet it is only one terminal command away:

valet use [email protected] --force

 

Want to switch back to PHP 8 then use [email protected]. Or just PHP since it’s the most recently released PHP version at this moment. You can switch to any PHP version installed with Homebrew on your system:

valet use [email protected] --force
valet use [email protected] --force
valet use [email protected] --force
valet use [email protected] --force
valet use [email protected] --force
valet use [email protected] --force
valet use [email protected] --force

 

You’ll probably need the shivammathur/homebrew-php tap to install some of these older versions with Homebrew.

Fixing a stuck Valet PHP version

Sometimes, the valet use the command only switches the PHP’s terminal version, but Valet’s PHP version keeps stuck. It can be that the valet socket is not configured properly, removing it normally solves the problem:

rm ~/.config/valet/valet.sock
valet restart

Leave a Reply

Your email address will not be published. Required fields are marked *

2 × four =