AUTOMATED MULTIPLE OLDER WORDPRESS VERSION SETUP

Bob Ong
Bob Ong
Jul 26, 2017 · 3 min read

For plugin development, you need to maintain a number of older 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

https://wordpress.org/wordpress-4.7.1.tar.gz
https://wordpress.org/wordpress-4.7.2.tar.gz
https://wordpress.org/wordpress-4.7.3.tar.gz
https://wordpress.org/wordpress-4.7.4.tar.gz
https://wordpress.org/wordpress-4.7.5.tar.gz
https://wordpress.org/wordpress-4.8.tar.gz

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

#!/bin/bash
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[@]}”
do
curl -O https://wordpress.org/wordpress-$i.tar.gz
done

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 () {
MAINDB=$1
ROOTPASSWD=$3
mysql -u$2 -p${ROOTPASSWD} -e “CREATE DATABASE IF NOT EXISTS ${MAINDB} /*\!40100 DEFAULT CHARACTER SET utf8 */;”
}

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.
driver.get(‘http://www.google.com/xhtml');

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.

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.

Bob Ong

Written by

Bob Ong

I live in my mom’s basement and make Wordpress sites. No system is safe! Audacity triumphs!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade