Bash Script To Create WordPress Site

A few months ago, I wrote a bash script that creates a database with a few simple prompts. Even though I knew the database commands from memory, it was still more convenient to only input the necessary data.

I decided to build out a similar workflow for creating WordPress sites. At the core of this script is the WordPress Command Line Interface. Installing on Ubuntu was a trivial matter, very easy to set up. It should be the same for MacOS X. Windows developers, however, may encounter trouble setting up the command.


Basic WordPress Site

Below is the bash script I use to set up the WordPress site. This script assumes that you’ve already created the database and have changed into the direcotry

#!/bin/bash

#get the site name
read -p "Site name (no spaces): " name

#get the site path
read -p "Site path (no spaces): " path

#get the database creator with default
read -p "Admin [admin]: " user
user=${user:-admin}

#get the database creator with default
read -p "Admin [admin]: " user
user=${user:-admin}

#get the database password with default
read -p "Password [temp]: " pass
pass=${pass:-temp}

#create new site
wp core download
wp config create --dbname=$path --dbuser=$user --dbpass=$pass
wp core install --url=localhost/$path --title=$name --admin_user=$user --admin_password=$pass --admin_email=$email

#confirmation message
echo "Created WordPress site: $name"