Nov 04 2006

Drupal Multisite Configurations and Hosts

Categories:


Domain Dashboard

To help facilitate the management of your Drupal multisites, you may want to take a look at the Domain Dashboard - allows you to manage multiple websites at once and see statistics and data all in one place. Optimized for WHM and Cpanel.

How to Correctly Set up Drupal Multisite?

The ability for Drupal to run multiple sites from one account is a huge plus for admins that are deploying multiple Drupal installations. The simple reason for this is that all Drupal installations can be updated at once. Basically each additional domain "points" to the document root of your primary Drupal installation. All you need to do to update the files of each additional Drupal site is update the files in the root install once. Caution: Before deploying production sites in a multisite environment I urge you to read my notes on security below and updating multisite codebases.

Security

Before proceeding with these multisite installations please note that it's possible for malicious users of one site to access protected files of multisite installations if they are given the ability to run PHP code. For example, the normally protected settings.php file (which hides confidential database access information) of one multisite could be accessible by another by running the following PHP snippet:

<?php
$file
= file ( 'sites/example.com/settings.php' );
foreach (
$file as $key => $line) {
print
$line;
print
"<br />";
}
?>
 

Therefore it is vital that you follow the below guidelines:

  • Only administrators of the multisites should have access to the PHP input format that would enable them to do this in the first place, and never give the owners uid = 1.
  •  
  • If you need PHP input for users, run each user's php process as fast-cgi and only link their sites subdirectory from the primary installation.
  • It's recommended that you use a Virtual Host setup to begin with. You can also set up chrooted Apache environments. A V-host will usually do this for you.

Individual settings and themes for each site

In addition, each site will have its own settings and themes. This is where the "sites" folder comes in. You place each additional multisite in the /sites directory as its own directory. For example, the domain example.com would be added in /sites/example.com. It will have its own settings.php file, and its own theme folder.

Separate databases for each site

In the settings.php file for each site you will enter the information for its respective database. This way, each multisite will run off its own database. In addition, each will have access to its own theme files.

Fully separated control for each multisite

Finally, when you log into example.com (multisite pointing to your primary domain), you will be able to select which modules it uses, which theme, and will have full control over its settings as if it were its own separate Drupal installation.

 

How to set all this up?

The key behind Drupal multisite installations is that your host must enable you to point your additional sites to your primary Drupal installation's document root. This can be done via domain parking, symlinks and virtual hosts.

Multisite via parked domains

It is also possible to implement a multisite configuration by simply parking the multisite domain on top of your primary domain. This may in fact be the easiest route to take. You can then administer emails for the parked domains as well as access their databases by logging in to your primary root's admin (Cpanel).

Steps to park a domain on top of another

Domain Parking Via Cpanel

To park a domain in Cpanel (Control Panel), simply click on "parked domains," add your domain, and it will be parked on top of the root domain. To unpark the domain go back to "parked domains," select which domain you wish to unpark from the drop-down box and select "remove domain."

Domain Parking Via WHM

To park a domain in Web Host Manager, go to DNS Functions, and click on "park a domain." From here you will be able to select a) the domain to park on top of, and b) the domain to park. To unpark the domain select "List Parked Domains" from Account Information, and click "UnPark" next to the domain you wish to unpark.

 

Symlinks point subdirectories at your root installation.

Configuration with shell access

First create a subdomain (ie. newsite.primary.com). This will create a new folder: /root/public_html/newsite. Delete the "newsite" folder, as it will be replaced by your symlink. Inside "public_html," create the symlink with the following code (shell access):

ln -s . newsite  

The symlink "newsite" now points to your document root (public_html) - voila!

 

Configuration without shell access

It is still possible to execute shell code without shell access. To execute shell code in Drupal, simply create a PHP page with the following and execute it from your root Drupal directory:

<?php print `ln -s /root_path/public_html/ /root_path/public_html/newsite`; ?>  

In this example the first path is the primary domain, followed by the multisite domain. PHP also has a symlink function you can use:

<?php symlink('primary','multisite'); ?>  

important: The first example uses backticks (usually to the left of the '1' key on your keyboard), while the second example uses single quotation marks. The backticks tell PHP to execute the code, which we need for the shell script, but in the symlink function we are simply inserting values into an existing function.

Multisite via Virtual Hosts

In order to use this method you or your host will need access to httpd.conf. Since this file controls the entire server this option is normally only available in dedicated hosting environments.

