I have been reading through the multi-site installation documentation (http://drupal.org/node/167639) and wondered if someone could explain how apache and or drupal determines what site to use based on the domain name, given that the document root is identical in the apache config file?

I had assumed, that an http request is made and the serverName is used to determine the documentRoot to locate settings.php. All of the examples show documentRoot and directory being identical in both Vhosts?

<VirtualHost *:80>
        DocumentRoot /srv/www/htdocs/drupal
        ServerName yourdomain.com
        ServerAlias  *.yourdomain.com
        <Directory /srv/www/htdocs/drupal>
                Allow from all
                Options +Includes +Indexes +FollowSymLinks
                AllowOverride all
        </Directory>
</VirtualHost>

# Same directory and documentRoot ?!

<VirtualHost *:80>
        DocumentRoot /srv/www/htdocs/drupal
        ServerName blueberry.com
        ServerAlias  *.blueberry.com
        <Directory /srv/www/htdocs/drupal>
                Allow from all
                Options +Includes +Indexes +FollowSymLinks
                AllowOverride all
        </Directory>
</VirtualHost>

Thanks in advance

Comments

when you setup your drupal

when you setup your drupal install you have to go into the sites folder and create a folder for each sub-domain. I don't know the details of how the code works but the sites folder would have a folder that is named the same as each of your subdomains and also one that is named the same as your main site.

So for example.com and sub.example.com the sites folder would have a folder named example.com and sub.example.com with the appropriate files in each.

Thanks for your response,

Thanks for your response, Sorry if I wasnt clear. I will not be using sub-domains these are two seperate domains with two completely different sites. I assumed that the NAME of your folder could be anything and had no relationship to your domain name. So if I wanted I could name them default2, default3, default4 and so on for each site. From what I read the naming convention of example.com is only best practice to remember which folder holds what site. Am I completely wrong? If not that still begs the question, how does apache determine which incoming http request goes to which site installation? or is this done by drupal somewhere that I am not seeing?

Thanks

testing

Im going to test the folder names, user perspectoff comments here (http://drupal.org/node/138889) also that its the folder name that MUST match the domain name. Sorry for the doubt if it works ;-)

http://drupal.org/getting-sta

http://drupal.org/getting-started/6/install/multi-site

Most of the info I used when we set up our site was from the above link.

multi site installation

First of all I would recomand a 301 redirect to yourdomain.com with the following lines in apache configuration:

#rewrite the www
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.yourdomain\.com$ [NC]
RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301]

Than you have to create a directory called yourdomain.com in the sites directory.
$ mkdir /srv/www/htdocs/drupal/sites/yourdomain.com (this is an example)

In that directory called yourdomain.com you will copy the default.settings.php to settings.php as you would have done with a normal drupal installation.

Install the normal way...

Let me know - Michel - http://sabatino.name

------------------------
Michel
http://sabatino.name

Multisite and vhosts

I have a combination of these type of configurations and they all work since they are all based off the "requested host name" included in the http header of sent by the browser when it fetches a page.

Apache uses it to determine which vhost - it uses both ServerName and any of the ServerAlias to locate the document root and set permissions.

Drupal does the same thing - so it then uses the host name to determine which directory under sites/ that it should look at.

I have mixed and matched making the split at apache vhost level and at drupal - and its doesn't even matter if the domains are different it all works which ever way you do it. SO I don't think it is necessary for you to put two Identical (apart from ServerName and ServerAlias) vhosts in the apache configuration (but of course you may want other separation - such as separate log files ...)

Just a point to note - although the last poster suggested using the 301 redirects to normalize the domain as seen in the browser (I do the same, but like to keep the www) it is not necessary for drupal. A directory sites/example.com is used by both http://www.example.com (assuming there isn't another directory of that name) and http://example.com

Setting Up Multi Site

After a week of reading all the postings on multisite, I am thoroughly confused. I am setting up an intranet site and wish to utilize subfolders for each successive website off of the root website which does not have a domain name but an IP address. All of the literature reference"mydomain.com" etc. Can you reference an IP address, if so, then do the subfolders become xxx.x.xx.xx.subfolderone etc?

Also, assuming I have properly set up additional folders in the sites folder, what then must I do. The explanations for creation of symbolic links is not clear to me. What file needs to be modified?

IP based and named based virtual domains

You need to realise there are two types of virtual hosting methods.

The original method is to give each virtual host its own ip address and Apache (it works at the apache level) can determine the ip address being requested and can select the virtual host based on that

<VirtualHost 192.168.0.1:80 >
  DocumentRoot /var/www/someplace
</VirtualHost>

Is how you specify that. However, somewhat limiting outside of the local lan environment because of the lack of ip addresses.

So apache then came up with Named Based virtual hosts - this is when the ip address is NOT used (or rather it doesn't need to be - which is why you normally put an * in the virtual host directive)

<VirtualHost *:80>
  ServerName www.example.com
  ServerAlias  *.example.com
  DocumentRoot /var/www/someotherplace
</VirtualHost>

You also need to tell Apache which ip addresses it is listening on should be used for named based virtual hosting. You do that with the "NameVirtualHost" directive. Normally you want it to do named virtual hosts on all addresses and you just put a "*" as the parameter to that directive.

It can ONLY do this because modern browsers send the name of the site they are trying to access in the HTTP headers (and its incidently why https cannot do named based virtual hosting, only IP based - because the headers are encrypted in the https message, but can'd be decrypted until you know which virtual host its pointing at)

AFAIK - Drupal also uses the name of the site being accessed in the HTTP header to decide, in a multisite installation which site under the "sites" directory to look for the settings.php (and everything else it needs) - so you can't really use IP addresses with drupal to run a mulltisite installation

I presume your Intranet has a DNS name server for the name of machines on the intranet. In which case you need to make all the names you want to use point to the same ip address. If not, then possibly they are using the Apple Zeroconf stuff (called Bonjour I believe) where I think it can determine machine names from the names each machine publishes. Again I am not sure, but I think you can tell a single machine to publish multiple names - but from this angle, it is the limit of my knowledge.

If I am just testing on a single machine (say my laptop) I modify the hosts file to include all the names (/etc/hosts in linux something like c:\windows\system32\hosts in windows [sorry I don't often run windows so can't remember precisely - just remember that you have to edit the file in Admin mode, to prevent it giving errors])

Alan:

Thanks very much for taking the time to respond. You indicate that one can't really use IP addresses with Drupal to run a multi-site installation. My Apache hosts file has the IP address associated with 'drupal6' (w/o the quotes). I initially thought I could create files such as drupal6.subsite1 ,etc , then add a prefix to the data base for sharing data bases, and then create virtual links.

I read a few discussions on creating multi-sites on a local computer and thought that perhaps I could use the same approach on a server (re: http://groups.drupal.org/node/35656 )

However, am I correct to state that as a fundamental, initial step towards using a multi-site application of Drupal, I really need to resolve the IP address with a domain name and work with the systems administrators to update the DNS server? After which I would pursue the steps of fixing folder names for the sub sites, configure the various site directories, and then edit the etc/hosts file?

I am not 100% clear what you

I am not 100% clear what you mean by "Apache hosts file has ..." . Under linux, there are files /etc/apache2/sites-available/filename in which you create "filenames" with separate virtual hosts definition. Generally these are then symlinked where ready using the command a2ensite filename to /etc/apache2/sites-enabled. One of the files is called default and is symlinked to 00default to ensure it is referenced first in the /etc/apache2/sites-enabled directory. This is because Apache uses the first virtual host defined to send all requests which don't match any of the others.

The others are matched with a ServerName directive or a ServerAlias directive - but you can use * to wildcard - so you could use

ServerAlias *.example.com

To ensure it picked up all .example.com subdomains. This is probably what you want to do on your intranet.

Folder Names in Drupal sitting under the sites directory can be similarly shortened to example.com to pick up ALL example.com subdomains (assuming there isn't a folder called xxx.example.com - which picks up just that one). But if you point all domains at a single drupal site, then you will probably want to use the "domain" module to manage them (this allows content to be shared across sites - not sure if that is what you want - or it may just be a red herring). I think this is unlikely what you are trying to do - rather you should have a.example.com and b.example.com as separate subfolders of the sites directory and put separate installations in them. In this case, you would (normally) use separate databases for each one.

I am not sure why you mention the etc/hosts file. This is only a local way of defining domain names - this is what you do if you don't want or need anyone else to know that when you refer to xxx.example.com its really pointing at ip address 127.0.0.1 (ie localhost). But if you are trying to get everyone else to see your sites, it will have to be the intranet's DNS server that provides the names. To give you a more concrete example of how I am using it...

... My personal web site will be using drupal soon. At the moment www.chandlerfamily.org.uk points at my server. I have created a drupal test site on my desktop machine with sites/chandlerfamily.org.uk folder set up in it. I have then edited my /etc/hosts file to define test.chandlerfamily.org.uk as 127.0.0.1 and can test using the url http://test.chandlerfamily.org.uk on my own machine. When I am ready to go live, I will move the drupal installation onto my main server and the chandlerfamily.org.uk directory underneath it will support the www.chandlerfamily.org.uk web site.