How To Upgrade WordPress Using Subversion

What is Subversion?

Overview
Subversion is a version control system that makes it easy to get the latest version of files, or go back to previous versions. It is used by many different pieces of open source software and has been around since 2000. Subversion is considered the successor to the Concurrent Versions System.

To put it in layman’s terms, say you were running a Subversion server and your resume was checked into it when you first created it. Years later, if you have maintained your Subversion repository, you could go back and look at all of the changes you have ever made to your resume.

This is great for programmers, as we can track changes that we, and other people have made to our code over time, permitting us to revert back to those previous versions. Or if we are running a Subversion repository, we can push out our changes to all those on the web that use our software.

Where to find Subversion
Subversion is available for every major operating system, allowing you to connect to a Subversion server that is running Linux from a client computer running Windows or Mac OS X, and vice-versa.

If you have a server running Debian or Ubuntu, installing the Subversion server is as simple as running apt-get install subversion from the command line (you might have to run the command with the sudo prefix like, sudo apt-get install subversion, if you don’t have root level access).

From a Fedora based Linux distro, you should be able to easily add Subversion server using Yum by typing in yum install subversion.

For other operating systems, I suggest checking out the list of packages on the Tigris website.

As for the client side, Tigris also maintains a list of great clients for nearly every operating system. I have used TortoiseSVN on my Windows computer, and found it very easy to use and understand.

WordPress and Subversion

The folks that manage and distribute WordPress, Automattic Inc., currently run a Subversion server that we can connect to. It allows us to easily download the bleeding edge version of WordPress, the latest stable edition of WordPress, or even older releases of the CMS if we so choose.

In order to use Subversion with your web host, they must have Subversion properly installed on the web host’s server. Most shared hosting environments don’t provide access to Subversion, as it can only be utilized through SSH, a remote command line interface. If you are on a virtual private server (VPS), or your own dedicated server, you should have SSH access, and be able to install Subversion.

Note: Before installing any version of WordPress using Subversion, make sure to create a database for the install and write down the important details to use later in the wp-config.php file.

Automattic has released a small guide on getting WordPress using Subversion on the WordPress.org download using Subversion page, but unfortunately, like most tutorials, it only mentions how to download and install the Trunk version of WordPress.

Note: Another rarely mentioned caveat in using Subversion is that the files that Subversion downloads to your web hosting space are given the user and group of whatever user you happen to be logged in as.

If you are connected via SSH under the user root, then all files that you are downloading will be associated with the user and group of root. This is not a good thing, and should be changed to the user and group relevant to the installation you are doing.

Usually, it will be related to the domain name that you are installing WordPress in. For example, if the domain was subversionrocks.com, the user related to that account might be the first eight characters, or subversi in this case. If you don’t know the user and group that your files should be in, please contact your server administrator.

To change the files, use the chown and chgrp commands when connected to your web host via SSH. If these are confusing, then please make sure you are connected using the correct user account for the domain you are installing WordPress on.

Why Upgrade WordPress with Subversion?

With all of the interesting ways you can upgrade WordPress, why would anyone choose to use Subversion? Well, for me it was a simple choice, as I was managing upwards of fifty blogs at any one time, and so going through the process of upgrading them one at a time through FTP or even Fantastico would have been a long and boring process.

So for me, Subversion made upgrading a quick and simple event rather than a multi-day chore.

Once set up correctly, there is very little you can do that will cause a mistake to be made. I am forever hearing complaints of FTP software not replacing files or only partially transferring files, something that has never occurred to me while using Subversion. Also, I like the security of getting the files right from the source, Automattic’s Subversion repository.

The final thing that drew me to using Subversion when managing my WordPress blogs was that I would get the latest version of Akismet downloaded with it, something that I wasn’t getting when I was using FTP to transfer the files, as I never uploaded the wp-content folder included with newer versions of WordPress for fear of having something break.

Downloading Trunk
Trunk is the latest, bleeding edge of WordPress, updated constantly. Those running the Trunk version of WordPress are mostly testers and code contributors. I wouldn’t recommend that most people run this version as it can contain errors, and result in data loss.

If you want to test out the latest version of WordPress, it is fairly easy.

Connect to your web host using SSH. On Windows, I use a program called Putty. From my Mac, I use Terminal.

Once connected, go to the directory that you want to install the Trunk version of WordPress in. To change directories, type cd directoryname. If you don’t know what directory you are in, type pwd (print working directory).

When you have moved yourself to the directory you want to have the files downloaded to, type:
svn co http://svn.automattic.com/wordpress/trunk .

