Michael Dyrynda
Home Blog Podcasts
 
Switching PHP versions with Laravel Valet January 18th, 2017

At the time of writing, Laravel Valet ships with PHP 7.1 but if you're like me, you have some legacy projects around the place that haven't quite lifted their dependencies to PHP 7 just yet.

A lot of folks might have previously used a VirtualBox Virtual Machine, or more recently considered Docker but a lot of the time and especially when dealing with simpler situations, Valet may be all that you need.

Luckily, the combination of Valet and brew on macOS makes switching PHP versions really easy.

It's not covered in the screencast above, but you can install versions of PHP from 5.3 right through to 7.1 via brew using brew install php<version>. Note that whilst you can install any version from 5.3 via brew, the minimum that the latest version of Valet supports is 5.6.

1$ brew install php56
2$ brew install php70

You can check the currently linked version of PHP by running php -v and the running version of FPM with brew services list.

Switching the PHP version simply involves stopping and unlinking the active version and linking and running the supported version you want to work with.

If you find that Valet starts serving 502 errors, ensure that you ran the brew services start php<version> command. Without this, Valet won't have a running version of PHP FPM to forward its PHP requests through.

Lastly, I had previously come across an issue where sometimes Valet would stop serving sites entirely. Solving this was simply a case of running valet install to make sure all the services were linked properly, but I've not seen this issue since installing the latest - at the time of writing, 2.0.2 - version of Valet.

I'm a real developer ™
Michael Dyrynda

@michaeldyrynda

I am a software developer specialising in PHP and the Laravel Framework, and a freelancer, blogger, and podcaster by night.

Proudly hosted with Vultr

Syntax highlighting by Torchlight