How to Set Up Drupal Multi-sites

How to Set Up Drupal Multi-sites

Multi-sites is a Drupal feature that makes managing many websites easier.

The idea with multi-sites is that you can use a single codebase for more than one website. When you update that single codebase, you update all of your Drupal sites. Each site can still have its own theme, modules and content.

With multi-sites you can have many sites with one database, or many sites with different databases.  In this tutorial we will chose to have multiple sites, each with their own database.

We’re going to set up one core installation, and share those files with two sub-sites. Each sub-site will share those files but have its own URL and its own database. In this tutorial I’m going to set up two sub-sites with different URLs:

  • Master site: http://easywebupdate.com
  • Sub-site 1: http://edandrea.com
  • Sub-site 2: http://edsparty.com

Setting up multi-sites is not an easy task for beginners. To make it easier, we’re going to show you how to use your hosting account with cPanel to get this done more easily. If you aren’t using a commercial host with cPanel, your setup process will be slightly different.

Step 1. Choose your master domain name

Your first step is to hoose the URL that will host your main site. As we mentioned, in this example, our main URL will be http://easywebupdate.com.   This doesn’t have to be an important URL. Unless you decide you want it to, this one won’t be used by anyone but you. It’s only going to hold the master copy of your Drupal installation.   It is worth nothing however that this site might be visible if one of your sub-sites fails. So it would be a good idea if your master site had a page with your contact information and a message.

Step 2. Start out by creating databases for all the sub-sites

  • Go to MySQL in cPanel or use the database wizard to create databases for each site you want to add.
  • Be sure to add database users with full privileges to each database. If you want to maximise security, create a new database user for each database. In the example below, I named the databases the same as the URLs. This is recommended on a live site, but it does makes it easy for me to refer to them in the tutorial.
tutuploadsmedia_1332372657629.png