site-root: Name VirtualHost 111.22.33.444   <virtualhost>   DocumentRoot /absolute/path/to/drupal   ServerName site-root.com   </virtualhost>  site-one:   <virtualhost>   # note that the DocumentRoot is exactly the same for both VirtualHosts   DocumentRoot /absolute/path/to/drupal   ServerName site-one.com   </virtualhost>  subdomain.site-two.com:  <virtualhost>  # note that the DocumentRoot is exactly the same for both VirtualHosts  DocumentRoot /absolute/path/to/drupal  ServerName subdomain.site-two.com  </virtualhost> 

How to Update Multisite Installations?

This is a little more tricky, as multisite updating is not quite as smooth (yet) as you might first imagine. First of all, if you are still running 4.6, I recommend NOT deploying multisite environments that you plan on upgrading to 4.7+. The reason? The update process is tedious to the point that you might as well install separate sites. As for those installing 4.7 codebases, as I currently have the majority of my production sites running on, the upgrade process to 5.0 should work as follows, although I have yet to test this.

Upgrading from 4.7.x to 4.7.y in a multisite environment

The process involves replacing all the core files, and the running "update.php" on the primary domain. This will update the primary domain's database, but if you have your multisites set up with their own databases, you will need to update these independently. Simply run "update.php" from each installation. The problem with 4.6 upgrades is that this simply results in a blank screen (ie. doesn't work).

Using database prefixes

The alternative to setting up a separate database for each multisite installation is to assign all sites to the same database as the primary domain, but with their own table prefixes. So for example, for the users table you would have:

Multiple Databases

database1.site1.users database2.site2.users database3.site3.users  

Single Database

database1.site1_users database1.site2_users database1.site3_users  

An advantage prefixing gives you is that you can update all the multisites as once. The obvious disadvantage is that you have all your sites crammed into one database, which can make maintenance (backups) more tedious. Yet another advantage is that you can use this to implement shared functionality, such as allowing login sessions to authenticate across multiple sites.

I hope this helps. Please post any comments or questions below. Also, if you have found a host that is particularly suitable for Drupal multisite installations, please share your recommendations and experiences.

Average: 4.2 (10 votes)

Select your preferred way to display the comments and click "Save settings" to activate your changes.

How do I create the symlinks...

Above you state you can create symlinks to point one document root to another... Can you walk me through how to achieve this? ie which folders get deleted and symlinked, and which commands get used specifically to achieve this?

I have been searching for hours for the kind of info in this post. The info is fabulous, however I am looking for exactly the one item that wasnt explained...

Thanks,

Added symlink instructions

Hi there,

I've added symlink instructions - hope this helps Smiling

MultiSite Drupal & vBulletin

This is a great article. This is one of the best article that explain the Drupal multisite installation in detail. Thanks a lot.

I have been trying multisite myself and is facing some problems.

Are we able to install separate vBulletin for each site in a multi site environment?

I created domainB as a multi site of domainA. I parked domainB to domainA.

Where should I create the vbulletin folder for domainB?

You're going to create one

You're going to create one vBulletin folder in the root of your primary drupal install at primary.com/vbforum. All multisite vBulletin forums will then run off this primary vBulletin installation. This works in the same fashion as other multisite installations - ie. Gallery2, Drupal modules, etc. The key is having individual site files for each domain and appropriately configuring settings.php to point at the appropriate databases for each multisite installation, as described above.

Good luck and let me know if you get this to work Smiling

Thank you for helping.

Thank you for helping.

Is it possible to have multiple vbulletin for multi sites?

I mean each site in my multi sites environment has it's own vbulletin installation, not all sites sharing 1 vbulletin installation.

I don't have experience

I don't have experience setting up vBulletin, but I imagine you should be able to run unique vBulletin setups off one primary installation (so each multisite retains a unique vBulletin forum). Alternatively you should be able to create separate vBulletin installs for each site, yes, but that may be more of a hassle to update. If I get around to it I'll mess with this some myself and report back. Good luck!

files directory

And what about the /files and /Userfiles directories?

My problem is that I wish to create a space for each site keeping separate uploaded files.

Using the following VirtualHost directive (IP are hide) image gallery doesn't work for subsite www.example.com while in the default site it works regurarly.

#Basic setup
ServerAdmin webmaster@aaa.bbb.ccc.ddd
ServerName www.example.com
#Include conf.d/drupal.conf
DocumentRoot /usr/share/drupal-4.7.2
Alias /UserFiles /usr/share/drupal-4.7.2/sites/www.example.com/UserFiles
Alias /files /usr/share/drupal-4.7.2/sites/www.example.com/files

RewriteEngine on
#RewriteBase /usr/share/drupal-4.7.2
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all

