Automated Multiple WordPress Version Setup

Automated WordPress Setup
Automated WordPress Setup

For plugin development, you need to maintain a number of WordPress versions for testing. I need to at least install 5 version of WordPress if I start with 4.7.
The setup of a normal setup is:
1. Create database, user and password
2. Download WordPress, unzip, move to expanded folder
3. Copy and rename wp-config-sample.php to wp-config.php and add-in the credentials
4. WordPress core is updated automatically, you need to remove auto update feature by adding a line in wp-config.php

The Problem
Repeating the task everything you need a clean testing environment can be tedious.

Of course, there is WP-CLI the command line interface for WordPress but many web-hosts do not have WP-CLI installed, sometimes they have a strip down version, others they simply don’t work. If your host is provided with ssh, we could write a script for these, if not a good option will be to create all the files and then send it up by FTP.

The Solutions
For now, we will work with SSH. The solution will consist of 2 parts, a script to install the files and setup the database and another to open up the browser and complete the setups.

Part 1: The Server Script
We need a script that can be executed on the server that will download WordPress version 4.7.1 – 4.8. Since the archive version URL naming is quite standard

We can easily use a bash script to loop through and grab them with wget or curl.

arr=( "4.8" "4.7.5" "4.7.4" "4.7.3" "4.7.2" "4.7.1" )
## now loop through the above array
for i in "${arr[@]}"
curl -O$i.tar.gz

To complete the code, we need to unzip, rename the folder, add and insert our credentials to the wp-config.php
I modified a code by bgallagh3r.

We still need to add the code for creating the database. Since most web-host do not allow the use of root for MySQL, you need a user id that has the privilege of creating databases. If not, you can only create it manually through your web interface.

function createdatabase () {

During my research phase I came across some solution that generates different username and password for each site, but I prefer to keep it simple with just one username and password for all sites. I anticipate that these sites will be torn down once the testing is done.

Part 2: The Client-Side Script
We need a script to open up the browser and input, select and click through the steps. I choose Python and selenium. You can find out more here

First, download Python bindings for Selenium.
sudo pip install selenium

We need ChromeDriver that can be download here and read the ChromeDrive documentation here

from selenium import webdriver
driver = webdriver.Chrome('/path/to/chromedriver') # Optional argument, if not specified will search path.

Test and make sure that the path to ChromeDrive is correct and Selenium is installed correctly. This should launch google on a new browser window.
Now let’s work on our script.

Automated WordPress Setup Part 2
Automated WordPress Setup Part 2

Now let see how the whole thing runs on the client side.

See how easy it is to automate everything with a few lines of code.

Leave a Reply

Your email address will not be published. Required fields are marked *