I have a new WordPress MU (WPMU) install and I am ready for my first upgrade. I couldn’t get automatic upgrade to work, and all the forums said: do it by hand manually. This is fine, but I didn’t want my site to be in flux with some old an some new files as I make all the copies. To solve the problem, I used a symbolic link to set up an atomic switch that allows me to instantly (atomically) switch from one version to the next. If it fails, I can also revert back.
Here’s how I did it on my Ubuntu Hardy (8.04 LTS) server…
Backup WordPress Install
You should be backing up your WP install regularly. You should CERTAINLY do a backup before you try anything like the steps outlined in this article. AND, be sure to verify your backup.
If you don’t know about backups, read up on them before you proceed with this article. Here’s some useful WordPress backup info.
Make A Copy of Your Current WordPress or WPMU Files
First, we are going to make a copy of our current WP files. Make the copy in the same place as you current files — likely your web root. My WPMU install is in /var/www/wpmu/. You can use any name you want for the copy. I thought it most clear to give it a name that reflects the WP or WPMU version, so I called my copy wpmu-2.8.4. Note that it’s important to preserve the file attributes (permissions, ownership, etc.) during the copy. Do this with the –preserve parameter.
These lines handled everything for me:
cd /var/www/ sudo cp -r --preserve=all wpmu wpmu-2.8.4
Create a Symbolic Link to the WP Files
A symbolic link looks and acts like a file or directory, but all it does is point to another one. Any command you perform on the symbolic link (ls, cd, edit, etc.) is automagically acted on the file or directory to which the link points.
We want to create a symbolic link that will be the new document of our WP or WPMU install. We will then point this link to the version-specific set of files that we want to run at any given time. You can call the symbolic link anything you want. I chose to call mine wpmu-current, as it will always point to my current wpmu version files.
Here’s how I created the symbolic link:
cd /var/www/ sudo ln -s wpmu-2.8.4 wpmu-current
Now, any reference to wpmu-current automagically affects wpmu-2.8.4.
Point your Apache2 Install to the New Symbolic Link
Now, to make it all work, we need to point our Apache2 installation to use the new symbolic link. Mine is setup as a virtual host, so I changed the document root in my Virtual Host file.
Old line in my Virtual Host file:
To make it take effect, reload apache:
sudo /etc/init.d/apache2 reload
Now your WP or WPMU install should be running off the new files. Check out your site(s) and make sure that everything looks good.
Atomically Switch From one WP or WPMU Version to Another
You are now all set to make atomic switches between WP or WPMU versions. And if something goes wrong, you will be able to instantly revert back.
To do it, set up your new WP or WPMU upgraded version in a new folder. For example, /var/www/wpmu-22.214.171.124. Creating your upgraded version is beyond the scope of this article. For help, check out upgrade docs from WordPress.
Once the new version is all set up in your new folder, switch to it atomically by changing the symbolic link to point to the new files. Note changing the target of a symbolic link is not truly an atomic operation, so we will use one line to create a new temporary link and then rename the new link. (If you want to understand this better, Tom Moertel does a great job of explaining how to change atomically change a symbolic link). Assuming the new WP install is in directory wpmu-126.96.36.199, this code does the trick:
cd /var/www/ sudo ln -s wpmu-188.8.131.52 wpmu-current-tmp && sudo mv -Tf wpmu-current-tmp wpmu-current
Bingo. We have now switched to the 184.108.40.206 files. Quickly check out your site(s) and make sure it all looks good. If not, you can revert back to the old version files by pointing the symbolic link to back to the original files.