Drupal Multisite Installation using Sub-Directories

Written by Chris Smith  //  September 17, 2010  //  Our Code  //  4 Comments

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 (see section below for more information).

The current documentation for the Drupal community covers a number of different installation procedures. Regardless of existing documentation, our installation experience proved to be difficult. Here are the steps we followed to complete our setup.

Our Requirement

Create a multi-site installation of Drupal 6.19 with three sites. The site web addresses needed to be:

[fancy_box]

http://134.71.117.200/admreports

http://134.71.117.200/ecexpert

http://134.71.117.200/sciencesummary

[/fancy_box]

This is considered a sub-directory multisite, not a sub-domain multisite. These steps assume that you have the Drupal core files already on your server. You do not need to complete a base installation for this to work.

Site Directory Names, Permissions

Each new site requires that a directory be created. We created the following three directories:

[fancy_box]
sites/134.71.117.200.admreports
sites/134.71.117.200.ecexpert
sites/134.71.117.200.sciencesummary
[/fancy_box]

In each directory, you must place a copy of the settings.php file. For the installation process, you must enable write permissions to both the directories and the settings files.

Apache Aliases

Many installation instructions require that a symbolic link be created for each new subdirectory. However, as an alternative, we created three server Aliases. In the httpd.conf file of Apache 2, we added these three lines:

[fancy_box]
Alias /ecexpert /var/www/html/
Alias /admreports /var/www/html/
Alias /sciencesummary /var/www/html/
[/fancy_box]

Don’t forget to restart your Apache server once these changes have been made.

Enable Clean URLS

Our multi-site installation required that the .htaccess file be modified in order for clean-urls to work properly. We added the following rewrite conditions to our .htaccess file before the standard rewrite conditions:

[fancy_box]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/admreports/(.*)$
RewriteRule ^(.*)$ /admreports/index.php?q=$1 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/ecexpert/(.*)$
RewriteRule ^(.*)$ /ecexpert/index.php?q=$1 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/sciencesummary/(.*)$
RewriteRule ^(.*)$ /sciencesummary/index.php?q=$1 [L,QSA]
[/fancy_box]

Modifications to the Bootstrap.inc

At this point, I recommend you attempt to install your new sites. If it works, congratulations, you’re done. In our installation, we had to modify the boostrap.inc file for the installation to work.

The conf_path function (line 320) was never able to find the settings.php file for our new sites. As a results, the multi-site installation would fail with each attempt.

Therefore, we modified the original code and the function began to work properly.

Original code
[fancy_box]if (file_exists(“$confdir/$dir/settings.php”)[/fancy_box]
New code
[fancy_box]if (file_exists($_SERVER['DOCUMENT_ROOT'] . “/$confdir/$dir/settings.php”)[/fancy_box]

This solved the problem and we were able to complete the site installation.

Final Notes

We hope that these installation instructions were able to help with your installation. If you have any ideas on how to simplify this process (or how to avoid modifying the core files), please let us know.

About the Editor

Let's talk: public service, open government, innovation, open source, technology, and the web. CEO of csedev.com

View all posts by Chris Smith

4 Comments on "Drupal Multisite Installation using Sub-Directories"

  1. badmash October 23, 2010 at 6:18 am · Reply

    I just signed up to your blogs rss feed. Will you post more on this subject?

    • CSeDev October 27, 2010 at 6:25 pm ·

      Recently, we’ve begun working with the Drupal framework, and we will certainly be writing about our findings as they happen. We’ve found that there is a substantial learning curve with Drupal, and we’ll post any details that might make it easier for others. Thanks for your interest in the blog.

  2. Randy R. Karaan November 16, 2011 at 1:38 am · Reply

    Hello sir.

    I would like to thank you for sharing your ideas on Drupal.

    If you won’t mind, I have several drupal sites that I want linked together through a xhtml/css landing page.

    This landing page has 3 image links.

    Landing page is in here (xhtml/css):
    http://www.edelhomecare.com/edelMain/

    1st image link (drupal):
    http://www.edelhomecare.com/edelAdult/

    2nd image link (drupal):
    http://www.edelhomecare.com

    3rd image link (drupal):
    http://www.edelhomecare.com/edelProf/

    I tried changing the domain redirect settings pointing to the land page. But, when I click the image links, I get an error. The site being accessed will not load.

    I can access the sites using the links above when I type it in the browser’s address bar.

    I think it has something to do with the htaccess file.

    I hope you can shed light on my concern sir.

    Thank you.

    Gb!
    Randy

    • Chris Smith November 19, 2011 at 4:48 pm ·

      Seems you’ve figured out the problem. If you are still having difficulties send me an email and we can discuss further.

Leave a Comment

comm comm comm