Drupal’s multi-site capability has been around for quite some time. Site builders are able to spin up multiple sites, using the same code base, by creating a folder in the sites directory that matches the host name and path. On a production server the URLs never change, but if you want to create a local development version of your multi-site setup that’s where things get complicated.
For example, if your site domains are “example1.com” and “example2.com”. All you would have to do is create two directories called “example1.com” and “example2.com”, then create a file called settings.php in those directories and you’re done. You can place themes and modules within the specific directories and they’ll only appear on those sites. Your sites directory should look like the following:
When Drupal gets bootstrapped, it’ll look for a directory in the sites folder which matches the URL. If a folder is found it’ll use the folders settings.php to load the site. Open the default.settings.php
in the default folder for a more detailed explanation. The same applies when you create a local development version. If your local URLs are “example1.localhost” and “example2.localhost”, then you’ll also have to create a folder within the sites directory. When you have specific modules and themes within those site directories, managing the codebase with a version control system becomes very painful.
Luckily this issue has been fixed in Drupal 7 thanks to the sites.php
. The sites.php
is stored in the sites directory, if you have installed Drupal 7 you should see a file called example.sites.php
. Rename example.sites.php
to sites.php
, then uncomment and change the $sites
array as needed.
/** * Multi-site directory aliasing: * * Edit the lines below to define directory aliases. Remove the leading hash * signs to enable. */ $sites['example1.com'] = 'example1.com'; $sites['example1.localhost'] = 'example1.com';
im not a techie person. please bear with me. Im on a webserver
.1. I created the sql database.
2 a website folder in sites called teg,
3. copied settings.php without changing it
4. copied and renameexample.sites.php to sites.php,
but still getting problem when trying to install drupal… e.g http://www.abc.com/teg/install.php
Help
should i have amended the settings.php file and put in the actual name of the database and password, or should i leave it as is?
when im in the sites file, should it be $sites[www.abc.com/teg’] = ‘teg’;
holla at me please man
Try defining the site like this:
$sites['www.abc.com.teg'] = 'teg';
Notice the
www.abc.com.teg
You need to following Drupal’s auto discover rule. Read the comments within the default.settings.php (http://drupalcode.org/project/drupal.git/blob/refs/heads/7.x:/sites/default/default.settings.php)
So you are using example2.com, but I dont see that in your $sites variable in your code above? I dont get it. Also, is this aliasing thing got to do anything with vhosts and domain names? Thanks
example2.com is not in the code example because all I would be doing is duplicating the first two lines.
Regarding your question about vhosts and domains. Yes, you must setup the domain properly and the vhost on the server. Here’s a page on setting up multi-sites, http://drupal.org/documentation/install/multi-site
great site!
how do you ensure clean urls for multisites during initial drupal 7 install? i know you have to override/overwrite something in /etc/apache, either in the enabled or available sites, right?
Setting up clean URLs is a separate issue to setting up multi-sites. To setup clean URLs just make sure you enable the mod_rewrite apache module.
http://drupal.org/project/multisite_wizard – very simple to use!
Thanks, I’ll check out the module.
I need a Drupal 7 website with 2 sections…
for eg. http://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: http://www.example.com/Civil
section 2: http://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.
First of all understand that it is difficult for me to offer a solution because I don’t know the exact requirements for your website.
Looking at Themekey module is a good start. Also, look at the Domain access module (http://drupal.org/project/domain).
A multi-site setup is good if you want to share a single codebase, but each site will have their own databases. You can share database tables between sites but I don’t recommend it unless you know what you’re doing.
Hello Ivan,
I want a Drupal 7 website with landing page and two sections with different templates
I have a domain xyz.com
when we try xyz.com, we will see a page with two links…one for a section called Civil and the other is called MEP.
For both civil and MEP ,there will be different menu items and the layout is different.
so the link from the landing page may be xyz.com/civil and xyz.com/mep.
I don’t want sub domains for this.
Please check this:
http://drupal.stackexchange.com/questions/70596/drupal-7-website-with-landing-page-and-two-sections-with-different-templates/
I think this is not a multisite.
What do you mean by “templates” are they 2 separate Drupal themes? If it’s 2 separate themes, then things will get complicated.
I would keep everything in a single theme and change the design using CSS and template overrides. One of the comments on stackexchange (http://drupal.stackexchange.com/a/70603/247) explains it pretty well.
Hi
do you have some tips for a faster drupal multi-sites? any tutorial ?
thanks
MassiMo
It all comes down to how your hosting infrastructure is setup (database and web server). Most of the techniques used for speeding up a single site can be used on multi-site setups.
Check out the link below:
http://friendlymachine.net/posts/2011/5-ways-to-improve-performance-in-drupal
I have multisite with same codebase installation on my server. One of the site have 5 urls means I have to redirect from all of the five to same site folder(site-1). I have made 1 url as base url in settings.php. I have configured all the five URLs in sites.php to hit on the site folder (site-1). Now when I try to access the site with these 5 urls, I got the website correctly with ist url(base url in settings.php) but when I try to access the site with other 4 urls I got the website content but without CSS. Means CSS is broken in other 4 urls.
Please suggest any solution.
Thanks
Amit
I really can’t answer this without spending time investigating the problem. See if you can get it working with 2 URLs instead of 5.
Hi, I have 2 sites on my server. They are working fine but when I connect to one of them from outside, it is showing the ip address of the server (for example when I hover a link). I configured everything right I think, hosts and vhost files, .htaccess, settings.php and sites.php but I can’t find the problem. Do you have any suggestion?
Thanks, Linh
*They are working fine but when I connect to one of them from outside, it is showing the ip address of the server (for example when I hover a link).*
So the links are appearing as an IP, not a domain?
Try setting the `$base_url` in the `settings.php` file and see if that fixes the issue.
I did change the $base_url but the problem remains.
You’ll have to research it further, I don’t know what the problem could be.
I think I found the problem but I don’t really know how to fix it. The first website that showing the IP uses the settings.php of the default folder. But when I change the $base_url in that file, then the blocks and the CSS don’t work anymore. Any thought?
Sorry, I’ve never had this problem. You’ll have to investigate the issue further.
Druapl 7 solutions for https://www.webwash.net/comment/739#comment-739
I completed this by using
URL aliases
theme key-THEME SWITCHING RULE CHAINs
You can find answers in http://drupal.stackexchange.com/questions/70596/drupal-7-website-with-landing-page-and-two-sections-with-different-templates/
Hope this will be helpful.
Thanks for the update.
Hi Ivan!
I have a multisite configuration but my websites come from repository with a different kind of tree directory..
Was upload like this:
—–example1
|__src
|__module
|__themes
—–example2
|__src
|__module
|__themes
How can i set to Drupal see theses folders inside “src” ?
example
______|src
_________|modules
_________|themes
Hi Sofia,
I have no idea.
You’ll need to change how Drupal autoloads, look at https://www.drupal.org/docs/develop/coding-standards/psr-4-namespaces-and-autoloading-in-drupal-8 for more details.
Cheers,
Ivan
can We use same database for two domain like domain1.com and domain2.com
But I want to share the content in both domain .If i change in domain 1 content . It will show changes in domain2
But i want to use different layout different menu and different footer and different footer . How can I achieve this ?
Hi manmeet,
Multi-site is only useful if you want to use the same codebase, but each site has it’s own database.
What you want to do will be difficult because the configuration (layout) is still in the database.
Look at domain access module https://www.drupal.org/project/domain
Cheers,
Ivan