Using Drupal's multisite feature, one can use a single codebase for multiple sites. This leaves a smaller footprint and makes your sites more maintainable since you only have to update one bunch of files.
This was already possible in versions prior to Drupal 7 by creating a configuration directory whose name was based on the site's hostname and pathname.
Although easy to setup this was sometimes cumbersome to maintain if you had different copies of your site running on different locations. During the creation of a site, one might typically maintain a development copy, an acceptation copy and a production copy. All these are on different locations. This would lead to creating several versions of the settings directory for one particular site.
In Drupal 7 a solution is provided for this particular problem. A new configuration file is available under the sites folder, called "example.sites.php". Using that file you can set up directory aliases. To see what those are, let's look at a particular example.
Suppose you are developing a site "http://www.example.com". You might then create a settings directory "sites/example.com". On your local machine, you're developing the site as "http://localhost/example.com". Normally, you would need to create a settings directory "sites/localhost.example.com". Now, in Drupal 7 you can tell Drupal to use the same directory, "sites/example.com" for the local copy by setting up a mapping or alias.
To do this, make a copy of "sites/example.sites.php" and name it "sites/sites.php". In there, set up the mapping using the sites array:
$sites['localhost/example.com'] = 'example.com';
This will instruct Drupal to use the example.com directory for the "http://localhost/example.com".
Comments
Thanks for sharing this info. This will be very helpful. It took me a minute to grasp it's significance though.
You can follow the full discussion on why this feature was added in the issue queue.
You can still work your own way with with different configuration folders, include files, ... But most people try to have the exact same configuration for development, acceptation and production (maybe using virtual images).
I tend to agree with Christopher. If you have setup multi-stage deployment then your different sites likely require different database credentials. Also change/add different settings in settings.php they'll need to pass through quality assurance so they'll need to start out on your development site, get copied to your Q/A settings.php and then to the production settings.php.
Interesting feature,
Thanks Christopher
Christopher, I typically use a trick like this in my settings.php file to ensure different databases are used depending on whether I'm accessing the site on its testing server or its live server.
if ($_SERVER['HTTP_HOST'] === 'example.test') {
$db_url = 'mysqli://local_u:local_p@localhost/example';
}
else {
$db_url = 'mysqli://remote_u:remote_p@localhost/example';
}
Wouldn't your local dev and remote production sites then be pointing to the same database? Because settings.php is inside the sites folder? Don't you want the same code by and large but possibly some different modules restricted to one site or another, and definitely different settings.php files for each site?
Post new comment