Script to setup WPEngine site locally on VVV. This takes a backup.zip of a WPEngine install and creates a local VVV install. It extracts wp-content and database from the backup and installs locally. It also points the local install to a git repo of your choosing. Uses composer to handle dependencies.
1. download backup of live WPEngine site
2. change directory to vagrant/www
3. git clone git@github.com:pie/vvv-init-wpengine.git "sitename"
4. run search and replace on "sitename" directory (replace site-name with wpengine install name)
5. move WPEngine backup.zip into "sitename" directory (DO NOT RENAME IT)
6. run this script (./wpengine-init.sh) and follow the instructions (site name = wpengine install name = "sitename" directory)
7. before vagrant provision is run script notifies you to update the composer.json, make any required changes
8. either provision now or later and after it has run check all loaded properly
#!/bin/bash
# Setup local wordpress install from wpengine live site
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
# Grab site name
echo -e "${RED}Enter project name (this should match your wpengine install)${NC}"
read site_name
# Multisite?
echo -e "${RED}Is this a multisite? [yes/no]${NC}"
read multisite
# Check if directory exists
if [ -d "$site_name" ]; then
echo -e "${RED}Directory already exists! (www/$site_name)${NC}"
echo -e "${RED}Continuing will overwrite www/$site_name with your WP Engine backup!${NC}"
echo -e "${RED}Continue? [y/n]${NC}"
read continue
if [ "n" = "$continue" ]; then
echo -e "${GREEN}Exiting...${NC}"
exit
fi
fi
# Grab repository URL
echo -e "${RED}Enter repository URL${NC}"
read repo_url
# Create directory for local install
echo -e "${GREEN}Setting up local files${NC}"
# Check if new local install
if [ "y" != "$continue" ]; then
# New local setup
echo -e "${GREEN}Pulling down vvv-init${NC}"
git clone git@github.com:pie/vvv-init-wpengine.git $site_name
# Remove all git files
echo -e "${GREEN}Removing .git${NC}"
rm -rf $site_name/.git
# Run a search and replace on init script
echo -e "${GREEN}Search and replace to match your site name${NC}"
perl -pi -w -e "s/site-name/$site_name/g;" $site_name/*
# Update for multisite
if [ "yes" = "$multisite" ]; then
perl -pi -w -e "s/MULTISITE=false/MULTISITE=true/g;" $site_name/vvv-init.sh
fi
else
# Existing local setup
echo -e "${GREEN}Pulling down $site_name${NC}"
cd $site_name
git pull
cd ..
fi
# Extract wpengine files
echo -e "${RED}Move WP Engine backup .zip into www/$site_name${NC}"
echo -e "${RED}Press return to continue${NC}"
read undefined
echo -e "${GREEN}Extracting WPEngine file${NC}"
mkdir $site_name/public_html
mkdir $site_name/public_html/wp
unzip -o $site_name/site-archive-$site_name-*.zip -d $site_name/public_html/wp
# One more go to move it, exit if .zip not found
if [ 0 != $? ]; then
echo -e "${RED}Move WP Engine backup .zip into www/$site_name${NC}"
echo -e "${RED}Press return to continue${NC}"
read undefined
unzip -o $site_name/site-archive-$site_name-*.zip -d $site_name/public_html/wp
if [ 0 != $? ]; then
echo -e "${RED}No .zip found for $site_name, exiting...${NC}"
exit
fi
fi
# Add backup file to .gitignore
echo -e "${GREEN}Adding backup .zip to .gitignore${NC}"
echo "site-archive-$site_name-*.zip" >> $site_name/.gitignore
# Cleanup and move required wordpress files to local install
echo -e "${GREEN}Cleaning up files and removing core (handled by composer)${NC}"
rm -f $site_name/public_html/wp/wp-config.php
mv $site_name/public_html/wp/wp-content $site_name/public_html/
mv $site_name/public_html/wp-content/mysql.sql $site_name/$site_name.sql
rm -rf $site_name/public_html/wp
echo -e "${GREEN}Removing WP Engine MU plugins${NC}"
rm -rf $site_name/public_html/wp-content/mu-plugins/force-strong-passwords
rm -rf $site_name/public_html/wp-content/mu-plugins/wpengine-common
rm -f $site_name/public_html/wp-content/mu-plugins/mu-plugin.php
rm -f $site_name/public_html/wp-content/mu-plugins/slt-force-strong-passwords.php
rm -f $site_name/public_html/wp-content/mu-plugins/stop-long-comments.php
# Set up repository and do initial push
echo -e "${GREEN}Setting up Repository${NC}"
cd $site_name
if [ "y" != "$continue" ]; then
# Initialise new repository, commit and push
echo -e "${GREEN}Creating new repository and pushing to $repo_url${NC}"
git init
git add .
git commit -am "initial commit"
git remote add origin $repo_url
git push -u origin master
else
# Commit changes to repository and push
echo -e "${GREEN}Committing changes and pushing to $repo_url${NC}"
git add .
git commit -am "Re-install of $site_name from backup"
git push
fi
cd ..
# Reload vagrant to get new site installed
echo -e "${GREEN}A provision is needed to finish your site locally${NC}"
echo -e "${GREEN}Now's the time to edit composer.json to suit your needs!${NC}"
echo -e "${RED}Would you like to run a provision now (password maybe required)? [y/n]${NC}"
read provision
if [ "y" = "$provision" ]; then
vagrant reload --provision
else
echo -e "${GREEN}Exiting...${NC}"
exit
fi