Each multisite is able to

Aliases - have you tried referencing your /files directory with the absolute path - ie. /sites/www.example.com/files? If that works I don't see why the aliases should not.

As far as the image gallery is concerned - are you referring to gallery2 (menalto)? If so, you need to specify multisite install within the gallery2 installation. It will install a multisite gallery codebase on your primary domain. Your Drupal multisites should then be able to access the primary gallery2 installation. I have yet to actually set this up myself so I can't yet comment on details.

thanks!

Thanks for this great article. It is great to see the details for multisite all in one place. I am leaning towards using the virtual host method as I can edit httpd.conf. I guess all three methods work the same in the end.

Thanks,
Shrop

Security!

Note that you did not close up sites from running PHP on eachother.

Anyone who follows this howto will end up with a server where every admin of foo.com can run any code (and therefore takeover) on all the other sites on this multisite setup.

Thanks for pointing this

Thanks for pointing this out! Multisite setups are recommended to be set up in contained environments - in other words, related sites, and site creators should not be granting PHP access to roles they don't trust. But this raises an important issue, so I've added a corresponding Security section at top that all should read.

Symlinkquestion

How do write the php-script if it isn't a subdomain? If they are on the same level so to speak. Or if I want three subdomaines to be a multisite but want the main site to be a site on its own?

The php script functions for

The php script functions for multisites regardless of the level they are set up on. It's also possible to have a primary drupal site that is the codebase for three subdomain-based multisites. Simply park the subdomains on top of the primary site.

Hi

Just wanted to say "hi". Nice website.

Paul

routing the 404s

Great article,

I'm just having one problem. My 404s are all going back to the 'root' installation. Any way to set it up so that each 404 will go the right 404 page?

Custom Error Module

Are you using the custom error module? If so, make sure you have copies of it in each multisite (primary.com/sites/multisite.com/modules/customerror). You can use this approach to modify and customize modules for each multisite.

What about the .htaccess?

I have a different .htaccess files confiured for each of my sites. Is it possible to use each one for each site? Where should each of them be placed? What happens to the general .htaccess in the root dir (i.e. absolute/path/to/drupal) ?

You should be able to

You should be able to maintain a separate .htaccess file for each site, as well as control all your multisites via the primary .htaccess file. As far as gallery2 is concerned, you may use any .htaccess file. However, I recommend maintaining a separate .htaccess file for each gallery2 installation.

Smiling

Great tutorial

Thanks for this great tutorial. I run a dedicated server with WHM/Cpanel on it. I figured out how to do this myself by creating a virtual host and then modifying the httpd.conf section for that virtual host and pointing it to the original install. It would be great to be able to clone a site install to another one. Is this possible?

Yes, it's possible to clone

Yes, it's possible to clone installations.  You should be able to use WHM to WHM or Cpanel to Cpanel transfer (quickest way).  Alternatively, you can backup the database and files and add them back to the new site installation, making the appropriate adjustments in that site's settings file (for the new hosting account username).

symlink finely worked.... now...

So I found your page and a lot of others. Great article by the way, the most helpful and clearly written I have found. Covered what I saw in at least 50 places on Drupal.org.... Anyway, I wrote a symlink() that finely worked, or at least I thought it did. There was no permission denied (Must set the publichtml directory to 755 or 777 before you execute the symlink command) and I got "file doesn't exist....."

I thought: "okay, I am running this in the domainroot (publichtml) so the target can be "."... The source is (Was as it was created by cpanel) one level up, that means, "./subdomain.domainname.tld"' I ran the script.

Blank!!!1 No errors, no notices, nothing. How do I know if it worked?

Type in the address of the subdomain.... Nothing but a nice and wonderful 404 NOT FOUND

my drupal: version 5.1
site folder
-----------------------------------
sites/all ..settings.php
sites/all/modules
sites/all/themes
sites/default ..settings.php
sites/default/modules
sites/default/themes
sites/default/files
sites/default/tmp
sites/test.2wdirect.com ..settings.php
sites/test.2wdirect.com/modules
sites/test.2wdirect.com/themes
sites/test.2wdirect.com/files
sites/test.2wdirect.com/tmp
---------------------------------------------

My host gives me cpanel access no ssh. My tld (2wdirect.com) and my subdomain.2wdirect.com are created in the user root. I deleted (as per lots of instructions) the sub.d.tld directory that was created by cpanel. I made the permissions on the symlink.php file 777 and the publichtml 777 while trying to run the script. ---------------------------------------------
Question #1: Why do you think I got a 404 error?
Question #2: Is there a way to check in the php code to see if symlink() return TRUE or FALSE?
Question #3: Can you make any suggestions as to what to try next?

