Updating Wordpress from the Linux command line in 20 seconds or less
March 3, 2007 by Fernando Duran
So just 11 days ago there were new Wordpress releases: 2.1.1 and 2.0.9 , which included security fixes and less than a day ago we got the announcement WordPress 2.1.1 dangerous, Upgrade to 2.1.2, where we learnt that the previous release may include a security exploit that was added by a cracker. Gotta update wordPress.
Oh well, things happens but I guess I'm closer to getting my site un-php-fied and using Python or Ruby on Rails intead (yes, I fall for fads, especially when they involve better programming languages).
Anyways, to upgrade WordPress there are good instructions at the official site wordpress.org, but if you use the Linux command prompt things can be simplified a little, like making a copy of the database without need of a GUI, getting the new version without having to download it first to your desktop and then to your server or overwriting the old WordPress files automatically without having to delete them first.
Unless you've had WordPress for a while most likely you already have the minimum requirements for PHP and MySQL but it won't hurt to test; WordPress requires PHP version 4.2 or greater, and MySQL version 4.0 or greater, we can check with:
# php -v
# mysql --version
It's also recommended that from your wordpress' administration dashboard you deactivate your plug-ins.
Now, we go to the parent directory that holds the WordPress directory, for instance something like:
# cd /var/www/mywebsite/public_html
# cd /home/mywebsite/public_html
This will change if you are in a shared hosting environment.
Let's backup the database and the WordPress directory:
# mysqldump -u root -p --add-drop-table --extended-insert --quote-names database_name > wordpress_back.sql
This will prompt for your root password. If you have no root privileges (like in shared hosting), replace 'root' with your user name. Replace also database_name with the name of your wordpress database.
Do a minimum check with # less wordpress_back.sql to verify that your data is indeed there.
Making a tar backup of the current wordpress files:
# tar -cf wordpress.tar ./wordpress
check the tar file by printing its contents:
# tar -tf wordpress.tar
OK, so now let's get the newest WordPress package and deploy it:
# wget http://wordpress.org/latest.tar.gz
# tar -xzvf latest.tar
There's no need to delete any previous files since tar overwrites them.
The tar file extracts a 'wordpress' directory and files within it; if your current installation uses another directory name (or it's at the document root) you'll have to delete the old directory and rename the 'wordpress' directory: # mv wordpress old_directory_name
Now when you browse back to your site you'll be prompted to update by clicking in a link (pretty much like an interface with a big red button that Dilbert created once). And that's it for the update.
You can also check in your administrator's dashboard that you have the latest version (at the very bottom) and reactivate your plug-ins.