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
fun.mywonderfulsite.com the most specific
sites/ directory that Drupal will look for is:
sites/fun.mywonderfulsite.com. Then it will start working its way backward through the domain to find a match
sites/mywonderfulsite.com. 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
themes directories. Again, if the module/theme is duplicated, Drupal will use one found in the more specific directory.
sites/fun.mywonderfulsite.com/files 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
http://mysubsite.dev but the "development" and "production" sites will be at
http://www.mysubsite.com respectively. Now, Drupal can handle serving both
sites/mysubsite.com, 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.
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(
# 'devexample.com' => 'example.com',
# 'localhost.example' => 'example.com',
to be uncommented and map our existing url to the sites directory that we would prefer:
$sites = array(
'mysubsite.dev' => 'mysubsite.com',
Now, Drupal will serve up
http://mysubsite.dev from the
sites/mysubsite.com 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