Drupal Multisite Configurations and Hosts

How do we keep this site running? This post may contain affiliate links — the cost is the same to you, but we get a referral fee. Compensation does not affect rankings. Thanks!

Looking for a good Drupal host?

If you need a solid, reliable website host to host your Drupal multisites, check out Dreamhost. Use promo code We Rock Your Web50 to get up to 50% off your hosting order.

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:

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

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:

 

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

 

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
DocumentRoot /absolute/path/to/drupal
ServerName site-root.com

site-one:
# note that the DocumentRoot is exactly the same for both VirtualHosts
DocumentRoot /absolute/path/to/drupal
ServerName site-one.com

subdomain.site-two.com:
# note that the DocumentRoot is exactly the same for both VirtualHosts
DocumentRoot /absolute/path/to/drupal
ServerName subdomain.site-two.com

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.

Alex bring a series of in-depth articles on search marketing and content management systems as well as troubleshooting tips to We Rock Your Web's collection. He is an avid tennis player, nature enthusiast, and hiker, and enjoys spending time with his wife, friends, and dogs, Bella and Lily.

Leave a Reply

42 Comments on "Drupal Multisite Configurations and Hosts"

avatar
Anonymous
Anonymous

Hi Everyone,

Silicon Valley Drupal User Group is organizing a Drupal Session on MultiSite IN Drupal on 27th May.

Speakers include Karen Stevenson , Fred Davis and Jagdish Harsh.

Some of topics include :

1. Multisite IN Drupal: Challenges and convenience

2. Insights of Non Profit World and their inclination for using Drupal including demo of hivatlas.org

3. Showcase of Drupal IN SaaS Environment

For details please visit http://www.meetup.com/DrupalGroup

on behalf of Silicon Valley Drupal User Group

Anonymous
Anonymous

Hello,

I have no idea if you or anyone is still tracking this post, but I’ve stumbled across it, and find it very helpful…although I haven’t attempted the multi-site thing yet.

You keep talking about pointing to the root installation. I installed Drupal in a subdirectory so I could have example.com free to do a front page or whatever, so right now, I have Drupal in example.com/main (and a index.php doc in example.com that automatically fowards you to the subdirectory.

Now, I would like to have example.com/main be my main site, but I have several other sites that i would like to be example.com/site2, example.com/site3, etc. I do not anticipate having all of these other sites as separate domain names, but some will just be subfolders below example.com.

So, my question is can I install Drupal into example.com/main, and have a multisite at example.com/site2? Will the symlink still work? Or, does it need to be example.com/main/site2?

Thanks.

Anonymous
Anonymous

It would be great to see this article updated to be relevant to Drupal 7 as well as the various ‘cloud’ server/space (and VPS) options now available.

Anonymous
Anonymous

I’ve written up a post explaining the background concepts behind Drupal 7 (and 6) multi-site installs at mikehigginbottom.com/content/drupal-multi-site-installations-magic-secret-bits. It has some specifics but focuses on the stuff you need to understand rather than the steps you need to take, so while it’s not exactly a D7 version of this post it might help set you on the right track to adapt it.

Regards

Mike Higginbottom

Anonymous
Anonymous

Not sure Drupal multisite setups are really worth it. It seems like they’re more complicated than simply setting up a bunch of individual sites. I would say, as a rule of thumb, if you have less than 5 or so sites, set them up individually. If you have more than a dozen, it’s probably a good idea to bite the bullet and set them up in multi-site format, so updating the core and modules won’t take forever.

Anonymous
Anonymous

Hi, I got a Drupal multisite set up quite easily doing the following:

* I got a good hosting provider, then I set my first site up on it
* I got a new domain
* I set a domain addon configuration up on my hosting account (cPanel)
* I set a new DB to host mynewdomain datas
* I set my site to have a new folder in ../sites/ named as my new domain (mynewdomain.com) with setting.php, module folder and template folder
* I set my setting.php to point to mynewdomain DB
* Then I modify NS settings for my new domain to point to my hosting provider
* Finally I got both sites working fine each one with his own template and modules
* Then I added new domains following the same procedure

That’s all.

jdizon363
jdizon363

I have a Drupal based site. The front page is about 200kb and I have 10 trimmed topics in front page. Currently the site is hosted on a shared server. My question is how many hits or page loads per hour/minute should I have before it would be necessary to switch to a dedicated server?

Anonymous
Anonymous

Here is a good article about Drupal multisite with one database, but specific content types per site.

Anonymous
Anonymous

An advantage prefixing gives you is that you can update all the multisites as once.

I would be very happy to learn that the above was true but my research suggest otherwise.

Anonymous
Anonymous

Has anyone managed to get a Drupal 6 multisite installation going on the Mosso Cloud?

Thanks!

Anonymous
Anonymous

Is that possible? I wonder if every domain webmaster/superuser could manage their owns Cpanel.

Regards and thanks for this great post

Anonymous
Anonymous

You write well, thanks.

I am setting up a multi-site Drupal 6.4 on bluehost.com (which appears to be a good environment). If you are going to set up a customised version of say the Garland theme (which allows users to change colors, etc), I think you should first put a copy of the theme directory under the site’s directory and rename it:

/public_html/sites/example1.com/themes/garland_example1/. . .

then activate and use this. This way updates (which now work pretty smoothly) will not affect existing sites.

Anonymous
Anonymous

I’ve used the to setup a symlink since i do not have shell access. Is there a way i can remove this please?

alexc
alexc

Try this:

Anonymous
Anonymous

Worked like a charm.

Thanks

Anonymous
Anonymous

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

alexc
alexc

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.

Anonymous
Anonymous

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

Anonymous
Anonymous

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.

Anonymous
Anonymous

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?

Anonymous
Anonymous

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?

Anonymous
Anonymous

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) ?

Anonymous
Anonymous

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?

Anonymous
Anonymous

Just wanted to say “hi”. Nice website.

Paul

Anonymous
Anonymous

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?

Anonymous
Anonymous

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.

Anonymous
Anonymous

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

Anonymous
Anonymous

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 http://www.example.com while in the default site it works regurarly.

#Basic setup
ServerAdmin webmaster@aaa.bbb.ccc.ddd
ServerName http://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

Anonymous
Anonymous

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.

Anonymous
Anonymous

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?

Anonymous
Anonymous

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,

Anonymous
Anonymous

I created a file named create-symlink.php, and put it in my Drupal root directory. Then I call it from example(dot)com/create-symlink(dot)php. The code for the sample symlink file is below:
I use this method to create a multisite setup for a.com and b.com, both of which refer to c.com as a main domain. I hope this answer is useful.

wpDiscuz

Send this to a friend