WP-CLI WordPress Provision Script for New Installations

I have previously have demonstrated how WP-CLI can be used to batch install plugins. If you are on Cloudways or Siteground then you have WP-CLI access and get easily provision new installations. If you are running wplib box, VVV or something else Vagrant based you likely have WP-CLI as well.

Automatically install the following on your local install or host if they support WP-CLI

  • Plugins from wordpress.org repository
  • Premium plugins from cloud storage
  • Theme from wp.org repository or cloud storage

WP-CLI WordPress Provision Script for New Installations

Create an empty file for the WordPress provisioning script

nano wpsetup.sh

Paste the script and adjust the plugin and theme values

#!/usr/bin/env bash
# Purpose: WordPress provisioning script
# Source: https://guides.wp-bullet.com
# Author: Mike

# Verify WP-CLI is installed
if hash wp 2>/dev/null; then
    echo "wp-cli not installed"

# define WordPress path

# array containing plugin list to install from wp.org repository, separate plugin slugs with spaces
PLUGINS=(autoptimize wordpress-seo worker updraftplus aceide wp-file-manager)

# plugin list of remote urls like paid plugins stored on dropbox, separate urls with spaces
PLUGINSREMOTE=(https://github.com/wp-plugins/adminer/archive/master.zip http://exampleurl)

# plugins to remove
PLUGINSREMOVE=(akismet hello)

# choose theme to install from repository or replace with URL

# install theme
wp theme install $THEME --activate --path=$WPPATH --skip-plugins --skip-themes --allow-root

# install plugins
wp plugin install ${PLUGINS[@]} ${PLUGINSREMOTE[@]} --activate --path=$WPPATH --skip-plugins --skip-themes --allow-root

# delete plugins
wp plugin deactivate ${PLUGINSREMOVE[@]} --uninstall --path=$WPPATH --skip-plugins --skip-themes --allow-root
wp plugin delete ${PLUGINSREMOVE[@]} --path=$WPPATH --skip-plugins --skip-themes --allow-root

Ctrl+X, Y and Enter to Save and Exit.

If you ran the script as the root user be sure to reset permissions

sudo chown -R www-data:www-data /var/www/
sudo find /var/www/ -type f -exec chmod 644 {} +
sudo find /var/www/ -type d -exec chmod 755 {} +

Running the script is as easy as using this command

bash wpsetup.sh

This should make life easier 🙂