Optimizing and maintaining your Drupal site

Sure, the fun part of building a Drupal site is adding new functionality with modules, creating content, and seeing your theme come to life -- but there are quite a few things behind the scenes that are crucial to keeping your site running smoothly.

Here we'll cover backups, site maintenance, server performance, and general tune-up tasks that you'll want to keep your eye on.

Creating a backup of your database

 

Before performing any procedures that affect your database (such as installing or upgrading a module), you should create a backup in case you need to restore your site. The database contains all of the content of your website, as well as its settings and configuration options. As such, any issues caused by bugs in modules, conflicts between code, or data errors can seriously impact the content and functionality of your website.

Most web providers use software called PhpMyAdmin to allow easy administration of the MySQL database software that is also commonly used. This tutorial will focus on using it to create a backup.

  1. The exact method for reaching the PhpMyAdmin page for your website differs depending on your web host. Please consult their documentation or consult your system administrator for more detailed instructions in accessing it. It may simply be called something like “DB Admin”. 

  1. This is the main page. Begin by clicking on the “Export” link under the MySQL section of the main browser window.

  1. This is the export page. Be sure to choose your database’s name in the Export selection box before moving on.

  1. Scroll to the bottom and select the “gzipped” compression method and check the “save as file” box.

  1. A save file dialog box will pop up. The file you download will contain the backup of your website’s database. You can use this if you need to restore the contents and settings of your website.

 

Upgrading Drupal modules

Upgrading modules is a more involved process than installing or removing modules. The steps should be followed closely, as all these steps are necessary to ensure the stability of your website.

Database Backup

Your website’s database contains all of its content, as well as all of its settings and configuration. As such, any operation which modifies it could, although unlikely, be potentially damaging. We highly recommend you take steps to back it up before performing this procedure.

Update Module

Update capabilities are not automatically available in Drupal. You must first install the Update module, which is located here: http://drupal.org/project/update_status . Follow the instructions for installing modules with this module before continuing as it is required for the other steps.

Check Module status

  1. The Update module can check your modules for updated status automatically to assist you with updates. It will provide you with download links and available versions. Once the Upgrade module is installed and enabled, you can reach a list of modules for update by either clicking on the “available updates” link on the main administration page or by going directly to [sitename]/admin/logs/update. This page checks the current and the installed versions of modules, and will give a report on their status. This will allow easy updates without having to manually check each module installed in your website.
  2. In this example, the Views module is out of date. Any out-of-date module will be labeled in red, as shown above. We can upgrade this now.

Disable Module

You must first disable the module. Follow only part of the instructions listed here. Stop at the section labeled “Uninstalling a module” and only perform the first section of steps for disabling a module.

Reinstall Module

Next is reinstalling the module. These instructions are to be followed in their entirety. However, the Update module also provides a download link which may be used instead of going to Drupal.org as listed in the instructions.

Run update.php

Update.php is a script that is used to maintain websites after upgrades. A new version of a module may change the structure of the database. This script adjusts the database to fit the updated module. As the database contains all of the content and the settings of your website, this is an essential step to ensure its continued operation.

  1. The update.php script can be called two different ways. You may go to the main administration page and click on the “update.php” link on the front page, or you may go directly to [sitename]/update.php in your browser.

  1. Read over the content of this page. Instructions for a database backup are linked to above, and should be followed as noted here. You will require admin privileges to perform this upgrade. The first account created on your site will have the required privileges.

  1. If you do not have the proper privileges, you will receive this screen. Either log in or follow the instructions on the page to perform the upgrade.

  1. Once you have the proper privileges, you will see this screen. Click on the “Select versions” link to expand the section.

  1. These dropdown boxes contain database updates specified by modules you have installed. If you are not developing your own module or troubleshooting, you should leave them alone and just click the “Update” button. The correct items should already be selected by default — either “No updates available” if there have not been any database changes, or a number, which is simply an ID number of the database upgrade being applied.

  1. This next page may take a small amount of time to load, as the server is modifying your database. This page will display any errors that may have occurred during the process. If none have occurred, your module upgrade is complete!

 

Uninstalling Drupal modules

Uninstalling a module is easy. Before removing it, it must be disabled.

Disabling a module

  1. Go to [sitename]/admin/build/modules

                                                                                      

  1. Scroll down until you find the modules that you’d like to remove.   

  

  1. In this case, you’ll want to disable all of the “Views” set of modules. In order to disable a module, click to uncheck the “enabled” checkbox that’s next to it. If a module box is greyed out, that means you cannot yet disable it. This is because there is another module that requires that module to be active.

  1. In this case, Views RSS and Views UI must be disabled first before the Views module can be disabled. Uncheck those boxes first, then click on “Save configuration”          

 

 

  1. Once the page refreshes, the checkbox next to the Views module will no longer be greyed out. Repeat the process with the Views module, and everything will be disabled.  

 

                                                                  

Uninstalling a module

Not all modules have specific uninstall functions programmed in. A module will only show up on the uninstall tab if it has this feature. If it doesn’t, skip this step and simply delete its files.

  1. Click on the “uninstall” tab at the top of the [sitename]/admin/build/modules page. It will look like this: 

  1. Click on the checkbox next to the desired module (in this case Views) and click the uninstall button.

  1. Next, you’ll have a screen verifying your intention to uninstall this module.  

 

  1. Click on the uninstall button again, and you’ll get a screen with green text verifying that the module is uninstalled.

Remove/delete module files

Removal of module files is similar to the process of uploading module files.

  1. Use the same FTP client software as used in the uploading process, and use the same connection information.
  2. Navigate to the same directory
  3. Instead of uploading files from your own computer, delete the directory containing the desired module. 

SSH

  1. Use the same SSH client software as used in the uploading process, and use the same connection information.
  2. Navigate to the same directory.
  3. Instead of using the wget command to upload files, use the command “rm -rf [module folder name]”. In the Views example, you would type “rm -rf views”.

Note: a module without an uninstaller may leave tables or fields in your database. A module like this must be dealt with manually in order to completely remove it from your database, which is best practice to keep your site clean if you definitely do not want to use this module again. There may be an obviously named table or set of tables in your database which can be easily deleted, but the only way to know for sure is to examine the module installation file to see what was added in the first place. Always create a backup snapshot of your database before attempting this!