Skip to content

Instantly share code, notes, and snippets.

@obstschale
Last active July 19, 2017 15:13
Show Gist options
  • Save obstschale/e34e41620bdddb913a8f0007129fc821 to your computer and use it in GitHub Desktop.
Save obstschale/e34e41620bdddb913a8f0007129fc821 to your computer and use it in GitHub Desktop.
Bash script for setting up a new WordPress site (Laravel Valet runs in the background)
#!/bin/bash
# =========================================
# Create new WordPress Site with 1 command
#
# press <name> <dbname>
#
# name: name of the folder, website, url
# dbname: database name, which will be created and used by WordPress
#
# This script creates a new WordPress instance.
# It uses WP CLI and Laravel Valet.
#
# Steps:
# * Create WP directory
# * Create database
# * Download latest WordPress
# * Configure WordPress with default values
# * Opens new site in default browser
#
# The script is meant to be used in combination with Laravel Valet. Valet watches the current
# directory and each new dir will be automatically a new site with its own URL: <dir>.dev
#
# See: https://laravel.com/docs/5.4/valet
# =========================================
# Check if all necessary parameters are given
if [[ ! $1 || ! $2 ]]; then
output='Please provide a name'
if [[ ! $2 ]]; then
output="$output and a database name"
fi
echo $output
echo 'Usage: press <name> <dbname>'
exit;
fi
# Create new Directory and CD into it
mkdir $1
cd $1
# Use WP CLI to download latest WordPress and configure new site
wp core download
wp core config --dbname=$2 --dbuser=root
# Create new database with given name
echo "Create database $2"
mysql -u root -e "create database $2" 2>&1
# Install new site with given name and default credentials
wp core install --url=$1.dev --title=$1 --admin_user=admin --admin_password=password [email protected] --skip-email
# Open new site in default browser
open http://$1.dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment