Local WordPress development made easy with Laravel Herd and DBngin. We’ll use wp-cli to download, install, and manage a local WordPress environment in just a few minutes.
Relevant Links
- Laravel Herd
- DBngin
- WP-CLI
- Developer Riza responded by demoing a simple shell script to automate much of what I go over in this video.
- Tom McFarlin has a great snippet to integrate Herd’s local Mail server with WordPress
Set up a local WordPress site
If you want a fast local WordPress environment without Docker, you can assemble a lightweight stack from three tools: Herd handles PHP, nginx, and local .test domains; DBngin runs MySQL; and WP-CLI downloads, configures, and installs WordPress from the terminal.
In a few minutes, you can go from an empty directory to a working WordPress site at example.test.
This tutorial was originally recorded on macOS in October 2024. Herd and DBngin now support both macOS and Windows, but the directory and shell examples below use macOS.
Before you start
Download and install Herd, DBngin, and WP-CLI. The free version of Herd provides the PHP and web-server pieces we need. DBngin supplies the database server; TablePlus is optional if you want a graphical database client.
Open Herd and make sure it is running. Then open DBngin, create or select a MySQL service, and start it. The indicator should turn green.
Take note of the MySQL service’s:
- Host
- Port
- Username
- Password
In this example, MySQL uses 127.0.0.1:3306, the username root, and an empty password. Use the actual values shown in DBngin if yours are different.
1. Create the site directory
Herd uses “parked” directories. Every top-level folder inside a parked directory automatically becomes a local .test site. Herd parks ~/Herd by default, but you can add a different directory in its settings.
From your parked directory, create a folder for the site:
cd ~/Herd
mkdir example
cd example
Herd should now recognize the directory and serve it at http://example.test. You will see a 404 page for the moment because the directory is still empty.
If you want to use HTTPS locally, secure the site from this directory:
herd secure
Then use https://example.test as the site URL in the remaining steps.
2. Download WordPress
Use WP-CLI to download the latest stable WordPress release into the current directory:
wp core download
If you reload example.test, you should now see the WordPress installation screen. WordPress is not ready yet, though: it still needs a configuration file and a database.
3. Create wp-config.php
Create the WordPress configuration file with the connection details from DBngin:
wp config create \
--dbname=example \
--dbuser=root \
--dbpass='' \
--dbhost=127.0.0.1:3306Code language: JavaScript (javascript)
Change the database name or connection details as needed. In particular, DBngin can run multiple database versions on different ports, so do not assume that your service uses port 3306.
4. Create the database
Because the database credentials now live in wp-config.php, WP-CLI can use them to create the database:
wp db create
You should see:
Success: Database created.Code language: HTTP (http)
If WP-CLI cannot find the mysql command, add the bin directory for your DBngin MySQL service to your shell’s PATH, then try again. The exact directory depends on the MySQL version and where DBngin installed it.
5. Install WordPress
You could finish the familiar “five-minute install” in the browser, but WP-CLI is faster:
wp core install \
--url=http://example.test \
--title=Example \
--admin_user=admin \
--admin_password=password \
[email protected] \
--skip-emailCode language: JavaScript (javascript)
If you secured the site with Herd, change the URL to https://example.test.
These credentials are intentionally simple for a disposable local site. Use a stronger password if the site will ever be reachable outside your computer.
Once the command finishes, WP-CLI should report:
Success: WordPress installed successfully.Code language: HTTP (http)
Visit http://example.test/wp-admin/ and log in with the username and password you supplied.
6. Keep using WP-CLI
WP-CLI remains useful after the initial setup. For example, you can install and activate Query Monitor with one command:
wp plugin install query-monitor --activate
You can also update WordPress:
wp core update
Or check the versions of WordPress and PHP currently in use:
wp core version
php -v
herd which-php
That last check is helpful if you use Herd’s per-site PHP isolation. WP-CLI runs with the PHP available to your terminal, so make sure its version matches the version Herd is using to serve the site.
The complete setup
Here is the full WordPress portion in one place:
cd ~/Herd
mkdir example
cd example
wp core download
wp config create \
--dbname=example \
--dbuser=root \
--dbpass='' \
--dbhost=127.0.0.1:3306
wp db create
wp core install \
--url=http://example.test \
--title=Example \
--admin_user=admin \
--admin_password=password \
[email protected] \
--skip-emailCode language: PHP (php)
That is the entire local environment: Herd serves PHP and the site, DBngin runs MySQL, and WP-CLI handles WordPress. There are no containers and very little configuration to manage.
If you create local sites this way often, the next step is to wrap these commands in a small shell script. Until then, running them individually makes it easier to see what each part of the WordPress installation process is doing.
Are you using Herd for WordPress development, or is there another local environment you prefer?
Leave a Reply