Just like WordPress has specific tools like VVV that are tailored to the development of WordPress sites locally, the wider PHP community has similar tools. Today we’re going to look at Valet, which is a tool that is specific to hosting Laravel projects for local development.
While Valet was released by the Laravel team, it is designed to support WordPress out of the box, along with other CMS’s like Craft and Statamic.
Let’s dig into how to get a WordPress site running on Valet.
Prepping to Install Valet
If you’ve used tools like XAMPP or MAMP before, this is going to be a bit different as we need some other terminal-based tools installed before we can get Valet running.
First, we’ll need to install Homebrew. Homebrew is a package manager for macOS Terminals or Linux shell prompt. We’ll need this to install the packages that will make up Valet. If this feels daunting to start, don’t worry. There are only a handful of basic commands we need to run.
To install Homebrew use the command below.
/bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)”
You’ll be greeted by some prompts to set up Homebrew. They’re all very clear so just follow them and it will be set up for you.
Before we go forward we need to make sure that we have the most recent package definitions for Homebrew. To do this we need to update it with the commands below.
This makes sure that nothing needs fixing in Homebrew. If everything is good to go then you can update Homebrew.
If your system doesn’t find Homebrew in your $PATH then you can add it with this command. export PATH=”/usr/local/bin:$PATH” If you have other errors, check the Homebrew troubleshooting guide
Next, let’s get PHP 7.4 installed via Homebrew with the command below.
brew install email@example.com
How long this takes depends in part on your internet connection since Homebrew has to download PHP. Once it’s downloaded Homebrew will set up PHP 7.4 on your system.
Finally, we need to make sure that Composer is installed on our system. You can find those directions in my previous post on Composer or check out the official documentation on installing Composer.
Now that we have everything set up, it's time to install Valet via Composer with the command below.
composer global require laravel/valet
If you get errors it’s possible that you need to download some more dependencies. If so run the command above with –with-all-dependencies to make sure they get downloaded.
Now that we have Valet downloaded we need to set it up. Run the following command in Terminal. You should be prompted for your password before this command runs.
Now we have Valet installed, so we can move on to getting a WordPress site setup.
Getting WordPress Installed in Valet
There are two basic commands you’ll need to know to use Valet effectively.
- park: this is used to add a directory to Valet. If you created a folder called ~/valet-sites you would use the park command to add that whole folder as a spot that sites could run out of.
- link: this allows you to add a single site folder to Valet instead of a whole directory where you’d run different sites.
Now we need to download WordPress so that we can use it to create a Valet based site to work on. Unzip the download and rename it valet-nexcess. Next in terminal move into our new directory with cd valet-nexcess and then type valet link to link that directory into Valet so you can use it to host WordPress.
Now you should be able to visit valet-nexcess.test and see the WordPress install screen.
Before you move through the WordPress setup though we need to install a database layer because Valet doesn’t come with that. We can install MySQL via Homebrew with the following command.
brew install mysql
Once MySQL has been installed we need to start it.
To stop MySQL you’d use mysql.server stop
Now you can connect to the Valet database with your favourite local database tool and create a new database.
Then simply finish the WordPress install and get working on your new site.
When it comes to Unit Testing with Valet, you’re in luck because I’ve already written a tutorial on how to setup Unit Testing for WordPress using Valet. It’s fairly easy to do with a few terminal commands.
For capturing email we return to MailHog which can be installed via Homebrew easily. WP Beaches has an excellent tutorial on how to get this setup for your development environment.
While it’s not too difficult to setup Valet for your WordPress projects, I’ve found the performance to be lacking. Despite talking with many other developers, I’ve never been able to figure out why I’m having performance issues that they don’t see despite running huge sites locally for development.
I’ve also found that I have to adjust the Valet settings every month or so because it stopped working for some reason. For me, Valet has lots of power but takes a bit too much management to keep using daily as my local development environment.