Last updated January 16, 2014. Created by jbrauer on April 25, 2008.
Edited by PvdVelden, thumb, Christopher Jam..., Jovean. Log in to edit this page.

If you are running more than one Drupal site, you can simplify management and upgrading of your sites by using the multi-site feature. Multi-site allows you to share a single Drupal installation (including core code, contributed modules, and themes) among several sites.

This is particularly useful for managing the code since each upgrade only needs to be done once. Each site will have its own database and its own configuration settings, so each site will have its own content, settings, enabled modules, and enabled theme. However, the sites are sharing a code base and web document root, so there may be security concerns with multiple administrators. (See section"Security Concerns" below for more information).

Contents

 

Overview of the Process

To create a new site using a shared Drupal code base you must complete the following steps:

  1. Create a new database for the site (if there is already an existing database you can also use this by defining a prefix in the installation procedure).
  2. Create a new subdirectory of the 'sites' directory with the name of your new site (see below for information on how to name the subdirectory).
  3. Copy the file sites/default/default.settings.php into the subdirectory you created in the previous step. Rename the new file to settings.php.
  4. Adjust the permissions of the new site directory, and grant write permissions on the configuration file (sites/default/default.settings.php).
  5. Make symbolic links if you are using a subdirectory such as example.com/subdir and not a subdomain such as subd.example.com (see the subdirectory multi-site section below for details).
  6. In a Web browser, navigate to the URL of the new site and continue with the standard Drupal installation procedure (if you get an infinite redirection loop, check if the file install.php exists the document root).

It may also be necessary to modify your Web server's configuration file (often named httpd.conf for Apache) to allow Drupal to override Apache's settings. This is true for all installations of Drupal and is not specific to the multi-site install. Additional information is available in the Best Practices: Configuring Apache and PHP for Drupal in a Shared Environment section of the Install Guide.

           Back to Contents

Details of the Process

Domains, URLs, and sites subdirectory name

The new subdirectory of the sites directory has a name that is constructed from the site's URL. For example, the configuration for www.example.com would be in sites/example.com/settings.php. You do not need to include 'www' as part of the directory name.

Drupal will use the same sites/example.com directory for any subdomain of example.com, including www, unless there is an alternative, matching subdomain sites subdirectory. For instance, URL http://sub.example.com would be served from sites/sub.example.com, if it exists.

For a subdirectory URL, such as http://example.com/subdir, name the sites subdirectory as follows: sites/example.com.subdir -- and read the section below on getting subdirectory multi-site working.

If you are installing on a non-standard port, the port number is treated as the first part of the subdomain. For example, http://www.example.com:8080 could be loaded from sites/8080.example.com. If that directory doesn't exist, Drupal would then look for sites/example.com, just like a real subdomain.

           Back to Contents

Site-specific modules and themes

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

           Back to Contents

Document root

One area of frequent confusion is that in a Drupal multisite installation the webserver document root is the same for all sites. For example with the following three sites: example.com, sub.example.com and example.com/site3 there will be a single Drupal directory and all sites will be calling the same index.php file.

Some webhosts automatically create a new directory (i.e. example.com) when creating a new domain or subdomain. In this case it is necessary to make it into a symbolic link to the main Drupal directory, or better yet when creating the domain or subdomain, set it to use the same document root as the site where you have Drupal installed.

           Back to Contents

Subdirectory multi-site

If you are attempting to get Drupal multi-site working using subdirectory URLs rather than subdomain or different domain URLs, you may encounter problems. You'll start out by making a directory such as sites/example.com.subdir, and putting a settings.php file there. If this works for you, great! But it probably will not, until you make a symbolic link that tells your web server that the document root for http://example.com/subdir is the same as the document root for http://example.com. To do this, go to the example.com document root and type:

ln -s . subdir

(substituting the actual name of the subdirectory you want to make work).

If your codebase itself is in a subdirectory, then link your new site to the directory:

ln -s drupaldir subdir

For example, if your webroot is /var/www and you want example.com/site1 and example.com/site2.

1. Create Drupal install at /var/www/drupal/
2. Setup settings.php in /var/www/drupal/sites/example.com.site1 and /var/www/drupal/sites/example.com.site2
3. Create symbolic links in /var/www

ln -s /var/www/drupal /var/www/site1
ln -s /var/www/drupal /var/www/site2

This symbolic link is enough to resolve issues with subdirectory multi-site installations on at least some web hosts. If you still encounter problems with clean URLs and have access to edit the .htaccess file, try adding the following stanza immediately before the existing rewrite rule (for Drupal 7):

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{REQUEST_URI} ^/subdir
RewriteRule ^ subdir/index.php [L]

