Upgrading Drupal (Drupal, Part 2)

In the previous Drupal tutorial, we went through installing and configuring our Drupal site. However, Drupal is not a static product. It is an open-source project, which means that occasionally, new minor releases are issued. This tutorial will cover the steps required to safely upgrade to a newer minor revision of Drupal 7.x


Contents

Choosing the Right Upgrade Path

Drupal has both major and minor revision--figuring out which version you have can be found by going to the Available Updates page. This can be found by going to Admin > Reports > Available Updates. On this page, you can find all of the module and core version numbers. In this example below, we currently have version 7.8, and we need to upgrade to 7.10 for security reasons.

image:Drupal2-img01.png

As you can see, Drupal is warning us that the version we have currently installed, 7.8, is out of date. We should upgrade to version 7.10.


Putting the site into Maintenance Mode

All software updates must be performed with user account 1. [Remember in the previous tutorial how we created a special admin account? This is one of those times where this account must be used. Log into your site as admin and go to the Admin > Configuration menu. Under the Development tab, click "Maintenance mode". Click the "Put site into maintenance mode" checkbox (see below).

image:Drupal2-img02.png

While it is possible to upgrade your site while not in maintenance mode, visitors could access your site while updates occur. This could result in PHP errors being exposed to end users. It is preferable to perform all updates in maintenance mode to avoid these types of possible problems.

Creating Backups

Backing up your site

The next steps require the use of a command-line interface. This tutorial will use Terminal, which is shell client for Mac. Windows users can download Secure Shell with their UT EID from Bevoware. The following Unix commands can be used with either shell application.

The first step is to back up the entire file system. Log on to your FTP client using the command ssh yourhostname -l yourusername. Enter your password when prompted. Nothing will show up as you type your password, so carefully key it in.

image:Drupal2-img03.png

Once you've logged in, navigate to the directory of your Drupal installation. Depending on your server setup, this could be either in /public_html or /var/www/public_html. You can use the command ls -l to help you locate the files. The directory will contain folders such as authorize.php, cron.php, etc.

image:Drupal2-img04.png

Once you're inside the Drupal directory, you need to create a "tarball" of all the files. This is the equivalent of creating a ZIP file; it's an archive of all the files within your directory. The easiest way to do this is by using the following command: tar cvf backup.tar . (note the inclusion of the period at the end of the command, this tells the tar application to archive the entire directory). For more explanation on how to create a tar archive, check out Geek Venue's excellent page on compression tips.

image:Drupal2-img05.png

You'll see all of the files being added to the archive (the v in the previous command stands for 'verbose'). To verify your files are present in the archive, key in the command tar tvf backup.tar. This will display the complete directory structure of the archive (t = 'table of contents'). Since we are just making a backup, it's not necessary to compress our tarball.

Backup up your database

To back up the database, we will use a program called mysqldump. This program creates all of the SQL commands required to completely recreate your database, in case the upgrade fails.

Use this command to create a backup of your database:

mysqldump --user=YOURUSERNAME --password=YOURPASSWORD --databases YOURDATABASENAME > backup.sql

Replace the username, password, and database name fields with the information you used in Part 1 of this tutorial.

Once the files and database have been backed up, performing an ls -l command on your directory should look like this:

image:Drupal2-img06.png


Upgrading your site

Now that you've created a backup of the site and the database, you can remove every directory except the sites folder (since your downloaded modules and themes live in this folder, you definitely need to keep it). The rm -r command can be used to delete all files and directories that you want. The image below shows the commands needed to delete the files. Notice that we leave the backup.tar, backup.sql, cgi-bin, and sites files/directories.

image:Drupal2-img07.png

Once we've completely removed these old files, we use the wget command to download the new version of Drupal. In this case, the command would be wget http://drupal.org/files/projects/drupal-7.10.tar.gz. You would replace the version numbers in this filename with whatever the current version you are upgrading to.

After downloading the file with wget, you can use the tar command again to unzip the file. The command in this case would be tar -zxvf drupal-7.10.tar.gz.

Finally, we need to copy all of the files from the unzipped directory back into our main /www folder. This command is cp -R drupal-7.10/* drupal-7.10/.htaccess DRUPALDIRECTORY. This ensures all of the files from the unzipped archive are placed in the DRUPALDIRECTORY. You should substitute your install path for DRUPALDIRECTORY.

The complete directory structure should look like this once you are done:

image:Drupal2-img08.png


Running update.php

Now that we've completed the download of the new files, we need to update the database structure. In your web browser, navigate to http://yoursite/update.php. Run through the update wizard. Any database structure changes will appear in the "Pending Updates" page.

image:Drupal2-img09.png

Once the wizard completes, check to make sure there are no errors. If there are none, you can go back to the home page.


Updating Modules

Sometimes, modules have updates that are specific to certain Drupal Core updates. To make sure all of your modules are up to date, go to the Admin > Reports > Available Updates page again. You'll see that your site has now been upgraded to the latest version of Drupal core (7.10 in our case). Click the update tab to see any module updates.

In our case, we have two available modules to update.

image:Drupal2-img10.png

Click the checkboxes next to all the modules to update, and click Download these updates. Run through the wizard that comes up, authorizing the selected updates. Finally, when it is complete, run update.php again to apply any new database upgrades.


Cleaning Up

Sometimes core and module updates can change the way your site looks. Go through the pages of your site, checking to make sure all pages still render properly. If everything checks out okay, you can delete all of the files you created in the command line and re-enable your site.

We can use the rm -r command again to delete all of the backups and downloads from earlier. The following image shows the commands to run:

image:Drupal2-img11.png

Finally, we can re-enable our site by going to Admin > Configuration > Maintenance mode and unchecking the "Put site into maintenance mode" checkbox.

Congratulations, you've just updated Drupal Core!

image:Drupal2-img12.png