Step 3. Install Drupal in your master URL directory

  • Install Drupal in your /public_html/ directory.
  • Visit the URL (in this case http://easywebupdate.com) and step through the Drupal installation.
  • Use the master database connection information when the install script asks for it.
tutuploadsmedia_1332354346780.png

Step 4. Create a sub-folder for each sub-site.

  • Create a folder under public_html/sites/subsite.com. Substitute the URL you are going to use.
tutuploadsmedia_1332373988030.png
  • Create one folder for each sub-site.
  • Now copy default.settings.php to each one.
  • CHMOD those files to 644 if they aren’t already.
  • If you are doing multi-sites for Drupal 6, you should also create an additional folder called “files” and make sure it’s CHMOD 755.
tutuploadsmedia_1332374012859.png

Step 5. Upload or copy default.settings.php to the new folders

You now need to add default.settings.php to your new folders. The image below shows how file structure looks in Filezilla that makes it a little more obvious.

  • If it is Drupal 6, create a files directory with the path sites/domain.com/files/. You don’t need this extra directory here for Drupal 7.
  • Copy or upload default.settings.php to the folder.
  • Rename it to settings.php.
tutuploadsmedia_1332374565075.png

We are now finished with the Drupal master site. The next part is more complicated because we have to make sure the domain names are correct. Luckily cPanel can do this easily for beginners. We’ll show you that method first. There is a manual method, but it involves making changes in Apache files and this is probably beyond beginner-intermediate skills required of this tutorial.

Step 6. Return to cPanel

  • On the main cPanel dashboard, find the Domains section and click Parked Domains.
tutuploadsmedia_1332375283418.png

Step 7. Add the domain

  • Park the domains on top of the master domain.
  • When you park a domain, the domain needs to be pointed at the DNS servers for your hosting account. If you don’t know how to do this, the proper place to get information is from the domain name registrar. If you don’t know who your registrar is, you get that information your hosting company.
tutuploadsmedia_1332375638592.png

Step 8. Go to your browser and visit the URL

tutuploadsmedia_1332375936533.png
  • In your browser address bar, type the url to your second or third site.
  • Install Drupal by following the prompts.

Step 9. Connect to the proper database

tutuploadsmedia_1332376154830.png
  • When prompted, enter the database information for this specific site.

Result

tutuploadsmedia_1332376922412.png

Three sites, each with their own theme, each with their own modules, all on the same hosting account. To create another site, I just repeat the process. Using cPanel’s parking feature, I was able to avoid the need to make changes to Apache, and the need to make symbolic links or redirects in the .htaccess file.

There is another way to do it that is almost as simple, but if you want to try it you will learn a little more since it involves creating a symbolic link. We’ll give you the code to paste into your site and walk you through it.

Option 2: Quick ways to set up Drupal multi-sites with cPanel Sub-Domains

Go through Steps 1 through 3 of this tutorial. Everything is the same up to that point. In Step 4 you take a slight detour and so Option 2 starts from that point on.

Option 2, Step 4: Create directories for each domain with the convention subdomain.domain.com

tutuploadsmedia_1332378791796.png
  • Create folders for each site you want to create.
  • Create the folder names with this convention subdomain.domain.com.
  • Upload or copy default.settings.php to each directory.
  • Change the name of each copy to settings.php.
  • Return to cPanel home.

Option 2, Step 5: Create subdomains

tutuploadsmedia_1332382035356.png
  • Go to the Domains section and click Subdomains.
tutuploadsmedia_1332382168695.png

The correct directory structure is pictured below:

  1. The directories created by cPanel.
  2. The directories created by you.
tutuploadsmedia_1332382407419.png

Option 2, Step 6: Write a simple php script to create a symlink

In a script editor create a file called mysymlink.php and put the following code into it.

<?php symlink( '/home/cPanel_User_Name/public_html/', 'subdomain' );
?>

In my case the file would look like this

<?php
symlink('/home/myuserdirectory/public_html/','edandrea');
symlink('/home/myuserdirectory/public_html/','edsparty');
?>

Option 2, Step 7: Upload the symlink script to the main directory

To run it go to your browser address bar and type in your url and the name of the file.

http://example.com/mysymlink.php

If all goes well you will see a completely blank page. If you made a mistake in the file you will see error messages.

tutuploadsmedia_1332383456174.png

Option 2, Step 8: Add redirection to your .htaccess file

  • Open your .htaccess file in a script editor
  • Find the line # RewriteBase/ and remove the # sing.
  • Add the following line and save the changes
RedirectMatch 301 ^/subdomain/(.*)$ http://subdomain.yoursite.com $1

Here’s what my .htaccess looked like when finished:

RewriteBase / RedirectMatch 301 ^/edandrea/(.*)$ http://edandrea.easywebupdate.com/$1 RedirectMatch 301 ^/edsparty/(.*)$http://edsparty.easywebupdate.com/$1

This redirection will make it so the site can be accessed in two ways.

http://easywebupdate.com/edsparty and http://edsparty.easywebupdate.com will both be redirected to the same site.

Option 2, Step 9: Visit your subdomain and complete the installation

If you did everything right, you can visit your subdomain and you will now be asked to install Drupal in your subdomain.

More on Drupal Multi-sites

What you’ve seen in this tutorial is just the beginning of the possibilities with Drupal Multi-Sites. There are many optional ways to arrange the code and the data:

  • Multiple domains or vhosts using different databases.
  • Multiple domains using the same database.
  • Multi-site setup using a single Drupal instance.
  • Same codebase, completely different content and users.

One security concernt to note is that Drupal’s multi-site feature is normally used in situations where the administrators for all of the sites are highly trusted. The reason is that anyone with full administrative privileges on a Drupal site can execute arbitrary PHP code on that site through various means, even without FTP access to the site. That arbitrary PHP code could be used from one site to affect another site if the two sites are in the same HTTP document root and share the same Drupal codebase. For more information: http://drupal.org/node/476544 and http://drupal.org/node/1244642.

Author

0 0 votes
Article Rating
Subscribe
Notify of
guest

14 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
jhemsley30
jhemsley30
12 years ago

Great tutorial. Do you know a way that you can do the multisite that shares the same content but allows you to implement changes to the theme and .tpl.php files?? Please help.

thanks,

James

Tazim
Tazim
12 years ago

When i create my subdomain it create a folder automatically out of my main domain folder.

1. where i upload mysymlink.php?

2. what is the path for my multisite folders? my multisite folder in to [url=http://maindomain.com/sites/subdomain]maindomain.com/sites/subdomain[/url]

but my domain folder list style is

[url=http://maindomain.com]maindomain.com[/url]

[url=http://subdomain.maindomain.com]subdomain.maindomain.com[/url]

pls help.

Rashd
Rashd
11 years ago

Nice Tutorial

Abhishek
Abhishek
11 years ago

Hi , Ed Andrea Great Tuturials The first part works completely fine but second part related to subdomains shows up error from step 6 . My hosting company’s cPanel do not support the FollowSymlinks option instead they recommend using the SymLinksIfOwnerMatch option . Can you help what changes are requred in subdomains steps .Thanks Abhishek

swep
swep
11 years ago

I’ve followed the steps and get an internal servor error or a subdomain not found error. I’m trying to run four sites off of one installation of Drupal. I did everything in the precise order. Still no go. Please help!

madjoe
madjoe
11 years ago

There’s a missing instruction in Option 2, Step 5: Delete folders created by cPanel! Then you’ll be able to create symlinks and no error messages will be displayed.

mtkatom
mtkatom
11 years ago

I followed the instructions, but when I update the .htaccess file, I get an Internal Server Error.

And it seems like the Symlinks folders just redirect back to the home site.

Here are my sites:

[url=http://hhmn.org]hhmn.org[/url]

[url=http://northwest.hhmn.org]northwest.hhmn.org[/url]

[url=http://central.hhmn.org]central.hhmn.org[/url]

peprc
peprc
11 years ago

Can you advise the changes needed (if any) to your very enlightening tutorial

– if the multisite is not in root- but installed in a folder such as public_html/mydrupal (accessed as [url=http://mydomain.com/home)?]mydomain.com/home)?[/url]

– and the user wishes to access additional sites [url=http://mydomain.com/sitefolder2]mydomain.com/sitefolder2[/url]

… to use same domain and SSL for all

thank you 🙂

Abhijit
Abhijit
11 years ago

great tutorial but tell me how to do multisite on localhost

nadeem
nadeem
3 years ago
Reply to  Abhijit

you have to set up virtual host. 

Sseggembe Moses
Sseggembe Moses
9 years ago

Thanks alot. this helped.

Dani
Dani
9 years ago

How to configure sites.php in sites directory?

kattie
kattie
6 years ago

how can use same database for all sites and share the content among all sites but having different theme structure ?

Mahtab Alam
Mahtab Alam
4 years ago

How to run drush command specific to a site?

14
0
Would love your thoughts, please comment.x
()
x