This post was last updated on

Load Balanced WordPress

We run two load balanced servers that host our organisation’s public websites and we recently switched to WordPress having used a static site before this. Whilst WordPress offers significant gains in flexibility and functionality, we now have to write changes to two separate WordPress installations when updating a site – which is a bit tiresome and tedious. (This is on top of ftp’ing files to two servers, which is what we did before).

Oh yeah, did I mention we had 5 websites? So that’s 10 installation’s of WordPress to manage. Now were not big enough to have the resources to be able to do clever stuff with database clustering, so each server currently hosts the files and the database for 5 websites. WordPress runs on top of apache & PHP5 that sits on a RedHat distro of linux.

So how to make it simple? Well, all you need is a couple of easy to run scripts that make use of mysqldump, rsync, ssh and the mysql import function (ok, it doesn’t sound that easy, but it really is).

The basic workflow is to create a dump of the WordPress databases into a local folder on the master server (we treat one as the master and one as the slave, but they are almost identical and serve traffic equally!) and then use rsync to fire them over to a directory on the slave server, which is then loaded into the MySQL database.

A script on the slave is run to first back up the databases using a dump (actually it’s pretty much the same script as the first part on the master) – this makes sure we have something to role back to if it doesn’t work right, we can also fire it off to a backup location too. We then import the newly arrived sql dump files (sent from the master server) and voila – job done.

We can also use the first part of the above process to backup your database files automatically, see here. You can load this as a crontab to make sure that the process happens as frequently as you want it to to ensure you have a safe, up to date copy from which you cn restore should the need arise.

For the Import script which is used to upload the sql file(s) to the database, then see here.

All that’s left is to update the process with a call to update the website’s files and folders and it will be an effortless one touch process. Well, nearly!

/end of post


Written by

Last updated

First published

in

Tags:

Comments

Leave a Reply

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