Multi-site

Last modified: August 31, 2008 - 15:04

Multi-site is a very powerful feature in large sites or hosting operations but is often mis-understood. Multi-site is designed as a way to share the same code base for multiple different Drupal based sites. These sites are separate and do not share content or administration. Multi-site just helps with managing the code base, shared themes and modules.

A single Drupal installation can host several Drupal-powered sites, each with its own individual configuration.

Additional site configurations are created in subdirectories within the 'sites' directory. Each subdirectory must have a 'settings.php' file which specifies the configuration settings. The easiest way to create additional sites is to copy the 'default' directory and modify the 'settings.php' file as appropriate. The new directory name is constructed from the site's URL. The configuration for www.example.com could be in 'sites/example.com/settings.php' (note that 'www.' should be omitted if users can access your site at http://example.com/).

Sites do not have to have a different domain. You can also use sub domains and subdirectories for Drupal sites. For example, example.com, sub.example.com, and sub.example.com/site3 can all be defined as independent Drupal sites. The setup for a configuration such as this would look like the following:

sites/default/settings.php 
sites/example.com/settings.php 
sites/example.com.site3/settings.php 
sites/sub.example.com/settings.php 
sites/sub.example.com.site3/settings.php 
sites/www.sub.example.com.site3/settings.php
sites/www.sub.example.com/settings.php

If you are installing on a non-standard port, the port number is treated as the deepest sub domain. For example:
http://www.example.com:8080/ could be loaded from sites/8080.www.example.com/. The port number will be removed according to the pattern above if no port-specific configuration is found, just like a real sub domain.

Each site configuration can have its own site-specific modules and themes in addition to those installed in the standard 'modules' and 'themes' directories. To use site-specific modules or themes, simply create a 'modules' or 'themes' directory within the site configuration directory. For example, if sub.example.com has a custom theme and a custom module that should not be accessible to other sites, the setup would look like this:

sites/sub.example.com/settings.php 
sites/sub.example.com/themes/custom_theme 
sites/sub.example.com/modules/custom_module

One key part has been missed

seanray - September 13, 2008 - 15:09

One key part has been missed in this step - we need to make sure all the domains hosted in one Drupal installation point to the same folder where Drupal is installed.

This bring some troubles for those who host their web site in a shared web hosting environement since the new domain added to their account will point to a sub-directory, and this cannot be controlled by the user.

In order to resolve this issue, we need to remove the folder created by the system, and create a symbolic link with the same name to refer to the directory Drupal is installed.

See more detail from How to Enable Drupal Multi Sites Feature in a Shared Web Hosting

Best Drupal Hosting | Affordable Web Hosting | Discount Web Hosting

 
 

Drupal is a registered trademark of Dries Buytaert.