Drupal’s multi-site capability has been around for quite some time. Site builders are able to spin up multiple sites, using the same code base, by creating a folder in the sites directory that matches the host name and path. On a production server the URLs never change, but if you want to create a local development version of your multi-site setup that’s where things get complicated.
For example, if your site domains are “example1.com” and “example2.com”. All you would have to do is create two directories called “example1.com” and “example2.com”, then create a file called settings.php in those directories and you’re done. You can place themes and modules within the specific directories and they’ll only appear on those sites. Your sites directory should look like the following:
When Drupal gets bootstrapped, it’ll look for a directory in the sites folder which matches the URL. If a folder is found it’ll use the folders settings.php to load the site. Open the
default.settings.php in the default folder for a more detailed explanation. The same applies when you create a local development version. If your local URLs are “example1.localhost” and “example2.localhost”, then you’ll also have to create a folder within the sites directory. When you have specific modules and themes within those site directories, managing the codebase with a version control system becomes very painful.
Luckily this issue has been fixed in Drupal 7 thanks to the
sites.php is stored in the sites directory, if you have installed Drupal 7 you should see a file called
sites.php, then uncomment and change the
$sites array as needed.
/** * Multi-site directory aliasing: * * Edit the lines below to define directory aliases. Remove the leading hash * signs to enable. */ $sites['example1.com'] = 'example1.com'; $sites['example1.localhost'] = 'example1.com';