Skip to content
All posts
WordPress4 min read

Set Up a Local WordPress Site on macOS with Laravel Valet

A practical walkthrough for running WordPress locally on a Mac with Laravel Valet, Homebrew, PHP, MySQL and WP-CLI, with clean .test domains and optional HTTPS.

On this page
  1. What you need
  2. 1. Install Homebrew
  3. 2. Install PHP
  4. 3. Install Composer
  5. 4. Install and secure MySQL
  6. 5. Install WP-CLI
  7. 6. Install Valet
  8. 7. Create the WordPress site
  9. 8. Turn on debugging
  10. 9. Open the site
  11. Handy Valet commands
  12. Wrapping up

Valet is a lightweight development environment for macOS. It runs Nginx and PHP in the background and serves every folder in a directory you choose as foldername.test, so there is no Apache, no MAMP and no manual virtual hosts. This guide walks through a complete local WordPress setup using Homebrew, PHP, Composer, MySQL, WP-CLI and Valet.

What you need

  • A Mac running a recent version of macOS
  • Terminal access and an admin account
  • About 20 minutes

1. Install Homebrew

Homebrew is the package manager used for everything below. Grab the current install command from brew.sh and run it in Terminal, then update it.

brew update

On Apple Silicon Macs, Homebrew lives in /opt/homebrew. If the brew command is not found afterwards, add that folder to your shell path in ~/.zshrc:

export PATH="/opt/homebrew/bin:$PATH"

Reload the shell so the change takes effect:

source ~/.zshrc

2. Install PHP

Valet needs PHP. Install the latest version, or pin the one your projects target.

brew install php
# or a specific version
brew install php@8.2

If you installed a specific version, make it the active one:

brew link --overwrite --force php@8.2

Confirm with php -v.

3. Install Composer

Composer is PHP's dependency manager, and it is how Valet itself gets installed.

brew install composer

Composer places global tools in ~/.composer/vendor/bin (or ~/.config/composer/vendor/bin on some setups). Add the right one to your PATH in ~/.zshrc, then reload:

export PATH="$PATH:$HOME/.composer/vendor/bin"
source ~/.zshrc

4. Install and secure MySQL

WordPress needs a database, so install MySQL and start it as a background service.

brew install mysql
brew services start mysql

Run the hardening script and set a root password when prompted:

mysql_secure_installation

Keep in mind that a fresh Homebrew MySQL install has a passwordless root user. That is fine for a purely local machine, but remember what you chose because you will need it in the WordPress step.

5. Install WP-CLI

WP-CLI lets you download, configure and install WordPress without clicking through a browser.

brew install wp-cli
wp --info

6. Install Valet

Install Valet through Composer, then let it configure Nginx and DnsMasq:

composer global require laravel/valet
valet install

Next, pick a folder to hold your projects and "park" it. Every subfolder becomes a site automatically.

mkdir -p ~/Sites
cd ~/Sites
valet park

7. Create the WordPress site

Make a folder named after the site you want. Valet will serve it at wordpress.test.

cd ~/Sites
mkdir wordpress && cd wordpress

Download the WordPress core files:

wp core download

Create wp-config.php with your database details. Replace the password with your own if you set one.

wp core config --dbname=wordpress --dbuser=root --dbpass= --dbhost=localhost

Create the database, then run the installer:

wp db create

wp core install \
  --url=http://wordpress.test \
  --title="My Local Site" \
  --admin_user=admin \
  --admin_password=change-me \
  --admin_email=you@example.com

Use any credentials you like. They only exist on your computer, but avoid reusing a real password.

Run a quick sanity check on the tables:

wp db check

Because the folder sits inside a parked directory, the site is already live. If you keep a project elsewhere, run valet link from inside that project folder instead.

8. Turn on debugging

Local development is where you want errors visible. These commands flip the debug constants in wp-config.php:

wp config set WP_DEBUG true --raw
wp config set WP_DEBUG_LOG true --raw

Warnings and notices will be written to wp-content/debug.log.

9. Open the site

valet open

Visit http://wordpress.test/wp-admin and sign in with the credentials from the install step. If you use VS Code, code . opens the project folder in your editor.

Handy Valet commands

Enable HTTPS with a locally trusted certificate:

valet secure

Switch back to plain HTTP:

valet unsecure

Change the top-level domain, for example from .test to .dev:

valet tld dev

Remove the Valet link for the current site when you no longer need it:

valet unlink

Note that valet unlink only stops serving the site. Deleting the project folder and dropping its database (wp db drop before you remove the files) are separate steps, so nothing is lost by accident.

Wrapping up

With Valet in place, creating another WordPress site takes about a minute: make a folder, run wp core download, configure, create the database, install, and it is available at yourfolder.test. If something misbehaves, valet restart fixes most problems, and valet fix can repair common configuration issues.