Skip to content

Instantly share code, notes, and snippets.

@gilbitron
Forked from polevaultweb/wp-install-core-sub-dir.sh
Last active August 29, 2015 14:25
Show Gist options
  • Save gilbitron/e18286195740535200e2 to your computer and use it in GitHub Desktop.
Save gilbitron/e18286195740535200e2 to your computer and use it in GitHub Desktop.
This script installs WordPress inside a sub directory
#!/bin/bash
# Installation:
# Install the script in one of the folders in your PATH. Make sure it has execute permissions (i.e. chmod +x wp-install-core-sub-dir).
#Usage:
# $ mkdir mysite
# $ cd mysite
# $ wp-install-core-sub-dir
# This is a simple script as an example, it could be improved by accepting parameters etc.
CORE_DIR=wp
DB_NAME=wpclitest
DB_USER=user
DB_PASS=pass
SITE_URL=http://wpclitest.dev/
SITE_TITLE='WordPress CLI Test Site'
SITE_USER=admin
SITE_PASS=password
SITE_EMAIL=your@email.com
# create the dir for the core files
mkdir $CORE_DIR
cd $CORE_DIR
# download WordPress files
wp core download
cd ../
# create the wp-config.php file
wp core config --dbname=$DB_NAME --dbuser=$DB_USER --dbpass=$DB_PASS --path=$CORE_DIR
# create the database
wp db create
# install WordPress (less than 5 mins)
wp core install --url=$SITE_URL --title="$SITE_TITLE" --admin_user=$SITE_USER --admin_password=$SITE_PASS --admin_email=$SITE_EMAIL --path=$CORE_DIR
# Copy (not move) index.php file to root
cp "$CORE_DIR/index.php" ./index.php
# Edit index.php to point to correct path of wp-blog-header.php
sed -i '' "s/\/wp-blog-header/\/$CORE_DIR\/wp-blog-header/g" index.php
# Update the siteurl in the database with sub directory path
wp option update siteurl $(wp option get siteurl)/$CORE_DIR
# Uncomment the below line if you want the config in root
#cp "$CORE_DIR/wp-config.php" ./wp-config.php
echo 'Install finished!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment