06 - June - 2012

Drupal 7 subfolder multisite install

Post by Mike B
Ixis Service

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:


$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

Picture of Mike B

Mike B

Drupal Developer

Developer, Tinkerer, Coder, Hacker, Husband. Powered by coffee and whisky.

Comments

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.

Mike C

In reply to by Visitor

Couls use the domain_dir module instead

Visitor

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.

Visitor

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?

rCharles

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.

harikris

Using NGINX the symlinks solution worked for me except for clean urls for the subsite, it doesn't work though it's working on the main site

Visitor

Thank you so much for posting this! I've wasted almost two hours messing with apache settings, /etc/hosts, you name it. Turns out my problem was using a slash in the sites array key instead of making it a dot.

Too bad Drupal's docs don't point this out in their subdirectory instructions for multisites.

Charles

Add new comment

Share this article

Sign up to our newsletter!

Our thoughts

Let's work together

Get in touch and find out how we can empower your organisation.
Back to top