Book Image

Drupal 6 Performance Tips

By : T J Holowaychuk, Trevor James
Book Image

Drupal 6 Performance Tips

By: T J Holowaychuk, Trevor James

Overview of this book

<p>Drupal is one of the most respected and widely used open source content management frameworks.&nbsp; Small, medium, and large-scale websites are built using Drupal and the framework supports ecommerce, CRM, multisite and web service integrations.&nbsp; <br /><br />Once you get your Drupal site installed and up and running, you will be concerned with site performance and how fast you can make your Drupal site run.&nbsp; This book will focus on implementing performance modules and solutions to help speed up your Drupal website.<br /><br />We will look at introductory topics such as upgrading your Drupal site, maintaining your site, and enabling core Drupal page compression and caching. <br />&nbsp;<br />Then we will turn to an advanced look at some contributed modules that help speed up performance, including Development, Boost, Authcache, Advanced Cache, and the Memcache API and Integration module.<br /><br />Finally, we&rsquo;ll look at how best to implement a Drupal multisite environment and run it with high-speed performance in mind.<br /><br />This book is designed for Drupal developers and webmasters who want to increase their Drupal site&rsquo;s speed and performance.&nbsp; You will take your Drupal site to the next level by not only displaying relevant and newsworthy content, but also running a powerful and high-speed website.</p>
Table of Contents (14 chapters)
Drupal 6 Performance Tips
Credits
About the Authors
About the Reviewers
Preface

Upgrading Drupal core


We're going to upgrade the Drupal core code first. Here are the steps:

  1. 1. Login to your server through FTP/SFTP.

  2. 2. You should have your local drupal-6.13 folder on your local FTP side (left side) and your Drupal site on your right side in the FTP window.

  3. 3. Open up /sites/all/modules and delete your entire contributed module list—you can safely delete all the contributed module code as you'll be adding the new Drupal 6.x versions during the upgrade process. It's a good idea to remove the legacy module folders first.

  1. 4. After backing up your custom theme files (make sure you have a good backup of all your CSS, and so on), delete the entire custom theme folder (in this case Zen). We'll add our custom theme CSS to the site once we complete the core upgrade process.

  1. 5. Delete all of your core Drupal files taking care not to delete the /sites or /files folders. Do not delete your .htaccess, robots.txt files, or any other files you may have added custom code to either. This includes php.ini. These files can remain in your Drupal directory.

  1. 6. Move your Drupal 6.13 files from your local side to your remote server—this will add all of the Drupal 6.13 core folders and files to your Drupal site/server. You do not need to move over the /sites folder, .htaccess, or robots.txt files. If you accidentally do move over the /sites folder, you will not replace your settings.php file because Drupal 6.x names this file with a different file name, so you cannot accidentally overwrite the file during an upgrade.

  1. 7. Refresh your Drupal site (on whatever admin page you are currently on). If you receive immediate parse errors or a white screen (the infamous white screen of death, though it's really nothing to be afraid of), make sure to carry out the following steps and run your update.php to update the database schema. You should see a screen with a bunch of parse errors at this point:

Running update.php

Immediately after moving your new Drupal 6.x core files over to your server and refreshing your site page, you'll see a bunch of parse errors. Don't panic! Follow these steps to run your update.php script in order to update your Drupal database schema, so it updates to the latest Drupal 6.x configuration:

  1. 1. Type in update.php at the root level of your site URL. So, for this site we'll have the following URL to run our script: http://variantcube.com/fire/update.php

  2. 2. Click the Return button on your keyboard to load the update.php script.

  3. 3. You will see the following Drupal database update page (along with more parse errors):

  1. 4. Click on the Continue button to begin the update process.

  2. 5. A second Drupal database update page will load. You do not need to select the versions—Drupal will do this automatically. Click on the Update button.

  1. 6. The updates will run. You will see a progress bar and each core module will be updated in the database schema. Allow all the database updates to complete. Do not click your mouse during this process.

  2. 7. Once completed, you should see a final Drupal database update page load. A series of messages will be visible telling you the database update is complete. For example, on our site Drupal tells us that it now has separate edit and delete permissions. This is good information to read, as you know exactly what Drupal did during the upgrade process. You'll also see a long list of executed database queries. This list will tell you exactly what updates the Drupal update.php script performed in your database tables. For example, if the update script altered or replaced tables.

  3. 8. At this point your update page should show all green messages and gray query executed updates. You should also see green checks next to your upgrade list at the top left corner of the page—Overview, Select Updates, Run updates, and Review log.

  1. 9. Your core upgrade process is now completed from the database side.

  2. 10. Click on the Main page or Administration pages link to be taken back to your new 6.13 site. It's a good idea to first click on the Administration pages link to make sure the admin pages load correctly.

  1. 11. Once you click on the Administration pages link, you can then go to your Status report page through the Reports | Status report link.

  2. 12. The Status report should now show you the new version of Drupal 6.13 listed. It should also show you green checks next to the rest of your configuration. This shows you that you have successfully upgraded your core code to Drupal 6.13. Congratulations!

  1. 13. Run cron manually to make sure the Status report loads again without any errors. cron should run successfully.

  2. 14. We're now ready to complete the entire upgrade process by installing the new 6.x versions of our contributed modules, and our Zen theme and corresponding custom theme files.

  3. 15. We will then enable the update status module (that now comes packaged with Drupal 6.x) and that will complete the entire upgrade.

Upgrading contributed modules

We're now ready to update our contributed modules to their 6.x versions. Follow these steps:

  1. 1. Download all of the contributed module tar.gz files corresponding to the latest 6.x stable releases to a folder on your desktop. You may want to create a folder called contrib._module_upgrades to put the new releases in.

  2. 2. Once you have downloaded all the tar.gz files, extract them into your contributed modules folder. This will create all of your module folders (one for each module).

Note

If you are using CCK and Imagefield, you'll also need to download the Filefield module—this is a dependency of Imagefield in Drupal 6.x.

  1. 3. Also, make sure you download and extract the Advanced Help module, so you can add advanced help documentation to your Drupal site (this is a large scale Drupal 6.x enhancement). The project page is here: http://drupal.org/project/advanced_help

  2. 4. You should by now have extracted all of your modules ready to upload via FTP:

  1. 5. Move your new contributed modules using FTP to your /sites/all/modules directory.

  2. 6. Go to your Modules admin list and re-enable the 6.x versions of the modules you just installed through their respective groups. For example, re-enable all of the Views modules and then run your update.php script. Then come back to the modules admin list and re-enable your Panels modules. Doing it in this way by enabling the modules as groups will help you to identify problems with your module upgrades and more easily diagnose problems than if you just re-enable all your contributed modules at the same time.

  3. 7. The only module you do not need to enable at this time is the Devel module. We're going to look at that module in detail in Chapter 3, so leave it disabled for now. Be sure to enable the Advanced Help module as well. Click on Save configuration.

  4. 8. You may receive a Fatal Error warning about your memory_limit size (in your PHP settings). If you receive this, go ahead to the next step and run your update.php script. We'll address our memory issue immediately after running update.php.

  5. 9. If you receive parse errors, immediately run update.php again. This time the script will update all of your contributed modules database schemas.

  6. 10. You will see your Drupal database update page again (at update.php). Click on the Continue button.

  7. 11. Click on Update on the next screen (the same as our update.php during core upgrade above).

  8. 12. When I run update.php, Drupal informs that there is not enough memory to run the upgrade. This is a performance issue due to the amount of modules we've added to our site and the resources these modules require. Before continuing our update.php we'll need to upgrade our memory_limit. We can do this by editing our site's settings.php file. These are screenshots of the two types of errors which may arise at this stage of the process:

Updating your PHP memory limit

We're getting errors related to PHP memory, so we need to increase our memory_limit in our PHP settings. There are a number of methods of doing this. You can set a higher memory limit in your .htaccess, php.ini or settings.php files. We'll try doing this by adding a memory limit increase to our Drupal site's settings.php file first. There's more about tweaking Drupal PHP memory limits here: http://drupal.org/node/207036

  1. 1. Either login to your cPanel File Manager utility or to your site through FTP to edit the settings.php file that is in your /sites/default folder. If you do this via FTP, you will need to edit the file's permissions first in order to add or edit the file. It needs to have write permissions for editing purposes.

  2. 2. I've logged into my cPanel File Manager utility and I've browsed to my /sites/default directory.

  3. 3. I check the box next to my settings.php file and then click on the Change Permissions button in the File Manager admin screen. I add full write and execute permissions. I click on the Change Permissions button.

  1. 4. I then click on the Edit button in the File Manager utility.

  2. 5. This launches the settings.php file in edit mode. I look for the PHP settings section of the file and the array of ini_set settings. I add the following line of code to my file: ini_set('memory_limit', '96M');

  3. 6. I specify 96M as my new memory_limit value.

  1. 7. Save the changes to your file.

  2. 8. Refresh your site admin screen to see if the changes worked.

  3. 9. If you refresh your update.php screen, the updates should automatically begin because your memory limit is now working. If you receive any remaining parse errors, run the update.php script again until you see no errors.

  4. 10. Drupal will give you the following note/info when you run update.php to upgrade your modules.

Note

Please note that the Panels upgrade from Drupal 5 to Drupal 6 is far from perfect, especially where Views and CCK are involved. Please check all your panels carefully and compare them against the originals. You may need to do some rework to regain your original functionality.

This is why we took the time earlier to make notes about the home page panel we're using on the site, in case we need to rebuild it.

  1. 11. You should now see a final Drupal database update screen with links back to your Administration pages (just like at the end of the core upgrade process). Click on the Administration pages link.

  1. 12. If you have installed the CTools module (to allow Panels to work) you'll see two messages appear at the top of the Administer page: The directory files/ctools has been created and The directory files/ctools/css has been created.

  1. 13. Load your Status report page and you should see everything in green mode with checks. You've successfully completed stage 1 of the contributed module upgrade process. Congratulations! Notice that on your Status report page you'll see the PHP memory limit is now set to 96M.

  1. 14. Run cron manually once more to make sure you do not receive any errors. The last items to address will be to re-enable your View for the photo gallery and your home page panel. Finally, we'll re-install and enable your custom Zen sub-theme.