27 November 2008 • 328 views, 3 today

Upgrading multiple WordPress installs

Warning: geeky content!

When WordPress 2.6.5 was released yesterday, that ‘Oh no, not again!’ sinking feeling was quite overwhelming this time. You see, I have 20-something WordPress installations already — imagine the time and effort it would take to upgrade all of them. Even if there was the WordPress Automatic Upgrade plugin, that would still mean having to access each WP dashboard and perform the semi-automatic upgrade (not fully automatic because you still have to manually click on stuff to begin and continue the process).

WPAU takes about 5 minutes to complete, a bit longer if you actually do download the backup files it generates for you. So, 20 x 5 = 100 minutes, or almost two hours! That is, if you don’t multitask and perform simultaneous upgrading — but I don’t like having sooo many browser tabs open.

So, I tried my hand on some hard-core Linux command line stuff. And it worked! I was able to upgrade all my sites to the latest WordPress version in under 2 minutes, not counting the time to learn the commands. To spare you the trouble of having to figure out the Linux commands on SSH yourself, here’s what I did.

:arrow: Make sure you have backups of your WordPress files and databases!

Let’s say your hosting setup is a VPS that allows you SSH or telnet access. And let’s assume that your website directory structure is /home/username/htdocs, where username is the unique identifier of each website account, and htdocs is where the public website files reside. For this how-to, let’s say you have three WP blogs with the following usernames: myblog1, myblog2, and myblog3.

• Download the latest WordPress zip file, and unzip it.

wget http://wordpress.org/latest.zip
unzip latest.zip
cd wordpress/

That should create a wordpress directory. Let’s say you downloaded the zip file in /home — so now you have /home/wordpress, and you’re there.

• The following commands will automate the upgrading process. Note: all of the commands will be executed only upon hitting enter after the last line.

