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 firstname.lastname@example.org 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
cd path/to/app # Isolate the current project valet isolate email@example.com # Isolate a site by name valet isolate firstname.lastname@example.org --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
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 version
valet composer ...will proxy Composer Commands with isolated PHP version
valet which-phpoutputs 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
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
To update PHPMon, do so using Homebrew:
brew upgrade phpmon