Small Variation

Thanks for this page, it makes things clearer.

Because of a bunch of problems, I want to move my sites. I created them originally as separate sites with 5.1, but as I move them, I want to turn them into a multisite with 5.2. Additionally, with D6 imminent, I want to set it up so that I can migrate sites one at a time after I build D6 on the server. I will probably do the actual conversion on my PC, where I sort of have multisite working, and then import the converted database.

This is obviously going to require supporting 2 codebases and 2 sites folders (because of modules). I can't see why my files folder won't be okay as it's mostly images.

Are there any other gotchas I have to watch out for? Tips, tricks, magic?

Thanks,
Nancy W.

Multisite, single control

Using Drupal, I am trying to set up multiple sites, on multiple domains, but want one single user interface. Can I do this with Drupal Multisite?

Each domain will have a different theme
Some content will be shared on some or all the sites

Is it possible to have 1 "non Drupal" and several Drupal sites

I want to have one old fashion domain that is static HTML and map to DOMAIN1.COM, while I have several other domains that each map to a different DRUPAL website, I am on a shared host and have been able to use a parked domain cPanel settings to get to my sites. But every request to the host seems to want to be a Drupal site. I need a method to set up the static site so it is outside the Drupal site. When I set this up originally I put Drupal at the top of my directory structure.

Thanks for the clear explanations above. David

Static and Drupal Multisite

Hi David,

The easiest implementation would be to have the static domain as a separate domain entirely - separate Cpanel, etc. If your host doesn't offer multiple hosted domains with your plan they're almost sure to offer pointers or aliases you can use to setup your different domains.

If you're putting all sites under one account you'll probably want to put your static domain in the root, and your primary drupal site in a subdirectory or subdomain with multisites running off the primary installation.

Great Post

Worked like a charm.

Thanks

How to remove symlink

I've used the <?php symlink('primary','multisite'); ?> to setup a symlink since i do not have shell access. Is there a way i can remove this please?

Unlinking Symlinks in PHP

Try this: <?php unlink('primary','multisite'); ?>

Is running a pre-production site as a multisite a good idea?

I thought that running a pre-production site as a multisite could be a good idea. Isn't it?

I had a look at the previous posts, considering security, file sharing and cloning questions. Yet in the following situations, I may encounter some problems:

Say that I want to test a new module as if it was on my main production site.
-> The pre-prod site would allow me to test the module at any time (almost) without requiring a maintenance period on my production site.

1- For this, I need my pre-prod site to exactly reflect the production site, at anytime.
-> Do you have suggestions on how to do this? Automated back-ups, manual copy/pasting?
-> How to clone on MacOS X Server? With TimeMachine? Cf.: Yes, it's possible to clone.
-> Is it possible to automate cloning?

1.1- My files folder might be the same for both, as it will become too big in the production site to be duplicated into the pre-prod one.
-> Is an alias sufficent?
-> If possible, what (APACHE2) server instruction might I give?
-> Else, how to do this?

---> If some option works for 1.1, I may have an alternative to multisite config, by just duplicating my production site (without its files folder) and its DB to an each-time-new pre-prod site. But witout automation, I'll loose the possibility for anytime testing of new modules. How to avoid this?
---> I'm aware that in the 1.1 case, I should not test any files related module...

-> The previous two ---> reasons make me ask whether there could be a better alternative to 1.1?

2- Considering we have both pre-prod and production sites in the same drupal folder might cause the security problem you described up there:

-> Which of the site should be the master one?
-> Would it be more secure to have 2 different single drupal instals?

Thank you Alex for this great tuto, and to the other contributors for their hints!

Arsène

As a complement to my

As a complement to my previous post, here are some good infos I glaned about a more secure drupal multi site install:

http://justinhileman.info

It stands for Linux hosting, but I guess will be helpful to other platform users. In his article Justin Hileman claims that his install proposition "keeps individual site content separate, but still maintains all of the advantages of a standard multisite installation (single codebase to update, smaller disk space requirements, etc). it places the drupal codebase in a folder that isn't web accessible, and uses some symlink magic to include only what should be exposed to the rest of the interweb."
(Quote taken from http://cmsproducer.com). )

Cheers, Arsène

  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • Textual smileys will be replaced with graphical ones.

More information about formatting options

Captcha
This question is used to make sure you are a human visitor and to prevent spam submissions.
Copy the characters (respecting upper/lower case) from the image.