Skip to content

Instantly share code, notes, and snippets.

@NorbertFeria
Created August 22, 2024 06:00
Show Gist options
  • Select an option

  • Save NorbertFeria/25ad0182c6cfdf8b6adeec90fd15a8c1 to your computer and use it in GitHub Desktop.

Select an option

Save NorbertFeria/25ad0182c6cfdf8b6adeec90fd15a8c1 to your computer and use it in GitHub Desktop.
Quickly install wordpress from the command line using WP-CLI
#!/bin/bash
echo "Usage: $0 <foldername> <dbname> <dbuser> <dbpass> <url> <title> <adminuser> <adminpass> <adminemail>"
echo "Or you can enter the details when prompted."
# Check if WP-CLI is installed
if ! which wp > /dev/null; then
echo "WP-CLI is not installed. Please install WP-CLI before running this script."
exit 1
fi
# Use parameters if provided, otherwise prompt for input
foldername=${1:-$(read -p "Enter folder name: " tmp && echo $tmp)}
dbname=${2:-$(read -p "Enter database name: " tmp && echo $tmp)}
dbuser=${3:-$(read -p "Enter database user: " tmp && echo $tmp)}
dbpass=${4:-$(read -sp "Enter database password: " tmp && echo $tmp && echo "")}
url=${5:-$(read -p "Enter site URL: " tmp && echo $tmp)}
title=${6:-$(read -p "Enter site title: " tmp && echo $tmp)}
adminuser=${7:-$(read -p "Enter admin username: " tmp && echo $tmp)}
adminpass=${8:-$(read -sp "Enter admin password: " tmp && echo $tmp && echo "")}
adminemail=${9:-$(read -p "Enter admin email: " tmp && echo $tmp)}
# Create the directory and navigate into it
mkdir -p $foldername
cd $foldername
# Download WordPress core
wp core download
# Create wp-config.php with database details
wp config create --dbname=$dbname --dbuser=$dbuser --dbpass=$dbpass
# Create the database
wp db create
# Install WordPress
wp core install --url=$url --title="$title" --admin_user=$adminuser --admin_password=$adminpass --admin_email=$adminemail
echo "WordPress installation complete."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment