Rectifying the vs. dilemma

By Erik, 6 June, 2011

Drupal multisites are really powerful and a nice way to not have to have all of the core files duplicated for each site that you're working on on a development or local server.

Drupal looks for settings.php in a number of places. The more exact of a match that it can find to your sites URL, the better. If your site's address is the most specific sites/ directory that Drupal will look for is: sites/ Then it will start working its way backward through the domain to find a match sites/ If it can't find a match, it will use the sites/default directory that comes shipped with Drupal.

Having found a valid settings.php file, Drupal will look in the same folder for modules and themes. It will also look in sites/all and in the core modules or themes directories. Again, if the module/theme is duplicated, Drupal will use one found in the more specific directory.

The sites/ directory is also typically where Drupal stores many uploaded and user contributed files. So this path is often included in settings and variables in the database. For this reason, transferring settings and content from local to development to production, it is very helpful if we can use the same directory on all of our machines.

The problem is that our setup is running from but the "development" and "production" sites will be at and respectively. Now, Drupal can handle serving both dev. and www. from sites/, you can't server a different TLD from the same directory.

To bypass Drupal's automatic multisite detection and to suggest a directory to be used, we turn to a small core patch for Drupal 6 that was wonderful enough to be included in Drupal 7 core. You can use the uploaded patch to create your own mappings.

cd ~/Sites/drupal
patch -p0 < d-6.20-directory-alias.patch

This changes one Drupal core file and adds a new file example.sites.php in the sites directory. To use the new functionality, simply copy the example.sites.php file to sites.php and edit it. There's a lot of detailed explanation and documentation within the file, but the guts of it are at the bottom commented out and ready for our changes. Change the following code:

#$sites = array(
#  '' => '',
#  'localhost.example' => '',

to be uncommented and map our existing url to the sites directory that we would prefer:

$sites = array(
  '' => '',

Now, Drupal will serve up from the sites/ directory so that all paths and configuration variables will be set the same way we need to have them on production.

Next: Keeping sites under control

Comments 3

Regina (not verified)

8 years 11 months ago

Hi Erik,

A quick thank you from someone who is an expert on Windows servers and c# applications. My first time in Apache/Drupal! I read this and related posted to set-up a development environment on my MAC :) Very generously done.

Many thanks!


Regina (not verified)

8 years 10 months ago

Hi Erik,

Could you point me to the best practices for moving a site from a multi-site in a local development environment to single site on hosted server? I am trying to figure out if I need to put my site in the sites/default folder on the hosted server or if I make a new folder matching my URL/Domain sites/, put my site in that new folder and leave the default folder there or delete the default folder. Thanks!


so, the best practice is to set up your local development env with the new domain and use sites.php to manage that.
Then on the final site use the sites/ directory. You should leave sites/default but you don't need to put anything into it as long as your domain will be swept up by