Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

Drupal 7 subfolder multisite install

Parent Feed: 

Recently we had to create a Drupal 7 multisite install that used subfolders of a single domain, rather than the standard sub domain approach.

This proved to be quite the challenge but we found the following solution courtesy of some lengthy discussion on the #drupal-uk IRC channel.

We were surprised about the lack of documentation or blog posts around such a set-up so for the future we're documenting the process.

Setting up each sub-site

In your Drupal document root create a symlink for each of your sites to the same document root folder:

cd /var/www/drupal
ln -s . site_1
ln -s . site_2
ln -s . site_3

Repeat for however many sites you wish to run as a sub folder, we've done it for 3 subsites.

Mapping to a Drupal site install

Each of your Drupal sub sites should be installed as normal with their own folder under the document root sites/ folder. Each directory containing its own settings.php pointing to a dedicated database etc.

Now within the new Drupal 7 global sites/sites.php mapping file use the following code:

<?php
$prefix 
$_SERVER['SERVER_NAME'];
$sites = array(
    
"8080.{$prefix}.site_1" => "site_1",
    
"8080.{$prefix}.site_2" => "site_2",
    
"8080.{$prefix}.site_3" => "site_3",
);
?>

Note: in the above code '8080' is pre-fixed to the path because our local development environment web server is running on port 8080. If you're using port 80 (standard) this bit can be removed. It's also worth noting that if your vhost has FollowSymLinks in it's options then this will not work, it has to be commented out.

Your Drupal sites should now be visible at http://SERVER_NAME/site_1 http://SERVER_NAME/site_2 http://SERVER_NAME/site_3

Author: 
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web