https://github.com/roelmagdaleno/herd-wp-setup
Automate local WordPress site creation with Laravel Herd, WP-CLI, and DBngin.
https://github.com/roelmagdaleno/herd-wp-setup
bash-script laravel-herd local-development wordpress wp-cli
Last synced: 2 months ago
JSON representation
Automate local WordPress site creation with Laravel Herd, WP-CLI, and DBngin.
- Host: GitHub
- URL: https://github.com/roelmagdaleno/herd-wp-setup
- Owner: roelmagdaleno
- Created: 2025-10-05T23:08:09.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-10-05T23:19:30.000Z (9 months ago)
- Last Synced: 2025-10-06T01:13:10.280Z (9 months ago)
- Topics: bash-script, laravel-herd, local-development, wordpress, wp-cli
- Language: Shell
- Homepage:
- Size: 4.88 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# herd-wp-setup
A tiny Bash utility to automate the local setup of a new WordPress site using WP-CLI and Laravel Herd.
## Features
- 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
## Requirements
### Laravel Herd
[Install and configure Laravel Herd](https://herd.laravel.com/docs/macos/getting-started/installation) on your machine. Ensure your base WordPress projects directory is added to Herd.
### WP-CLI
Install [WP-CLI](https://wp-cli.org/) and ensure it's available in your terminal's PATH.
### MySQL
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](https://herd.laravel.com/docs/macos/herd-pro-services/services), DBngin, Homebrew MySQL, or another local server.
The default connection in the script points to:
- `DB_USER` = `root`
- `DB_PASSWORD` = (empty)
- `DB_HOST` = `127.0.0.1`
- `DB_PORT` = `3307`
### Other Dependencies
- OpenSSL (for generating an admin password when not provided)
## Configuration
This script uses simple variables at the top of `herd-wp-setup.sh`. Edit these to suit your environment before running.
### Path
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.
### Database
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`)
### Environment variables (.env support)
You can configure the script using environment variables loaded from a .env-style file.
Ways to provide configuration (highest priority first):
1. CLI flags (e.g., `--name`, `--username`, etc.)
2. 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`
3. 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 username
- `HERD_WP_DB_PASSWORD` - MySQL password
- `HERD_WP_DB_HOST` - MySQL host
- `HERD_WP_DB_PORT` - MySQL port
- `HERD_WP_DEFAULT_ADMIN_USER` — Default WordPress admin username
- `HERD_WP_DEFAULT_ADMIN_EMAIL` — Default WordPress admin email
- `HERD_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
```
## Mail
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](https://herd.laravel.com/docs/macos/herd-pro-services/mail#wordpress) is part of Herd Pro Services.
## Usage
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:
- `--name` Site name (e.g., "WPB Plugins"). Used to derive domain, folder, and DB name
- `--username` WordPress admin username (default prompted; falls back to `admin`)
- `--email` WordPress admin email (default prompted; falls back to `admin@.test`)
- `--password` WordPress admin password (if omitted, you’ll be prompted and can auto-generate)
- `--env-file` Path to a .env file to load configuration variables (overrides defaults)
Examples:
```bash
# 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 download`
- `herd secure` to ensure a local TLS cert
- Create a MySQL database named `acme_blog`
- `wp config create` with the DB connection
- `wp core install` with the provided or prompted admin credentials
- Move the `herd-mailer` plugin to the `mu-plugins` folder for local email logging