Drupal 7 subfolder multisite install

Mike B's picture
Mike B

Interested in how we work? Find out what’s good to know when working with Ixis.

Twitter Bird
Keep up to date with us on Twitter.
IxisIT AvatarFollow us @ixisit

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

Comments

Hi, I don't understand why the complexity. I typically run sub sites in folders usually for testing or staging e.g http://mydomain.com, http://mydomain.com/testsite, http://mycomain.com/testsite2 and so on each with their own data base. I don't use symlink or change settings file what is difference and advantages to what you have suggested?
TIA for any clarification

Mike C's picture

Are you actually installing a complete drupal codebase in a physical sub folder though?

In Mike B's case above he's sharing the same Drupal core files and just using a different database for each multisite installation.

Director / Solutions Architect

Couls use the domain_dir module instead

I'm a bit confused here -- sites.php was supposed to do away with sym links in D7. Why even bother with sites.php and just use the former D6 way of doing multisites?

I'm still sorting through the documentation to find the correct D7 way of doing multisites.

Mike B's picture

In theory it was but even according to documentation on d.o this is the way to do it http://drupal.org/documentation/install/multi-site (see Localhost alias for local workstation)

Drupal Developer

Hope you can help.

Q1) I'm having an issue with symlinks. While the symlinks work for D6 & D7 multi-site subfolder/URL and it seems D7 sites.php is NOT essential, what I run into is infinite/recursion on the server and in the browser URL path.

ln -s . site_1

Now this URL:
http://sitename.com/site_1

Works with this server folder:
~/public_html/drupal7core/sites/sitename.com.site_1

But so does this:
http://sitename.com/site_1/site_1
http://sitename.com/site_1/site_1/site_1
http://sitename.com/site_1/site_1/site_1/site_1
etc

And on server files, through CPanel or SSH ls -1 command.

../drupalfolders/..
.. site_1
drupalfolders/..
site_1
drupalfolders/..
site_1
..etc ..etc
drupalfolders/..
drupalfolders/..
drupalfolders/..

Q2) Is sites.php supposed eliminate the need for symlinks OR is the term "alias" used in this context simply so that site related information stored the database is not skewed when moving from a dev/test site to live?

Also noticed D7.16 to D7.17 has changed the sites.php file. The 7.16 version seemed to both "$sites = array" section AND a leading hash section ie # $sites['etc.com'] = 'etc.com' where as 7.17 has just the array.

***** 7.16 ***** example.sites.php
* $sites = array(
* 'devexample.com' => 'example.com',
* 'localhost.example' => 'example.com',
* );

# $sites['devexample.com'] = 'example.com';
# $sites['localhost.example'] = 'example.com';

***** 7.17 ***** example.sites.php
* @code
* $sites = array(
* '8080.www.drupal.org.mysite.test' => 'example.com',
* );
* @endcode

Any tips? Does this happen to everybody?

I need a Drupal 7 website with 2 sections...

for eg. www.example.com is main domain.

I have no sub domains.
The two sections of website are One is Civil and the other is MEP.

We have a Landing page with navigation to the below two sections:

section 1: www.example.com/Civil

section 2: www.example.com/MEP

The exact requirement is as follows:

/ = intro page

/site-a/ = menu and templates for site a

/site-b/ = menu and templates for site b

Separate layout and menu for these two sections. How can we keep two layout for the two sections? Is it a multisite? or just two sections?

I think we can use Themekey module for automatic selection of a theme depending on current path.

Please suggest me a solution.

Post new comment

The content of this field is kept private and will not be shown publicly.