Valet 4 is officially released! Let's look into what v4 offers and how you can upgrade your local install today.
Valet was originally introduced in May 2016 with this incredible video. Valet v2 was released soon after, bringing about the move from Caddy to Nginx. But after that, development on Valet slowed; as Taylor has often pointed out, "at that point, Valet was feature complete."
However, when I picked up maintenance of Valet a few years back, there were two things I noticed: first, that many people needed different versions of PHP for their different sites; and second, that miscellaneous features and bug fixes addressed over the years made the codebase a bit difficult to reason with at times.
Valet v3 was released in March 2022, with the primary focus on adding support for multiple versions of PHP running in parallel on the same machine.
And now, we're looking at Valet v4.
What's new in Valet 4?
The most important change to Valet 4 is something you can't even see from the outside: the internals of the project has been re-architected and tested heavily. Just to be clear, they've been re-architected back toward the style of simplicity Taylor and Adam's original code had. But they're now covered with all forms of unit and integration tests, and the changes made since Valet 2 are now much better integrated.
What does that mean?
Valet 4 is the most stable, easy to debug, and easy to fix version of Valet yet.
New features in Valet 4
There are a few user-facing new features:
valet statuscommand: If you run
valet status, you'll get a table showing you the "health" of a few important aspects of your Valet application. This is helpful both because you can use it when you're debugging, but, like any good CLI tool, it'll also return codes for success or failure that other CLI tools can consume.
- Upgrades to ngrok: If you use ngrok to share your sites, older versions of Valet bundled ngrok as an install. Now, Valet will prompt you to install ngrok through Homebrew, allowing you to have one universal version installed, and allowing you to keep it up to date as you please.
Expose as a share option: If you use Expose to share your sites, it's now integrated into Valet! Run
valet share-tool exposeand, if you don't have Expose installed, it'll prompt you to install it. Once you've set up your Expose token, you're ready to share using the same
valet sharecommand you're familiar with.
If you're upgrading from Valet 3, here's my preferred way to upgrade:
- Edit your
~/.composer/composer.jsonfile and update your Valet requirement to
composer global update laravel/valet
Make sure you run
valet install, as it'll check your system's compatibility and upgrade some configuration files for you.
If you have any custom drivers, you'll want to update them to match the new syntax (basically, drivers are now namespaced and have type hints and return types).
If you use
.valetphprc to define your sites' PHP versions, you'll want to rename those files to
.valetrc and change their contents;
.valetphprc files just contain a PHP Brew formula (e.g.
email@example.com), but the new
.valetrc files are broader config files, so you'll need to prefix the formula with
So if your project had this
You'll want to rename it to
.valetrc and update its contents to this:
Backwards compatibility: PHP 7.1-7.4
Valet 4 requires PHP 8.0+ to be installed on your system via Homebrew. As I mentioned already, you can use Valet's isolation feature to set individual sites to use older versions of PHP, back to 7.1.
However, if you have a reason you need to use PHP 7.1-7.4 as your primary linked PHP (meaning if you just type
php -v you see something between 7.1 and 8.0), you can do that! Just make sure that you have a modern version of PHP installed on your machine, and Valet will use that version to run its internal commands.
However, a quick warning: If you use Valet 4 and your primary linked version of PHP is lower than PHP 8, all of your local Valet CLI commands will run a bit more slowly, as they have to find your modern PHP install and proxy their calls through it.
That's it! The primary goal of Valet 4 is stability, but it also opens up some great new options for the future. First, the
.valetrc file is much more powerful than
.valetphprc was, and we can make it a lot more configurable. And second, I dropped a concept called
Extensions that was basically entirely unused, with the hope of building a plugin system sometime in the near future.
If you followed my journey of rebuilding Valet for v4 on Twitter, you might have seen that I attempted to make it work on Linux. Sadly, that wasn't successful, but I still have dreams of one day attempting it again. No promises... but it's still a dream!
I hope you all love Valet 4. Enjoy!
Co-founder, CTO, & COO at Tighten. Author of Laravel: Up and Running and host of the Laravel Podcast. Sharing tutorials and embarrassing stories on YouTube.