for acct in myblog1 myblog2 myblog3
do
mv /home/$acct/htdocs/wp-config.php /home/$acc/htdocs/config.bak
rm -f /home/$acct/htdocs/*.php
cp *.php /home/$acct/htdocs
mv /home/$acct/htdocs/config.bak /home/$acct/htdocs/wp-config.php
chown $acct:$acct /home/$acct/htdocs/*.php
mv /home/$acct/htdocs/wp-admin /home/$acct/htdocs/wpadmin.bak
cp -r wp-admin /home/$acct/htdocs/
chown -R $acct:$acct /home/$acct/htdocs/wp-admin
mv /home/$acct/htdocs/wp-includes /home/$acct/htdocs/wpinc.bak
cp -r wp-includes /home/$acct/htdocs/
chown -R $acct:$acct /home/$acct/htdocs/wp-includes
done

I know, I know. The process is pretty involved, but it’s well worth learning. What the above executions are supposed to do are the following: copies over the new WP files and directories to each website account (you can add as many accounts to the list after for acct in), while preserving the attributes of the original files. Each website account will also have backups of the wp-admin and wp-includes folders.

Notice that we didn’t touch the wp-contents folders of your blogs at all. That’s because there really is no need to do so when upgrading WordPress.

You might actually have a different directory structure in your hosting setup, like /var/www/domain_name/htdocs or /home/account_name/public_html. Simply replace the appropriate parts of the above code with your own directory structure. Note that, during execution of the commands, the variable $acct is replaced with each of the website accounts that you include in the list in the first line of the code (myblog1, etc.).

:arrow: Caution: In case you have WordPress installations that have modifications in the wp-admin or wp-includes folders, do not include those sites in the accounts list. The above commands actually replace these two folders with fresh ones — although, your old files would still be in the backup folders.

:arrow: [UPDATE] I’ve trimmed the script a bit, but the new set will work just as well. Also, please note that your server might have a different setup when it comes to account usernames. If so, the chown commands above will not work for you. You might have to do a separate set of commands for setting file/folder ownership.

With all of my WP sites safely upgraded to the latest version, now I can spend more time in the meatier aspects of blogging.

Btw, this has been my 200th post. :bananacool:

 
  • Digg
  • Facebook
  • del.icio.us
  • Google
  • Slashdot
  • Technorati
  • Live
  • StumbleUpon
  • Mixx
  • Ratimarks
  • Reddit
  • TwitThis

Posts at Random


15 Responses to “Upgrading multiple WordPress installs”

  1. Paul Villacorta
    10:03 am on 27 Nov 2008

    hi blogie!!

    didn’t know yer making a shell script! w0oot!! This is a good script for those who have ssh access… I’m using putty for remote terminal access.. are you using the same tool too??

    Paul here!

  2. Blogie
    10:06 am on 27 Nov 2008

    Hi Paul. Yes, I know it’s you — nasa name field ang full name mo eh.. :P

    Yep, I use PuTTY. But I’m not really an expert on Linux. I just know enough to be able to manage my servers.

  3. Winston
    10:14 am on 27 Nov 2008

    I don’t use ssh.

  4. Paul Villacorta
    10:14 am on 27 Nov 2008

    oh yes! :D hahaha!

    checked on WP upgrade only five files were affected
    maybe we could just extract those five files from the package and do some scripting :p
    may ill try doing it tonight at home :D ill get back to work na… hay..

  5. Paul Villacorta
    10:16 am on 27 Nov 2008

    @winston
    yer a windows boi! Im a FreeBSD user.. UNIX / LINUX

  6. Blogie
    10:16 am on 27 Nov 2008

    @Winston — You actually have SSH enabled in your hosting account. You can access it via cpanel or you can use PuTTY, which is an excellent proggy for shell access.

    @Paul — Yeah, only 5 WP files. Kaya man na sa scripting. Gawa ka! :)

  7. Kevin Paquet
    10:27 am on 27 Nov 2008

    Each time I see the Upgrading message, the firs thing that pops out on my mind is..
    YAHOO. NEW FEATURES, until I realized that it showed 2.6.5, an increment in the second decimal, and then suddenly I went.. OH NOH, JUST A BUG FIX..
    I can’t wait for WP 2.7 and mass upgrade all those blogs, even those which I haven’t upgraded yet since 2.5 haha..

    I tried the Automatic Upgrade plugin ones.
    I won’t use it again, in short. natrauma naq ana.

  8. Blogie
    10:29 am on 27 Nov 2008

    @Kevin — Yeah, WPAU was buggy before. Pati ako tinamaan nyan once, but I don’t remember anymore kung ano’ng nangyari. Anyway, OK na man sya ngayon. Even Matt recommends it.

  9. Ayel
    1:20 pm on 27 Nov 2008

    Gotta try this! I really have trouble upgrading my wordpress blogs, especially when I haven’t learned about WPAU yet. Thanks for this.

  10. iceman9
    9:49 pm on 29 Nov 2008

    hmm… it would be better to beta test the upgrade before performing the said upgrades, because this might cause some unwanted errors that someone is not expecting, (did i do it right?)

  11. Blogie
    9:57 pm on 29 Nov 2008

    @iceman9 — That goes without saying. As with anything involving your blog’s settings, coding, etc., one must always test first. Still, it’s good that you mentioned this.

    I’m fortunate to have a test bed server. I tested these scripts on that machine several times before doing the deed.

  12. iceman9
    10:30 pm on 29 Nov 2008

    @ Blogie

    wow! that’s great! this means less downtime more uptime I consider this a best practice before performing any upgrade/patch installs. cheers! good! performing these demanding technical tasks is indeed a nosebleed!.

  13. iceman9
    10:48 pm on 29 Nov 2008

    @ Blogie

    i would like to ask? please? can you suggest to me a better domain registrar and hosting service? that’s not expensive? anyways; is goddady ok for domain registration and hosting? cheers

  14. Blogie
    10:51 pm on 29 Nov 2008

    @iceman9 — Godaddy is probably the best in the world for domain registration and management. I’ve never tried them for hosting, but I’ve heard not very good things about their hosting service from several people.

    I offer hosting. If you’re interested, drop me a line.

  15. iceman9
    12:46 pm on 30 Nov 2008

    @ Blogie

    cool! ill give u a buzz about hosting soon… cheers

Post a Comment