Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
WordPress Installation with the Roots/Sage Framework and VirtualHost Creation
#!/bin/bash -e
# WordPress Installation and VirtualHost Creation
# Description: Installs a WordPress website in the ~/Sites folder, creates a homepage,
# cleans up the WP install a bit, deletes the akismet and hello dolly plugins, creates the permalinks,
# clones the roots/sage theme framework to the theme folder, deletes all the other WP default themes,
# installs/runs npm and bower and runs gulp to create the initial assets, adds a custom gitignore file
# to /wp-content, installs the roots/soil plugin, creates a git repo in wp-content, saves the WordPress
# credentials to a local file and the password to your clipboard. Then it creates a virtualhost for you. Voila!
# Author: William Donahoe - @ethicka
# Based off of
# Dependencies: wp-cli,, apg, git, npm, node, gulp, bower
# Homebrew installation: brew install apg git node gulp bower
# Command: wp-start [site-name-slug]
# set variables
echo "Beginning WordPress Installation..."
# Get the name of the folder
read -e -p "Folder Name: " slug
# Set the site path
sitepath=~/Sites/$slug # you could change this to wherever you install your sites
if [ ! -d "$sitepath" ]; then
mkdir $sitepath
cd $sitepath
echo "The site path is $sitepath"
# accept user input for the database name
echo -n "Database Name: "
read dbname
# accept the name of our website
echo -n "Site Name: "
read sitename
# add a simple yes/no confirmation before we proceed
echo -n "Run Install? [y/n] "
read run
# if the user didn't say no, then go ahead an install
if [ "$run" == n ] ; then
# download the WordPress core files
wp core download
# create the wp-config file with our standard setup
wp core config --dbname=$dbname --dbuser=$DBUSER --dbpass=$DBPASSWORD --extra-php <<PHP
define( 'WP_DEBUG', true );
define( 'DISALLOW_FILE_EDIT', true );
# generate password using apg
password=$(apg -n 1 -m 12 -M SNC)
# copy password to clipboard
echo $password | pbcopy
# create database, and install WordPress
wp db create
wp core install --url="http://$slug" --title="$sitename" --admin_user="$WPUSER" --admin_password="$password" --admin_email="$ADMIN_EMAIL"
# discourage search engines
wp option update blog_public 0
# delete sample page, and create homepage
wp post delete $(wp post list --post_type=page --posts_per_page=1 --post_status=publish --pagename="sample-page" --field=ID --format=ids)
wp post create --post_type=page --post_title=Home --post_status=publish --post_author=$(wp user get $WPUSER --field=ID --format=ids)
# delete readme and license
rm license.txt
rm readme.html
# set homepage as front page
wp option update show_on_front 'page'
# set homepage to be the new page
wp option update page_on_front $(wp post list --post_type=page --post_status=publish --posts_per_page=1 --pagename=home --field=ID --format=ids)
# set pretty urls
wp rewrite structure '/%postname%/' --hard
wp rewrite flush --hard
# delete akismet and hello dolly
wp plugin delete akismet
wp plugin delete hello
# you could also *install* some plugins here you use all the time, too.
# install roots sage theme and remove .git folder
cd $(wp theme path)
git clone --depth=1 $slug
rm -rf $slug/.git
wp theme activate $slug
# delete other themes
wp theme delete twentyfourteen
wp theme delete twentyfifteen
wp theme delete twentysixteen
# install npm and bower and run gulp
cd $(wp theme path)
cd $slug
echo "Installing Node Modules..."
npm install
echo "Installing Bower..."
bower install
echo "Running Gulp..."
# update manifest.json
cd $sitepath/wp-content/themes/$slug/assets
replace "" "http://$slug" -- manifest.json
# Create a .gitignore and start a git in the wp-content folder
cd $sitepath/wp-content
# .gitignore
echo "# Ignore themes except ours
# Ignore all plugins
# WordPress
# Files
" > .gitignore
echo "# $sitename" >
# first git commit
git init
git add .
git commit -m "Initial commit"
# install roots soil plugin and commit
cd $sitepath
cd wp-content
git submodule add -f plugins/soil
wp plugin activate soil
git add .
git commit -m "Soil plugin"
# site credentials
echo "WordPress Username: $WPUSER" > site_credentials
echo "WordPress Password: $password" >> site_credentials
# finalize
echo ""
echo "###"
echo "Installation is complete."
echo "Username: $WPUSER"
echo "Password: $password"
echo "###"
echo ""
# set up the virtualhost $slug
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment