Table of contents
Get the industry’s fastest hosting for WordPress◦ 99.999% uptime
◦ Comprehensive security
◦ 24/7 support

WordPress GuideLocal → Laravel Valet

Build a local development environment with Valet and WordPress

Just like WordPress has specific tools like VVV for local WordPress development, the wider PHP community has similar tools. Today we’re going to look at Valet, a tool for hosting Laravel projects locally.

While Valet was released by the Laravel team, it is designed to support WordPress out of the box, along with other CMSs like Craft, Drupal, and Statamic.

Let’s dig into how to get a WordPress site running on Valet.

Pros and cons of Valet

Pros

It has a simple setup process, allowing developers to get started quickly without complex configurations.

It is lightweight and fast, using minimal system resources for a smooth and efficient local development experience.

It integrates smoothly with Laravel, offering automatic configuration and optimized performance.

It supports a wide range of PHP frameworks and CMS platforms, including WordPress, Drupal, Craft, and Statamic, providing flexibility for different projects.

It automatically manages SSL certificates, simplifying the process of setting up secure local development environments.

Cons

It’s only available on macOS, leaving Linux and Windows users without native support, although forks and alternatives like WSL may work.

It’s best suited for simple projects and may not support more complex configurations or advanced setups.

It relies on Homebrew for installation and management, which might be inconvenient for users unfamiliar with this package manager.

It does not have a graphical user interface, meaning developers must manage everything via the command line.

How to set up WordPress locally with Valet

Valet pre-install preparation

The setup process is a bit different from other local WordPress development tools like XAMPP and MAMP as we need some other terminal-based tools installed before we can get Valet running.

First, we’ll need to install Homebrew, a package manager for macOS Terminals. 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.

If your system doesn’t find Homebrew in your $PATH then you can add it using export PATH="/usr/local/bin:$PATH"

If you have other errors, check the Homebrew troubleshooting guide.

Next, let’s get the latest version of PHP installed:

brew install php

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 on your system.

Finally, we need to make sure that Composer is installed on our system. Use the following commands to download, run, and delete the installer:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'dac665fdc30fdd8ec78b38b9800061b4150413ff2e3b6f88543c636f7cd84f6db9189d43a81e5503cda447da73c7e5b6') { echo 'Installer verified'.PHP_EOL; } else { echo 'Installer corrupt'.PHP_EOL; unlink('composer-setup.php'); exit(1); }"
php composer-setup.php
php -r "unlink('composer-setup.php');"

This will install Composer as composer.phar, but if you want to call it as just composer, from any directory, use the following command:

sudo mv composer.phar /usr/local/bin/composer

Installing Valet on your system

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.

valet install

Now we have Valet installed, so we can move on to getting a WordPress site setup.

Installing WordPress inside Valet

There are two basic commands you’ll need to know to use Valet effectively.

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 the folder to something like valet-project.

Next, in the terminal, move into the new directory with cd path/to/valet-project and then run valet link to link that directory into Valet so you can use it to host WordPress.

Now you should be able to visit valet-project.test in your browser 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.

mysql.server start

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.

You can also use Valet for WordPress multisite projects, same setup process and all, but there are considerations you need to make depending on whether you choose to use subdomains or subdirectories.

If you opt for subdomains, you’ll need to use the link command to source each one from the original directory, e.g.:

valet link site1.valet-project.site

This should also work for domain mapping, and Valet will handle all DNS wildcards automatically.

Unfortunately, Valet isn’t compatible with the subdirectory setup out of the box, but you can install the WordPress Multisite Subdirectory Valet Driver to add support.

Additional resources

How to install WordPress on localhost →

A beginner’s guide to WordPress local and how to get started

How to Install WordPress on Linux →

8 steps to get you started on AlmaLinux

Curtis McHale is a husband, father, developer and business coach. He specializes in helping people build a business that lets them spend time with their family instead of working all the time.