Skip to content

Instantly share code, notes, and snippets.

@skara
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skara/9569323a2db0bf57d38f to your computer and use it in GitHub Desktop.
Save skara/9569323a2db0bf57d38f to your computer and use it in GitHub Desktop.
Script to create new WordPress site using wp-cli (http://wp-cli.github.com), based on http://www.wpmayor.com/introduction-wp-cli
#!/bin/sh
# Set defaults
admin="InsertADMINhere"
mail="insert@example.org"
# password="REALLY?" # REALLY WANT TO SET A PASSWORD ?
# [install dir] use actual directoryx
dd=$(pwd)
# [WordPress URL]
url=$(printf '%q\n' "${PWD##*/}")
# [Website Title]
title="EXAMPLE"
#####
# Used to create database
#####
# [db prefix] generate random database prefix, 6 alphanum
dbpre=$(< /dev/urandom tr -dc [:alnum:] | head -c6)
# [name of database] use username & _ & dbpre (USER_z5y3x1)
db=$(whoami)"_"$dbpre
### Prompting for some variables
read -p "In which folder should we install WordPress [$dd]: " newdir
newdir=${newdir:-$dd}
read -p "Name of the database [$db]: " dbname
dbname=${dbname:-$db}
read -p "Database prefix [$dbpre]: " dbprefix
dbprefix=${dbprefix:-$dbpre}"_"
read -p "What is the URL of this WordPress site [$url]: " wpurl
wpurl=${wpurl:-$url}
read -p "What is the title of this WordPress site [$title]: " wptitle
wptitle=${wptitle:-$title}
read -p "What admin username would you like to use [$admin]: " adminuser
adminuser=${adminuser:-$admin}
read -p "What's your email [$mail]: " adminemail
adminemail=${adminemail:-$mail}
read -s -p "Which password would you like [ -EMPTY DEFAULT- ]: " adminpass
adminpass=${adminpass:-$password}
#######################
# Create DB if needed - remove if not wanted
# needs ~/.my.cnf for password and username
mysql -e "create database $dbname"
### Create a subfolder if needed:
if [ ! -d $newdir ]; then
mkdir $newdir
fi
cd $newdir
### Install WordPress and create the wp-config.php file...
# We add the --force so WP CLI doesn't get confused by some other wp version that might be running on this domain.
wp core download --force
wp core config --dbname=$dbname --dbprefix=$dbprefix
#finish the last step of a usual WordPress installation
wp core install --url=$wpurl --title="$wptitle" --admin_user=$adminuser --admin_email=$adminemail --admin_password=$adminpass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment