Drupal Installation and Performance

These are some notes on Drupal installation and performance on Unix-like operating systems (using Ubuntu here).

Drupal Installation

  • Install MySQL and create the database and Drupal database user first. If you must use apt or yum to install Drupal, don’t try to install everything at once.
  • If you can avoid it, don’t install Drupal from your OS package manager. Download the latest tarball from Drupal.org, or use Drush.
  • If you’re running APC with apc.stat=0, set it to apc.stat=1 or turn it off temporarily before installation. Any caching system that doesn’t check for changed files will cause Drupal’s installer to fail. Be sure to enable your cache again once Drupal is running.
  • I’d recommend sticking with the “Minimal” install option and then adding what you need. “Standard” adds too many irrelevant modules.
  • At minimum I add these modules: Administration Menu, WYSIWYG, Boost, Chaos Tools, Token, Pathauto, XML Sitemap, and the Views UI.
  • Always enable clean URLs.
  • Put your Drupal install under Git control so you can revert changes if needed.
  • Copy your theme to sites/default/themes and work from there.
  • If you want all https://, add something like this to your site’s settings.php:
    // If you want your site to be SSL only, you can use a redirect like this
    if(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'){
        header('Location: '. 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);

Drupal Performance Improvements

  • Enable Drupal’s built-in ability to compress its Javascript and CSS files.
  • If you’re using a development theme like Zen, be sure to turn off its “Rebuild theme registry on every page” setting on production web sites.
  • Disable the ‘Devel’ module on production web sites. Devel is incredibly helpful, but it can come with a major performance hit.
  • Enable the “Boost” module on all the sites — Boost specifically caches pages for anonymous visitors, which on most sites is most traffic.
  • Set Drupal’s built-in cron tasks to run every 24 hours. Drupal uses cron to reindex content, check for updates, and flush its caches. If you try to access one of the sites, and it’s really slow, it’s possible that cron ran a few minutes before and Drupal has to regenerate everything because its cache is empty. (For some statistics on this, see http://www.metaltoad.com/blog/how-drupals-cron-killing-you-your-sleep-simple-cache-warmer.)

    Incidentally, I find Drupal’s “cron” tasks to be misleadingly named — they only run when someone accesses the site and the whole stack is loaded, including hook_cron(). Traditionally the whole point of cron is that it runs without human intervention.

    Another possibility might be to install Elysia Cron (http://drupal.org/project/elysia_cron, which gives you fine-grained control over which scheduled processes run and when.

  • If you’re not running the Zend Optimizer (e.g., with PHP 5.5 on Ubuntu 14), install the PHP APC caching system (as of this writing, 3.1.13) on the web server (Ubuntu used here):
    $ wget http://pecl.php.net/get/APC
    $ apt-get install libpcre3-dev
    $ tar -xvzf APC-3.1.13.tgz
    $ cd APC-3.1.13
    $ ./configure --enable-apc --enable-apc-mmap --with-apxs --with-php-config=/usr/bin/php-config
    $ make
    $ make test
    $ make install

    The basic settings I typically use are:

    apc.shm_size = 128M
    apc.mmap_file_mask = /apc.shm.XXXXXX
    apc.ttl = 3600
    apc.user_ttl = 7200
    apc.gc_ttl = 3600
  • Enable Drupal’s built-in caching of pages for anonymous visitors.
  • Enable gzip compression: use mod_deflate in Apache, or ngx_http_gzip_module in Nginx, to make the web server transfer compressed HTML, CSS and Javascript to the browser.
  • Add cache-control headers in Nginx or Apache to leverage browser caching.
  • Move all the JavaScript files to the bottom of the page. Putting them at the top tends to lock things up because HTTP restricts parallel file downloading.
  • Use Devel to identify slow-loading scripts and queries.
  • Install a general web caching system like Varnish or Squid. If you’re running Varnish, install the Varnish module, then configure it through the Drupal admin panel. Ensure “3.x” is selected as the Varnish version and copy in the contents of /etc/varnish/secret as the “Control Key”.


Leave a Reply

Your email address will not be published. Required fields are marked *