Created
December 13, 2018 22:14
-
-
Save bitsnaps/cce9cea66efa3378799ab48c1c6c2f34 to your computer and use it in GitHub Desktop.
Wordpress CLI tool (wp-cli) script installation automation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# Script tested on MacOS 10.14 with Wordpress 5.0 | |
# Original article at: | |
# https://deliciousbrains.com/automating-local-wordpress-site-setup-scripts/ | |
# Usage: | |
# ./install-wp.sh MyNewSite | |
# Path to your custom themes/plugins | |
#PROJECT_PATH="/Users/$USER/Projects" | |
PROJECT_PATH="/Applications/XAMPP/xamppfiles/htdocs/wp/Projects" | |
# Path to your WordPress installs | |
#SITE_PATH="/Users/$USER/Sites" | |
SITE_PATH="/Applications/XAMPP/xamppfiles/htdocs/wp/Sites" | |
# Path to your custom Scripts folder | |
#SCRIPT_PATH="/Users/$USER/Scripts" | |
SCRIPT_PATH="/Applications/XAMPP/xamppfiles/htdocs/wp/Scripts" | |
# Base URL (sites will be setup as subdirectories) | |
BASE_URL="http://localhost/wp/Sites" | |
# Database information | |
DB_USER="root" | |
DB_PASS="" | |
DB_HOST="127.0.0.1" | |
# WP Info | |
WP_EMAIL="YOU@YOURDOMAIN.com" | |
ADMIN_USER="admin" | |
ADMIN_PWD="master" | |
# Installation Script | |
if [ $# -ne 1 ]; then | |
echo $0: usage: Destination Name | |
exit 1 | |
fi | |
DEST=$1 | |
# Create the database. | |
DB_NAME=$(echo $DEST | sed -e 's/-/_/g') | |
echo "Creating database $DB_NAME..." | |
mysql -u$DB_USER -p$DB_PASS -e"CREATE DATABASE $DB_NAME" | |
# some time slot | |
sleep 1 | |
# Download WP Core. | |
echo "Downloading core archive..." | |
wp core download --path=$SITE_PATH/$DEST | |
# not tested | |
#wp core download --path=/Applications/XAMPP/xamppfiles/htdocs/wordpress-4.9.8.zip | |
# some time slot | |
sleep 1 | |
# Generate the wp-config.php file | |
echo "Generating config settings: (DB_NAME: $DB_NAME, DB_USER: $DB_USER, DB_PASS: $DB_PASS)" | |
wp core config --path=$SITE_PATH/$DEST --dbname=$DB_NAME --dbuser=$DB_USER --dbpass=$DB_PASS --extra-php <<PHP | |
define('WP_DEBUG', true); | |
define('WP_DEBUG_LOG', true); | |
define('WP_DEBUG_DISPLAY', true); | |
define('WP_MEMORY_LIMIT', '256M'); | |
PHP | |
# some time slot | |
sleep 1 | |
# fix issue with connection (replace 'localhost' with '127.0.0.1') | |
echo "Fix wp-config.php file..." | |
sed -e 's/localhost/127.0.0.1/g' "$SITE_PATH/$DEST/wp-config.php" > "$SITE_PATH/$DEST/wp-config.bak" | |
rm "$SITE_PATH/$DEST/wp-config.php" | |
mv "$SITE_PATH/$DEST/wp-config.bak" "$SITE_PATH/$DEST/wp-config.php" | |
# Install the WordPress database. | |
echo "Install Wordpress database for: $DEST" | |
wp core install --path=$SITE_PATH/$DEST --url=$BASE_URL/$DEST --title=$DEST --admin_user=$ADMIN_USER --admin_password=$ADMIN_PWD --admin_email=$WP_EMAIL | |
# some time slot | |
sleep 1 | |
# Installing plugins... | |
wp plugin install --path=$SITE_PATH/$DEST all-in-one-wp-migration --activate | |
wp plugin delete --path=$SITE_PATH/$DEST hello | |
wp plugin delete --path=$SITE_PATH/$DEST akismet | |
wp theme install --path=$SITE_PATH/$DEST winsome --activate | |
# Delete all pages | |
#wp post --path=$SITE_PATH/$DEST delete $(wp post list --post_type='page' --format=ids --path=$SITE_PATH/$DEST ) | |
wp post delete 1 --path=$SITE_PATH/$DEST # delete sample post | |
wp post delete 2 --path=$SITE_PATH/$DEST # delete sample page | |
# Delete all posts in the trash | |
#wp post --path=$SITE_PATH/$DEST delete $(wp post list --post_status=trash --format=ids --path=$SITE_PATH/$DEST ) | |
# Install Languages Pack | |
wp language core install fr_FR --path=$SITE_PATH/$DEST | |
#wp language core activate fr_FR --path=$SITE_PATH/$DEST # deprecated use switch-language instead: | |
wp site switch-language fr_FR --path=$SITE_PATH/$DEST | |
echo "Site available at: $BASE_URL/$DEST" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment