A tiny Bash utility to automate the local setup of a new WordPress site using WP-CLI and Laravel Herd.
- Creates a project folder under a configured base path
- Downloads WordPress via WP-CLI
- Secures the local site with
herd secure - Creates a MySQL database
- Generates
wp-config.php - Runs the WordPress installer with your chosen admin credentials
- Loads configuration variables from a .env file (or via
--env-file) with sensible defaults
Install and configure Laravel Herd on your machine. Ensure your base WordPress projects directory is added to Herd.
Install WP-CLI and ensure it's available in your terminal's PATH.
Ensure you have a local MySQL server running and accessible. The script uses the mysql client to create databases.
You can use databases created via Herd Pro Services, DBngin, Homebrew MySQL, or another local server.
The default connection in the script points to:
DB_USER=rootDB_PASSWORD= (empty)DB_HOST=127.0.0.1DB_PORT=3307
- OpenSSL (for generating an admin password when not provided)
This script uses simple variables at the top of herd-wp-setup.sh. Edit these to suit your environment before running.
This is the base folder where new WordPress sites will be created. It must be registered in Herd.
Default is /Users/roelmagdaleno/Code/WordPress, but change it to your own path.
Configure your local MySQL connection details:
DB_USER(default:root)DB_PASSWORD(default: empty)DB_HOST(default:127.0.0.1)DB_PORT(default:3307)
You can configure the script using environment variables loaded from a .env-style file.
Ways to provide configuration (highest priority first):
- CLI flags (e.g.,
--name,--username, etc.) - Variables loaded from an env file
- Pass a file via
--env-file /path/to/.herd-wp-setup.env - Or place a default file at
~/.herd-wp-setup.env
- Pass a file via
- Built-in defaults (shown above)
Supported variables for the env file:
HERD_WP_BASE_PATH— Base folder for new sites (must be registered in Herd)HERD_WP_DB_USER- MySQL usernameHERD_WP_DB_PASSWORD- MySQL passwordHERD_WP_DB_HOST- MySQL hostHERD_WP_DB_PORT- MySQL portHERD_WP_DEFAULT_ADMIN_USER— Default WordPress admin usernameHERD_WP_DEFAULT_ADMIN_EMAIL— Default WordPress admin emailHERD_WP_DEFAULT_ADMIN_PASSWORD— Default WordPress admin password
Example ~/.herd-wp-setup.env:
HERD_WP_BASE_PATH=/Users/you/Code/WordPress
HERD_WP_DB_USER=root
HERD_WP_DB_PASSWORD=
HERD_WP_DB_HOST=127.0.0.1
HERD_WP_DB_PORT=3307
HERD_WP_DEFAULT_ADMIN_USER=admin
HERD_WP_DEFAULT_ADMIN_EMAIL=admin@local.test
HERD_WP_DEFAULT_ADMIN_PASSWORD=secret
The script includes the stubs/herd-mailer.php must-use plugin that connects to Herd's Pro SMTP server for local email logging.
After running the script, the PHP file will be copied to the next path wp-content/mu-plugins/herd-mailer.php of the new WordPress site.
Mail is part of Herd Pro Services.
Make the script executable (first time only):
chmod +x herd-wp-setup.sh
Run the script. You can provide CLI arguments or follow the interactive prompts.
Supported options:
--nameSite name (e.g., "WPB Plugins"). Used to derive domain, folder, and DB name--usernameWordPress admin username (default prompted; falls back toadmin)--emailWordPress admin email (default prompted; falls back toadmin@<domain>.test)--passwordWordPress admin password (if omitted, you’ll be prompted and can auto-generate)--env-filePath to a .env file to load configuration variables (overrides defaults)
Examples:
# Fully interactive
./herd-wp-setup.sh
# Provide only the site name (other values prompted)
./herd-wp-setup.sh --name "My WP Site"
# Use an env file for configuration (overrides defaults)
./herd-wp-setup.sh --env-file ~/.herd-wp-setup.env --name "Env Driven Site"
# Non-interactive install with explicit admin credentials
./herd-wp-setup.sh \
--name "Acme Blog" \
--username acme_admin \
--email admin@acme.test \
--password "S3cureP@ss!"What the script will do:
- Convert the site name to a domain (lowercase, spaces → dashes). Example: "Acme Blog" →
acme-blog.test - Create a folder at
${BASE_PATH}/acme-blog wp core downloadherd secureto ensure a local TLS cert- Create a MySQL database named
acme_blog wp config createwith the DB connectionwp core installwith the provided or prompted admin credentials- Move the
herd-mailerplugin to themu-pluginsfolder for local email logging