Local WordPress with Herd, DBngin, and WP-CLI

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

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?

7 responses to “Local WordPress with Herd, DBngin, and WP-CLI”

  1. Trevor Robertson Avatar

    Cool, thanks for making this post! How great is it hey that there is now a proliferation of better local dev tools than the XAMPP days? Docker sounded great when I finally decided to move to something new, but upon diving in I quickly realised it was overkill for a sole developer. I just wanted to get things done not mess around with my dev setup for hours.

    So in the end my local dev tool of choice became Lando. Have you checked it out before? All the power of Docker without any of the PITA. I love the built in easy local SSL cert setup. Overall, Lando is a maybe a slight bit more work than Herd, but I’ve read elsewhere that if you need Herd Pro, Lando (which is free) is probably what you should do instead as Herd Pro is essentially a GUI wrapper equivalent of Lando.

    1. Brian Coords Avatar
      Brian Coords

      I have used Lando in the past, when I was working with clients on Pantheon. And then Docker for projects on WordPress VIP. It’s kind of annoying that all these hosts have specific dev environments, though it makes sense to match the environment to the host. I think what I likes about Herd was it feels very minimal- just directories of PHP. I almost never open the GUI.

    2. Slava Abakumov Avatar

      I used Lando, and it’s awesome until you need to sync changes in big /vendor/ or /node_modules/ directories. Everything was so slow unless you unmount those directories. But then you will need to manually run “composer update” and “npm update” in 2 places: on a host (so IDE knows about the changes) and in the docker image (so the site knows about the changes). PITA.

      But I was on Windows back then, now sure how fast does it work on MacOS/Linux.

  2. Slava Abakumov Avatar

    With your setup you still must have PHP running on your computer which defies the reason of using Herd. It’s because wp-cli requires PHP.
    And now you have inconsistency when you switch PHP versions for your sites in Herd, and PHP and wp-cli on your host are still running something else – and you need to switch PHP version there as well.

    MySQL via dbngin can indeed be replaced with Herd Pro though.

    That’s why I continue using valet + phpmon, everything through brew – until I figure out how to easily use wp-cli from within the Herd-initiated terminal.

  3. Ahmet Avatar

    easily, useful and minimalist thanks brian

  4. Colin Avatar
    Colin

    Thanks for this – couple problems I ran into:

    Don’t try to customize the location of the DB (‘data path’) in DBgin as you run into permissions trouble, which I didn’t feel like hassling with. It likes being in `users/Shared` to obviously avoid this problem

    Don’t forget to add the DB executables to your PATH or wp-cli will have no idea where they are and will fail on trying to do anything DB-related, eg
    `export PATH=”/Users/Shared/DBngin/mysql/8.0.40_arm64/bin”:$PATH`

    1. Brian Coords Avatar
      Brian Coords

      Nice! I also ended up just paying for Herd Pro and using their database service, too. Though now I find myself using WordPress Studio more often for local sites.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Follow Modern WordPress Development

Receive new posts in your inbox. Never spam.

Continue reading