Create new WordPress site for DDEV via script

1. Ensure You Have DDEV Installed

Make sure you have DDEV installed on your system. You can check by running:

ddev version

2. Save the Script

  1. Open a terminal.
  2. Create a new file:
nano create-ddev-wp.sh
  1. Copy and paste the script into the file.
#!/bin/bash

# Usage: ./create-ddev-wp.sh myproject

set -e

PROJECT_NAME=$1

if [ -z "$PROJECT_NAME" ]; then
  echo "❌ Please provide a project name."
  echo "Usage: $0 <project-name>"
  exit 1
fi

echo "πŸš€ Creating DDEV WordPress project: $PROJECT_NAME"

mkdir "$PROJECT_NAME"
cd "$PROJECT_NAME"

ddev config --project-type=wordpress
ddev start

echo "🧩 Installing WordPress..."

ddev wp core download

ddev wp core install \
  --url="https://${PROJECT_NAME}.ddev.site" \
  --title="$PROJECT_NAME" \
  --admin_user=admin \
  --prompt=admin_password \
  [email protected]

echo "βœ… WordPress installed at: https://${PROJECT_NAME}.ddev.site"
ddev launch wp-admin/
  1. Save and exit (press CTRL + X, then Y, then ENTER).

3. Give the Script Execution Permission

Run:

chmod +x create-ddev-wp.sh

This makes the script executable.

4. Now make it an alias

Steps to Create an Alias

Step 1: Move the Script to a Permanent Location

It’s best to store the script in a directory that’s always accessible, like /usr/local/bin/ (for system-wide access) or ~/.local/bin/ (for your user only).

Move the script to ~/.local/bin/ (if it doesn’t exist, create it):

mkdir -p ~/.local/bin
mv create-ddev-wp.sh ~/.local/bin/create-ddev-wp
chmod +x ~/.local/bin/create-ddev-wp

Now, the script is globally accessible as create-ddev-wp.

Step 2: Add an Alias to Your Shell Configuration

Edit your shell configuration file:

  • For Bash (.bashrc):
nano ~/.bashrc

Add this line at the bottom to make It Work with “new site” as One Command

If you want to make create new site myproject work exactly like that, you need to define a function instead of an alias.

Edit your shell config file (.bashrc or .zshrc) and add:

function create() {
    if [[ $1 == "new" && $2 == "site" ]]; then
        ~/.local/bin/create-ddev-wp "$3"
    else
        echo "Usage: create new site <project-name>"
    fi
}

Then reload:

source ~/.bashrc # or source ~/.zshrc

Now, you can run:

create new site myproject

And it will execute the script with myproject as the project name! πŸš€