How to Upgrade WordPress across Multiple Blogs

First off, I keep my main WordPress installation in Subversion.

This does have the added drawback that all of my WP blogs will be out of date until I update my main WP Subversion trunk and svn up on the server(s). At the same time, updating X number of WordPress blogs by hand would be even more work…

Advantages of keeping your stock WordPress install in Subversion:
* You can include a standardized Plugins directory with all your favorite plugins
* Once you’ve updated your main Subversion trunk with WordPress & Plugin updates, it’s trivial to deploy these to all of your blogs
* You can keep a stock set of your favorite WordPress themes checked in
* Makes it really easy to setup a new blog, using all of your favorite plugins & one of your pre-selected themes (k2-themed blogs, for example, look nearly 100% different just by uploading a custom header graphic)

If you’re not already familiar with Subversion or version control in general, there’s an online book to help get you up to speed. TortoiseSVN is a great little GUI for Subversion on Windows systems that integrates right into Explorer.

How to Upgrade a Subversion Managed WordPress Repository

This guide is written for OS X. If you’re using TortoiseSVN and are familiar with basic version control concepts, you should be able to follow along at home.

Some initial setup:

mkdir ~/temp && ~/temp/wordpress
cd ~/temp/wordpress

Check out your managed WordPress subversion trunk:

svn co http://my.subversion.host/svn/wordpress .

Grab the latest version of WordPress:

wget http://wordpress.org/latest.zip
# Now dump the latest WordPress release into 'wordpress/'
unzip latest.zip

Now let’s copy these files on top of our current WordPress installation:

cp -R wordpress/* .

What changed?

svn status

Check in the changed files:

svn -m "upgrade WordPress to latest" ci

Now do another ’svn status’ to see what’s new.

Add these new files to your repo (e.g. for WordPress 2.3.2):

svn add wp-includes/wlwmanifest.xml
svn add wp-content/themes/classic/*
# ...

Now check all these bad boys in:

svn -m "latest WordPress additions" ci

Svn Updating Your WordPress Blog(s)

c1.Png

Now comes the easy part. SSH into your blog and cd to its public_html directory (cpanel sites).

You might be able to simply ’svn up’ here and deploy the latest changes.

svn up

Since I’ve had problems with this in the past, I’ve written my own ’svn_update.sh’ script which handles post-update permissions management for me.

Copy the following into a new file ’svn_update.sh’:

#!/bin/sh

echo "Beginning svn update process"
svn update
echo "Svn update complete"
echo "Fixing permissions"

# start by removing write permission for group on all files
# if we don't do this, then Apache throws a 500 error
chmod -R 755 *

# now remove execute permission on all non-directory files
find ./* -name "*.jpg" -exec chmod 644 {} \;
find ./* -name "*.gif" -exec chmod 644 {} \;
find ./* -name "*.js" -exec chmod 644 {} \;
find ./* -name "*.php" -exec chmod 644 {} \;
find ./* -name "*.html" -exec chmod 644 {} \;
find ./* -name "*.txt" -exec chmod 644 {} \;
find ./* -name "*.ico" -exec chmod 644 {} \;

chmod 777 svn_update.sh
chmod 777 .htaccess
chmod -R 777 wp-content/uploads/
chmod 777 wp-content/
chmod 777 wp-content/*

echo "Permissions fixed"

Next modify its permissions so it can be executed:

chmod 755 svn_update.sh

And run it with:

./svn_update.sh

You might see some permissions warnings like:

Fixing permissions
chmod: wp-content/plugins/xdforum/includes/Smarty/templates_c/%%F7^F7F^F7F34188%%header.tpl.php: Operation not permitted

Which you can safely ignore.

Next, if it’s a major version release, you’ll need to visit WordPress’ upgrade page:

http://your-blog-url.com/wp-admin/upgrade.php

And ta da, you should now have a fully upgraded WordPress installation.

Running this on Multiple WHM-managed Blogs

If you have root access on a WHM-powered server, then you can really streamline your WordPress blog setup / updating / etc.

Dedicated servers with WHM + cPanel can be had, for example, from HiVelocity for $90 per month. (Select the cPanel upgrade when checking out, for $25 per month). You can find even better deals, just don’t be so penny-wise that your server is so slooow that your readers flock elsewhere.

Log into your machine as root, and place this in a file ~/update_all.sh:

#!/bin/sh
su - onwebapp -c "cd /home/onwebapp/public_html/ && ./svn_update.sh"
su - sablog -c "cd /home/sablog/public_html/ && ./svn_update.sh"
# ... more as necessary

To run, modify it’s execute permissions first then run it via the command line:

chmod 755 ~/update_all.sh
~/update_all.sh

What this script does is first switch users “su - ” to the specified username.

Then the “-c” param is the command that should be executed. Multiple commands are daisy-chained together via linux’s “&&” operator.

So first we change directories into the public_html of the user’s home directory (”cd /home/onwebapp/public_html/”).

Next, we run our “svn_update.sh” file that we created above with the “./svn_update.sh” command.

If you have any questions or feedback, please drop a line in the comments. Thanks!

Leave a Reply