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
- Open a terminal.
- Create a new file:
nano create-ddev-wp.sh
- 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/
- Save and exit (press
CTRL + X, thenY, thenENTER).
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! π