Skip to content

Instantly share code, notes, and snippets.

@n8finch
Last active August 5, 2025 19:31
Show Gist options
  • Save n8finch/0ceddc0f29695d14aad33818fed6e9ef to your computer and use it in GitHub Desktop.
Save n8finch/0ceddc0f29695d14aad33818fed6e9ef to your computer and use it in GitHub Desktop.
#!/bin/bash
# Credit: https://gist.github.com/bacoords/7a3d8eba7ec36adbb3d28ae8e328bf61
# Credit to https://github.com/rizaardiyanto1412/rizaardiyanto1412/blob/main/installwp.sh
# Check if WP-CLI is installed
if ! command -v wp &> /dev/null; then
echo "WP-CLI is not installed. Please install it first."
exit 1
fi
# Check for MySQL client
MYSQL_CMD="mysql"
if ! command -v mysql &> /dev/null; then
echo "MySQL client not found. Please ensure DBngin is installed and running, or install MySQL client."
exit 1
fi
# Check if --multi flag is passed
MULTISITE=false
for arg in "$@"; do
if [ "$arg" == "--multi" ]; then
MULTISITE=true
fi
done
# Prompt for new site folder
read -p "Enter the new site folder name: " SITE_NAME
# Validate folder name input
if [ -z "$SITE_NAME" ]; then
echo "Folder name cannot be empty. Exiting."
exit 1
fi
# Set variables
DB_USER="root" # DBngin typically uses root without password by default
DB_PASSWORD="" # Empty password as per DBngin default
DB_HOST="127.0.0.1"
WP_TITLE="My $SITE_NAME Site"
WP_ADMIN_USER="asdf"
WP_ADMIN_PASSWORD="asdf"
WP_ADMIN_EMAIL="[email protected]"
SITE_SLUG=$(echo "$SITE_NAME" | tr '[:upper:]' '[:lower:]' | tr ' ' '-')
SITE_DB_NAME=$(echo "$SITE_NAME" | tr '[:upper:]' '[:lower:]' | tr ' ' '_')
# Create new site directory
mkdir "$HOME/Herd/$SITE_SLUG" && cd "$HOME/Herd/$SITE_SLUG" || exit
WP_URL="$SITE_SLUG.test"
DB_NAME="$SITE_DB_NAME"
echo "Using the following values:"
echo "WordPress URL: $WP_URL"
echo "Database Name: $DB_NAME"
# Create database
"$MYSQL_CMD" -h"$DB_HOST" -u"$DB_USER" -e "CREATE DATABASE IF NOT EXISTS \`$DB_NAME\`;"
if [ $? -ne 0 ]; then
echo "Failed to create database. Please check your DBngin setup and ensure MySQL is running."
exit 1
fi
# Download WordPress core
wp core download
# Create wp-config.php
wp config create --dbname="$DB_NAME" --dbuser="$DB_USER" --dbpass="$DB_PASSWORD" --dbhost="$DB_HOST"
# Install WordPress (Single or Multisite)
if [ "$MULTISITE" = true ]; then
echo "Installing as a subdomain-based multisite..."
wp core install --url="$WP_URL" --title="$WP_TITLE" --admin_user="$WP_ADMIN_USER" --admin_password="$WP_ADMIN_PASSWORD" --admin_email="$WP_ADMIN_EMAIL"
wp core multisite-convert --title="$WP_TITLE" --subdomains
else
echo "Installing as a single site..."
wp core install --url="$WP_URL" --title="$WP_TITLE" --admin_user="$WP_ADMIN_USER" --admin_password="$WP_ADMIN_PASSWORD" --admin_email="$WP_ADMIN_EMAIL"
fi
echo "WordPress installation complete!"
echo "Site URL: $WP_URL"
echo "Database Name: $DB_NAME"
echo "Admin username: $WP_ADMIN_USER"
echo "Admin password: $WP_ADMIN_PASSWORD"
echo "Remember to change the admin password after logging in!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment