For my local PHP Development needs I use Laravel Valet. It’s easy to set up, provides HTTPS, and just works. The only downside of using it, is the fact that the selected PHP version is system-wide: switching PHP versions — using valet use php@7.4
for example — affects all sites. With the 3.0 release of Valet this is no longer the case, as it offers per-site PHP version isolation.
To isolate a site, use new isolate
command:
cd path/to/app
# Isolate the current project
valet isolate php@7.4
# Isolate a site by name
valet isolate php@8.0 --site=laravel9x
If a certain PHP version is missing, Valet will install it automagically (using Homebrew)
⬆️ If you’re already running Valet, you can’t update to 3.x by invoking good ’ole composer global update
. Instead, you must re-require Valet again, with the required version set to ^3.0
composer global require "laravel/valet:^3.0"
~
Note that when isolating sites using valet isolate
, it only affects the PHP version that’s used by Nginx. On the CLI your php
will always use the one you’re globally using. For dependencies, you could lock down your PHP version via composer.json
, but that won’t prevent you from possibly incompatible PHP syntax.
To cater for both issue, version 3.1 (which got released just few days after 3.0) comes with three new commands that allow you to run PHP and Composer commands using the isolated site’s PHP version on the CLI.
valet php ...
will proxy PHP Commands with isolated PHP versionvalet composer ...
will proxy Composer Commands with isolated PHP versionvalet which-php
outputs the PHP executable path for a site. For isolated site it would output the isolated PHP executable path. But non-isolated site will just output the linked default PHP path. The other two commands are dependent on this one to find the PHP executable.
To not have to type valet php
every time, this tip by Jacob Delcroix is pure gold: make php
an alias for valet php
My aliases to work seamlessly with new Valet isolation feature 🙂 #valet #laravelvalet #phpmon. Thanks @stauffermatt @NasirNobin and @nicoverbruggen for your amazing work. 🚀🚀🚀 Now I don't have to worry about PHP versions anymore. My main version is always up-to-date! pic.twitter.com/XPOdyhGLHK
— Jacob Delcroix (@JacobDelcroix) April 3, 2022
~
If you’re rocking the aforementioned PHP Monitor, you’ll be glad to read that version 5.2 has isolate
support built-in.
To update PHPMon, do so using Homebrew:
brew upgrade phpmon
~
🔥 Like what you see? Want to stay in the loop? Here's how: