Always assume multisites!

Printer-friendly versionPrinter-friendly version

(Note: this article is about Drupal, but the same philosophy applies to other content-management systems that have multisite capability, such as PmWiki's WikiFarms feature.  In order to use multisites, you will need to have a hosting account that allows you to keep more than one domain or subdomain in the same account, so that they can access the same files.  Generally speaking, PHP cannot run files that are in another account.)

There are differing schools of thought about whether it's better to have a separate Drupal installation for each site (for example, example.com and cart.example.com), or to use its built-in multisite capability.  In my experience it is better to assume from the start that you may serve multiple sites from a single installation, because even if you never do, you will at least keep your site's files cleanly separate from Drupal's files, which makes upgrading or moving between hosting accounts much easier.  And if you do wind up hosting multiple sites, you will save a ton of time doing upgrades in one place instead of several, and all your sites' performance will improve from server-side caching of the PHP files.

Let me explain what I mean.  When you do a fresh install of Drupal 6, a settings.php file is created for you at drupal/sites/default/settings.php, and a files directory is created at drupal/sites/all/files .  (In Drupal 5, you had to create the file and directory manually, which meant that you might well put the files directory at drupal/files -- outside the sites directory -- but fortunately this has been corrected in more recent versions.)  Like this:

  • drupal
    • sites
      • all
        • files
        • modules
        • themes
      • default
        • settings.php

The default directory is for when no more specific settings.php file is available for the domain name you're using, and the all directory is available to all sites regardless of what domain name you're using... in other words, if you decide to use the same Drupal installation to serve cart.example.com, you would put its settings.php file at drupal/sites/cart.example.com/settings.php, and the example.com site would continue to use the one in the default directory, like so:

  • drupal
    • sites
      • all
        • files
        • modules
        • themes
      • cart.example.com
        • settings.php
      • default
        • settings.php

Both sites would be able to access the same files, which can be handy, but presents problems if you're not sharing users between the sites, because two users with the same ID number could potentially overwrite each other's files!

But the main problem with this setup is that if you later decide to serve a site with another domain name such as demonstration.com, it's no longer clear what the "default" means.  Is "default" example.com or demonstration.com?  Well, it's whatever isn't otherwise specified.  You can move the files into a subdirectory, but you will have to run a series of queries on the database -- potentially on four or five tables -- to change where Drupal looks for all the files.  You may also have to change your theme templates, if you referenced images that were in the files directory.

Instead, I highly recommend creating a directory for the domain name from the start: before you run Drupal the first time, simply create a directory at drupal/sites/example.com.  Drupal will find it and put the settings.php and files directories there instead of in its default locations.  All files specific to example.com will be kept in this one location.  (You're on your own to make sure that themes and modules specific to the site are kept in the right directory.) 

  • drupal
    • sites
      • all
        • modules
      • example.com
        • settings.php
        • files
        • themes
      • cart.example.com
        • settings.php
        • files

If you decide to upgrade this site separately from the others in your account (for example, because another site relies on modules that aren't yet available for the new version of Drupal), you can just move that one directory from the one drupal directory to the other, without worrying about leaving any files behind. Of course you'll also have to copy any modules that it may need from the drupal/sites/all/modules directory ... there are too many advantages to sharing modules among sites to go putting them in the site-specific directories.

  • drupal-5
    • sites
      • all
        • modules
      • cart.example.com
        • settings.php
        • files
  • drupal-6
    • sites
      • all
        • modules
      • example.com
        • settings.php
        • files
        • themes

Similarly, if you need to move a site to a different hosting account, you can move its files without affecting any of the other sites.  This is very handy if you happen to be a Web developer for multiple clients.