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







38 Responses to How To Upgrade WordPress Using Subversion

    • The guide is nowhere as extensive and doesn't cover all the possibilities. Please note that the link to the article you mentioned is already in the text.. (maybe you didn't readit all? :) )

      • It's mentioned in the body of the article that the WordPress guide to setting up WordPress via Subversion is lacking – it only shows you how to install trunk. I agree that the guide that was linked to in the body of the article is lacking especially if you're new to Subversion.

        In looking back I did notice that at the bottom of the article under "More Resources" there is a link to the guide I linked to so I apologize for not seeing that. While the Codex guide may not be as extensive (read have as much text) it is a good guide and there is something to be said for brevity.

  1. This is awesome! Thanks for posting. I will have to go check out SSH and see if I can somehow get this set up. I have been using the trunk on my blog, and not having to reupload stuff would be great!

  2. This is awesome! Thanks for posting. I will have to go check out SSH and see if I can somehow get this set up. I have been using the trunk on my blog, and not having to reupload stuff would be great!

    • The guide is nowhere as extensive and doesn’t cover all the possibilities. Please note that the link to the article you mentioned is already in the text.. (maybe you didn’t readit all? :) )

      • It’s mentioned in the body of the article that the WordPress guide to setting up WordPress via Subversion is lacking – it only shows you how to install trunk. I agree that the guide that was linked to in the body of the article is lacking especially if you’re new to Subversion.

        In looking back I did notice that at the bottom of the article under “More Resources” there is a link to the guide I linked to so I apologize for not seeing that. While the Codex guide may not be as extensive (read have as much text) it is a good guide and there is something to be said for brevity.

  3. Regarding updraing wordpress using subversion, i’m a bit skeptical. This is because, you will have to know about all the pros and cons of using the latest version of wordpress. it might or might not support all the pluggins that you’ve been using for your current version of wordpress.

    • You could say the same about any upgrade system you use to keep your WordPress powered blogs up to date. Subversion doesn’t upgrade things automatically. You have to tell it that you want to upgrade. Just like through most other upgrade paths.

  4. Regarding updraing wordpress using subversion, i'm a bit skeptical. This is because, you will have to know about all the pros and cons of using the latest version of wordpress. it might or might not support all the pluggins that you've been using for your current version of wordpress.

    • You could say the same about any upgrade system you use to keep your WordPress powered blogs up to date. Subversion doesn't upgrade things automatically. You have to tell it that you want to upgrade. Just like through most other upgrade paths.

  5. Okay, here’s what I did, you tell me where I’m going wrong:
    No problem getting svn installed on my SliceHost server.
    I create the “public_html_new” directory; no challenges.
    Made sure I surf the command line to that new directory and check out the trunk by typing exactly the line you state above, only to receive an error that the URL does not exist.
    I check out the SVN page at WordPress.org and it has no “period” that you’re stating is important, so I try the URL with no period.
    It works (and it works with or without the trailing slash).
    The challenge, however is that it downloads a copy of WordPress and puts it into a directory called “trunk”!
    And I did the same with the /tags/2.6/ and it created a directory called “/2.6/” (imagine that!)

    So, what to do? Now I should move all up one directory, which shouldn’t be a problem, but I’m concerned when I do an update that the files will get put in to a folder one directory below “public_html”, and having to move them all manually kind of defeats the purpose.

    Otherwise I really am excited to learn about this. Thanks for any info you can share on this!

    • See, that period at the end of the command, that’s why it is important. Without it, you get the issue you are having with it creating its own directories inside of where you already are.

      Also, I have used that exact command on over 40 blogs, so the error you received, I can’t replicate. The URL does exist. Did you put a space between the end of the url and the period?

  6. Okay, here's what I did, you tell me where I'm going wrong:

    No problem getting svn installed on my SliceHost server.

    I create the "public_html_new" directory; no challenges.

    Made sure I surf the command line to that new directory and check out the trunk by typing exactly the line you state above, only to receive an error that the URL does not exist.

    I check out the SVN page at WordPress.org and it has no "period" that you're stating is important, so I try the URL with no period.

    It works (and it works with or without the trailing slash).

    The challenge, however is that it downloads a copy of WordPress and puts it into a directory called "trunk"!

    And I did the same with the /tags/2.6/ and it created a directory called "/2.6/" (imagine that!)

    So, what to do? Now I should move all up one directory, which shouldn't be a problem, but I'm concerned when I do an update that the files will get put in to a folder one directory below "public_html", and having to move them all manually kind of defeats the purpose.

    Otherwise I really am excited to learn about this. Thanks for any info you can share on this!

    • See, that period at the end of the command, that's why it is important. Without it, you get the issue you are having with it creating its own directories inside of where you already are.

      Also, I have used that exact command on over 40 blogs, so the error you received, I can't replicate. The URL does exist. Did you put a space between the end of the url and the period?

  7. I love the automated plugins update in wordpress 2.6. What about an svn client to update wordpress in the same way we use to the plugins?

    It would be great :)

  8. I love the automated plugins update in wordpress 2.6. What about an svn client to update wordpress in the same way we use to the plugins?

    It would be great :)

  9. I now believe the challenge I was experiencing has to do with “where” I was typing in that “period”. There is a space between the end of the svn URL and the period, yes? That seemed to be the cause of my challenges, and when I entered the space, the download stayed in the directory I was working in.

    Please let me know if this sounds about right! Thanks.

  10. I now believe the challenge I was experiencing has to do with "where" I was typing in that "period". There is a space between the end of the svn URL and the period, yes? That seemed to be the cause of my challenges, and when I entered the space, the download stayed in the directory I was working in.

    Please let me know if this sounds about right! Thanks.

  11. Very nice. Clear and straightforward. I had tried to do this previously, but the insistence in other documentation that you must name the directory “trunk” just made it too hard.

    Two questions:

    1) Is there any way to tell it _not_ to update Akismet? I don’t use that, and really don’t need it in my plugins directory.

    2) If I wanted to use SVN to track my own plugins separately within an SVN install of WordPress, how would I set that up? Maybe another article??? :) (Pretty Please?)

    P.S. — You have two separate “subscribe to comments” buttons — one in the form and one below it.

  12. Very nice. Clear and straightforward. I had tried to do this previously, but the insistence in other documentation that you must name the directory "trunk" just made it too hard.

    Two questions:

    1) Is there any way to tell it _not_ to update Akismet? I don't use that, and really don't need it in my plugins directory.

    2) If I wanted to use SVN to track my own plugins separately within an SVN install of WordPress, how would I set that up? Maybe another article??? :) (Pretty Please?)

    P.S. — You have two separate "subscribe to comments" buttons — one in the form and one below it.

  13. Great post here.
    Automatic Upgrade plugin allows that it automatically upgrade wordpress installation following official instructions listed here. It performs tasks: backing-up database, plugin deactivation, downloading latest wordpress version, upgrading files/database, etc all automatically.

  14. Great post here.

    Automatic Upgrade plugin allows that it automatically upgrade wordpress installation following official instructions listed here. It performs tasks: backing-up database, plugin deactivation, downloading latest wordpress version, upgrading files/database, etc all automatically.

  15. Hello!
    Very Interesting post! Thank you for such interesting resource!
    PS: Sorry for my bad english, I’v just started to learn this language ;)
    See you!
    Your, Raiul Baztepo

  16. Hello!

    Very Interesting post! Thank you for such interesting resource!

    PS: Sorry for my bad english, I'v just started to learn this language ;)

    See you!

    Your, Raiul Baztepo

  17. Hello ! ;)
    I am Piter Kokoniz. oOnly want to tell, that I like your blog very much!
    And want to ask you: will you continue to post in this blog in future?
    Sorry for my bad english:)
    Tnx!
    Piter Kokoniz, from Latvia

  18. Hello ! ;)
    I am Piter Kokoniz. oOnly want to tell, that I like your blog very much!
    And want to ask you: will you continue to post in this blog in future?
    Sorry for my bad english:)
    Tnx!
    Piter Kokoniz, from Latvia