DEV Community

Ariel Mejia
Ariel Mejia

Posted on

Switch to Older PHP versions with Laravel Valet

The problem

Laravel Valet currently support PHP 8 and higher versions (8.1, 8.2), but if you try to switch from PHP 8.1 to PHP 7.4 for a legacy project (as an example) it would be a headache.

The problem would be, when you need to return to an updated PHP version... there would start the real mess...

Solution

Lets supposed that we are currently in PHP 8.1 version, then to work on a legacy project you would require to switch to PHP 7.4 as an example:

valet use php@7.4 
Enter fullscreen mode Exit fullscreen mode

It would work, then to return to an updated PHP version (8.1 or 8.2), you would face an issue if you try to switch back with this command:

// use to work with the most recent version
valet use php
Enter fullscreen mode Exit fullscreen mode

Fix the issue and go back to the most recent PHP version:

This command would unlink all 7.x versions, (but you can unlink only a specific one):

brew unlink php@7.0 php@7.1 php@7.2 php@7.3 php@7.4
Enter fullscreen mode Exit fullscreen mode

Install the most recent PHP version, (if the system does not have it):

brew install php
Enter fullscreen mode Exit fullscreen mode

Then it would link the most recent PHP version

brew link php
Enter fullscreen mode Exit fullscreen mode

If this last command does not work, you can use some flags to force it:

brew link --force --overwrite php
Enter fullscreen mode Exit fullscreen mode

Then just instruct Valet to use the most recent PHP version:

valet use php --force
Enter fullscreen mode Exit fullscreen mode

Hope it helps and thanks for reading, happy coding!

Top comments (0)