⚠️ Running Valet 2.x with 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.
ℹ️ UPDATE 2019.08.12: With the release of Valet 2.2.0, it is now possible to change PHP versions using the
valet command itself:
valet use firstname.lastname@example.org valet use php
Valet will install the specified PHP version via Brew if it is not already installed.
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@example.com # Stop latest PHP brew services stop php brew unlink php # Activate PHP 7.1 brew link firstname.lastname@example.org --force brew services start email@example.com
🔥 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
# Tap exolnet/homebrew-deprecated $ brew tap exolnet/homebrew-deprecated # Installing these old versions will now work $ brew install firstname.lastname@example.org $ brew install email@example.com
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 firstname.lastname@example.org
After these steps here I (finally) got it working.
Switching PHP versions with Laravel Valet →
Thank me with a coffee.
I don\'t do this for profit but a small one-time donation would surely put a smile on my face. Thanks!
To stay in the loop you can follow @bramus or follow @bramusblog on Twitter.
You are a life saver my friend.
I followed the same process for switching from php 7.1 to 7.2 . It worked like charm.
Can’t thank enough.
If you upgrade to the latest version of Valet, you can now switch using the command “valet use php@version”. If you don’t have that version, it will install via Homebrew and then switch.
Leave a comment