The period at the end is important, as it tells Subversion that you want the files to go “here”. Press Enter/Return, and it should begin to download the Trunk version of WordPress to your current folder.

Now you just need to create and edit the wp-config.php file with the correct database information and WordPress is ready to install.

Using your favorite web browser, go to where you installed WordPress, and it should run you through the normal quick install to name your blog, and provide an e-mail address.

Once that is complete, you have installed the very latest version of WordPress.

Upgrading: Over the course of days, weeks, months and even years, the WordPress trunk will continue to change. To upgrade to the latest version, you only need to type svn up from the SSH command line while in the folder where WordPress is installed.

Downloading Latest Stable Version for a New Blog
The Stable version of WordPress is as its name implies: stable. It is the final packaged release that Automattic and the WordPress development team have released to the world. It is given a set version number and can be found on the download page in a packaged form. Usually, they have most of the bugs worked out and new features finalized. The stable versions are considered ready for mass consumption, and you shouldn’t experience any major glitches or data loss from the stable releases.

To find out what the latest version is, you only need to look at the download section of WordPress.org, or jump over to WordPress Trac. Under the tags section, you can easily see which version is the newest by scrolling to the bottom.

Once you have written the version number down and created the database you are going to use, connect to your web host using SSH.

Once connected, go to the directory that you want to install the latest stable version of WordPress.

When you have moved yourself to the directory you want to have the files downloaded to, type:
svn co http://svn.automattic.com/wordpress/tags/xxx . – Replace the xxx at the end with the latest version number.

For example, WordPress 2.6 is currently the latest version, so we would enter:
svn co http://svn.automattic.com/wordpress/tags/2.6 .

And again, the period at the end is important.

From here, it is the same as the instructions for installing Trunk. You need to edit the wp-config.php file, and then using your web browser, go to the site, and go through the installation process.

Switching an Established Blog to Subversion
So this is the first time you have heard about Subversion being used to quickly and easily upgrade your blog, but you’ve been blogging for months. How can you switch your established blog to use Subversion?

Well, if you tried to run any of the commands above, you were probably met with errors letting you know there were already files in the way, and so Subversion couldn’t do its magic, but there is a way to move your blog to using Subversion.

First, upgrade your current blog using FTP, or whatever other method you choose to the latest stable version of WordPress.

Then, log in using SSH, and browse to your current blog. Go up one folder using the command cd .. in the terminal window.

Next, create a directory using mkdir. I usually make a directory called public_html_new.

mkdir public_html_new

Now browse into that directory, and using the instructions above, install the version latest stable version of WordPress using Subversion.

Once that is complete, copy your wp-config.php file from your old blog in the regular public_html folder to the public_html_new folder. This will allow your Subversion controlled blog to access your current blog’s database.

Next copy your wp-content folder from the old public_html folder to the public_html_new folder. This will give your new Subversion controlled blog all of your plugins, images, and themes.

Lastly, rename your public_html folder to public_html_old and then rename your public_html_new folder to just public_html. Check to see if your blog is working, and if so, you are most likely seeing your blog, now being version managed by Subversion.

Switching from One Stable Version to the Next
New versions of WordPress will continue to come out, and when running WordPress off the stable versions, it isn’t as easy as typing in the svn up command that you are able to use when running off of Trunk. You need to tell Subversion to switch from one stable version to another.

You will need to use the Subversion switch command. Simply log into your web host using SSH, and browse to the blog you want to update.

In the command line interface, enter:
svn sw http://svn.automattic.com/tags/xxx with the xxx being the version you want to switch to.

For example, if you were going to be moving from WordPress 2.6 to WordPress 2.7, you would type:
svn sw http://svn.automattic.com/tags/2.7

It should then start downloading all files pertaining to WordPress 2.7.

Once this is complete, browse to the site using your favourite web browser, and you will most likely see an upgrade screen. Click upgrade, and if there aren’t any problems, you will have successfully upgraded your WordPress blog from one stable version to another.

And if you are worried about what the Subversion commands should look like when they are working right, here is a quick video showing both a SVN check out command, and a SVN switch command, as well as their results.


David Peralty, a full time problogger for the last two years, writes about making money online to fund his geek living over on eXtra for Every Publisher.

More Resources

Version Control with Subversion – A Very Detailed Online Book
Updating WordPress with Subversion – From the WordPress Codex
How to Install WordPress using SSH and SVN – Mark Kirby’s Guide


Geeks are Sexy needs YOUR help. Learn more about how YOU can support us here.