Switching PHP versions with Laravel Valet

⚠️ Running Valet 2.x in a PHP version lower than 7.1 won’t work, until this issue is resolved. You can still switch to that version for use on the CLI. You just won’t be able to use it with Valet 2.x

ℹ️ UPDATE 2018.10.23: Freek has developed some handy aliases to easily switch PHP versions.

For some older projects that I still need to run, I recently started using Valet. As those projects sometimes require different versions of PHP – or when I want to test them with the latest PHP version – I followed this set of instructions by Michael Dyrynda:

With the most recent Homebrew – in which PHP got moved to the core – I had to slightly tweak the commands a bit though:

# Install PHP 7.1 (you only need to do this once)
brew install [email protected]

# Stop latest PHP
brew services stop php
brew unlink php

# Activate PHP 7.1
brew link [email protected] --force
brew services start [email protected]

🔥 Because they are no long supported, PHP versions 5.6 and 7.0 have been removed from homebrew/core. If you still need to install them, you can find them in the exolnet/homebrew-deprecated tap.

# Tap exolnet/homebrew-deprecated
$ brew tap exolnet/homebrew-deprecated

# Installing these old versions will now work
$ brew install [email protected]
$ brew install [email protected]

I noticed that after running these command you – somehow – might still have the “old” php service running as root (you can check with brew services list). In that case force it to stop, and restart the new version service:

sudo brew services stop php
brew services restart [email protected]

After these steps here I (finally) got it working.

Switching PHP versions with Laravel Valet →

(via Freek)

Did this help you out? Like what you see?
Consider donating.

I don’t run ads on my blog nor do I do this for profit. A donation however would always put a smile on my face though. Thanks!

☕️ Buy me a Coffee ($3)

Join the Conversation

1 Comment

Leave a comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.