Apparently, WordPress is famous for its 5 minute install procedure, and claims upgrading WordPress is even easiier. And to be fair, it is a reasonably straightforward three (four?) steps:
- Step 0: Before You Get Started: Backup and deactivate plugins.
- Step 1: Replace WordPress files: Extract the new tarball over your existing installation. With special notes about what files you need to be careful to preserve.
- Step 2: Upgrade your installation: Hit your
wp-admin/upgrade.phpURL, which nicely upgrades your DB.
- Step 3: Do something nice for yourself.
My problem is I’m always, always recalcitrant in upgrading WordPress, because I cannot help but shirk at Step 1. Have I preserved the correct files (I have a whole lot of custom static content that sits alongside WordPress)? Did I make any changes anywhere that I need to keep (I once change a core WordPress file to work around a bug)? How do I even tell if I’ve accidentally overwritten the wrong file? And at about this stage it gets thrown into the too-hard basket, to be retried next weekend.
But not anymore!
funionfs I no longer have first-step fear. And while some of you may think that fiddling with
yum is a level of complexity well beyond Step 1, I can honestly say that this is what I consider an elegant solution.
A union filesystem is something I’ve pondered the existence of before (and trust Ivan to know exactly what I wanted). They allow you to fold up a set of separate directory trees and have them appear as one. One of the directories is usually read-write (with copy-on-write), while the others are read-only.
What’s in my docroot?
I have a reasonable chunk of static content (images, flash animations, software archives, movie downloads, etc) that I keep in a Subversion repository and deploy to this website via rsync. This content existed before I started using WordPress, and will exist if I ever stop using WordPress, so it is not appropriate content for WordPress to own.
I have WordPress, which is a whole bunch of
.php and what-not.
I have my all my files that sit on top of WordPress. My
wp-config.php config file, the
.htaccess file that WordPress generates so my URLs look cool, some plugins and my theme. It is these files that cause my Step 1 fears. (And in fact, these fears prevent me from making some much needed changes to my theme, too).
All these files, with their different sources and different life-cycles used to be clumped into the one scary directory.
What’s where now?
Now, I have three different directories:
/home/matt/madbean.com/static: My rsync-ed static content.
/home/matt/madbean.com/wordpress-2.1-orig: An extracted wordpress-2.1.tar.gz with no modifications.
/home/matt/madbean.com/wp_data: my WordPress config, plugins, themes, etc.
/home/matt/madbean.com/wordpress_all: An empty directory.
After a bit of fiddling with
funionfs options, I settled on a mount like this:
sudo funionfs -o dirs=\ /home/matt/madbean.com/wordpress-2.1-orig=RO:\ /home/matt/madbean.com/static=RO:\ /home/matt/madbean.com/wp_data=RW:\ NONE /home/matt/madbean.com/wordpress_all
After running that,
wordpress_all contains exactly what WordPress wants to see: a big mishmash. Any writes WordPress makes (e.g. to configuration or
.htaccess) get written through to
wp_data. Each time I rsync my static content to
static it is automatically visible in
wordpress_all. And as you will see below, upgrading is a scream.
To ensure this union mount exists next time the box reboots, I converted the above
funionfs instruction into an
funionfs#/home/matt/madbean.com/wp_data /home/matt/madbean.com/wordpress_all fuse rw,nosuid,nodev,allow_other,dirs=/home/matt/madbean.com/wordpress-2.3.1=RO:/home/matt/madbean.com/static=RO 0 0
Having set that up, it was now time to finally upgrade from WordPress 2.1. This is what it looked like:
$ cd ~/madbean.com $ wget http://wordpress.org/wordpress-2.3.1.tar.gz $ tar fvxz wordpress-2.3.1.tar.gz $ mv wordpress wordpress-2.3.1 $ sudo vi /etc/fstab $ # change the line to refer to wordpress-2.3.1 instead of wordpress-2.1 $ sudo umount /home/matt/madbean.com/wordpress_all $ sudo mount funionfs#/home/matt/madbean.com/wp_data $ sudo /etc/init.d/httpd graceful # for good measure $ # hit upgrade.pgp in my browser
Do you know how happy that made me?
I’m thinking of making the
wp_data directories Subversion workspaces (checked out directories). I can then version control my WordPress config. And by being able to remotely edit my theme and check it in (and check it out on a test WordPress server) I’m finally likely to make some changes.