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 firstname.lastname@example.org --force
Want to switch back to PHP 8 then use email@example.com. Or just php since it's the most recent released PHP version at this moment. You can switch to any PHP version installed with Homebrew on your system:
valet use firstname.lastname@example.org --force valet use email@example.com --force valet use firstname.lastname@example.org --force valet use email@example.com --force valet use firstname.lastname@example.org --force valet use email@example.com --force valet use firstname.lastname@example.org --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
valet use 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