That block should go right after the RewriteBase / line, and before the other RewriteCond lines. What that does is catch incoming URLs that contain the subdir prefix and route them to the symlinked file so that they find the right database. Note that if you have multiple subdirectory-based multi-sites, each one will need its own block as above. It also may be necessary to use the absolute path to your subdirectory in line 4 above RewriteCond %{REQUEST_URI} ^/~user/path/to/symlink/subdir
(Based on this forum thread: http://drupal.org/node/239583#comment-786932)

Note that these problems do not usually occur for multi-site installations using a subdomain, so you might want to try that if you cannot get subdirectory multi-site to work. (However, subdomains are not good for search engine rankings!)

           Back to Contents

Localhost alias for local workstation

On many systems it is possible to create entries in a "hosts" file to create aliases for the localhost name for a local workstation. By creating aliases for localhost it is possible to create names such as localdev1.example.com and localdev2.example.com, both for the local computer.

If on the other hand you use subdirectories in your local web root, create a symbolic link like this:

ln -s drupaldir subdir

and name your site folder localhost.subdir.

           Back to Contents

Domain name changes

Once a site is in production in a particular subdirectory under the sites directory, the subdirectory should not be renamed, even if the Web site URL changes. This is because several database tables (for example: system and files) include references to "sites/www.mydomain.com." Instead of renaming the sites directory, you can create a symlink to the new URL from the old one. Navigate to the sites directory and then use the following command:
$ ln -s /path/to/drupal/sites/old.domainname.com new.domainname.com

           Back to Contents

Security Concerns

You might want to reconsider using Drupal's multi-site configuration, in situations where the administrators for all of the sites being run from the same code base are not either the same person or a small group with a high level of mutual trust. The reason is that anyone with full administrative privileges on a Drupal site can execute arbitrary PHP code on that site through various means (even without FTP access to the site), and that arbitrary PHP code could be used from one site to affect another site, if the two sites are in the same HTTP document root and sharing the same Drupal code.

So, unless you completely trust all of the administrators of the sites you are considering running from the same Drupal code base to be knowledgeable, careful, and not malicious, you might want to consider installing their Drupal sites in completely separate areas of the web server that are not able to affect each other via PHP scripting.

           Back to Contents

When to multisite

As a general rule on whether to use multisite installs or not you can say:

  • If the sites are similar in functionality (use same modules or use the same drupal distribution) do it.
  • If the functionality is different don't use multisite.

This is because you want your sites to stay as up-to-date as possible regarding drupal module security updates and when you have different functionalities this is more difficult to do because it takes a little more time since you need to test each site independently. If you are doing multisite, then the update needs to be run at the same time for all the sites which is not always possible.

So sites with different functionality usually end up being upgraded at different times because each needs to be tested and backed up. Site updates and backups are also pretty easy to do and can be automated with drush, but drush has little support for multisite install.

           Back to Contents

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

Running multi site was easy to set up as described on Drupal 6.16, Fedora 12, Apache 2.x, PHP 5 on my Rackspace cloud. But after several few hours I gave up on getting clean URL's to work, and went back to several copies of the code, one for each site, as clean URL was important to me.

I'm sure it easy, I just can't figure it our alone. Sample files from a working multi-site with clean URL's would be nice please post if you have them.

Even though I've done this successfully in the past, I drove myself a bit nuts this time around. I set up a multisite on a VPS and added two new domains, and was greeted with an error, then a "Drupal already installed" message. But I had forgotten to allow Noscript permissions for the new domains! I just used IE 8 and all went smoothly. Simple mistake, but wasted time figuring it out.

Will it be possible to create multiple sites by the registered users as in Wordpress...

Also,I would like to display certain modules to all the sub-sites registered under the main site. And, once a condition is satisfied, that particular module can be removed from that sub-site which satisfied the condition. Will it be possible.

Also, is it possible to select individual themes by users, and also, will it work with subdomains?

I've had a drupal multi-site setup working for a few months now, but have always wondered - should I have a directory in sites/ for each of my websites, or just the second one (I only have 2)? Lets say I had a site example.com, for which I just used sites/default/ and sites/all/, then I added a 2nd site example2.com, for which I created sites/example2.com/. Should I also have created sites/example.com/?

I've read lots of conflicting information about this, but generally, multi-site how-tos don't tell you to create sites/example.com/ but maybe they assume you already have?

Cheers,
Jack

Within the sites directory you will find at least two directories: "all" and "default".
The "all"-directory contains the shared files (modules and themes) while the default contains the site specific information (at least the settings.php and files directory, possibly also modules and themes).

In the Drupal Bootstrap (includes/bootstrap.inc function conf_path()) Drupal looks for sites/SITE_URL/settings.php, but when this is not found, the fallback is to sites/default/settings.php.

So in short: you don't need a directory for your default website, only for the extra sites. :-)

Hi MadChris:

I found your comments helpful. One more clarification will help me. I'm confused about the SITE_URL in sites/SITE_URL/settings.php. I have an existing Drupal site that I've been setting up. I want to create another sub site for my daughter's business. She doesn't have a domain name yet. Let's say my site is called mysite.com. Would I just create a directory called sites/michal.mysite.com? Having done this, would her clients actually go to michal.mysite.com to see her site? Now, what if she doesn't like the address michal.mysite.com and wants here clients to go to michal.com. Would this still work? Would I still begin with creating michal.mysite.com and then somehow redirecting people here from michal.com?

Thank you!
Kevin

Hi Kevin,
You are on the right track, but you should distinguish server configuration from Drupal configuration.
If the other site doesn't have a domain name (eg. example.com), a subdomain is a good solution (eg. subsite.example.com).

First, you should setup your server configuration (DNS and virtual host) to make sure the new subdomain is routed to the same path on your server as the main domain (eg. /var/www/example.com/httpdocs/) . If you need more help on this topic, your hosting provider and google are your friends.

Without further Drupal configuration, both urls (subsite.example.com AND example.com) will serve the same site. But if you add the directory subsite.example.com/ to your /sites directory and create a configuration file with a different database connection (or prefix), the domain subsite.example.com will act as a separate Drupal installation.

Hope this cleared things up,
Cheers.

Chris.