Multi-site how-tos

Drupal 5.1 Multi Site Configuration

ants01 - March 15, 2007 - 19:43

Example:

1. Create dns entries for the sites ( or use hosts file for testing)
2. Create vhosts in Apache configuration file and restart Apache:

Listen 80
<VirtualHost *:80>
    DocumentRoot "C:/Program Files/xampp/htdocs"
    ServerName localhost:80
</VirtualHost>

<VirtualHost www.site1.local:80>
    DocumentRoot "C:/Program Files/xampp/htdocs"
    ServerName www.site1.local:80
</VirtualHost>
<VirtualHost
www.site2.local:80>
    DocumentRoot "C:/Program Files/xampp/htdocs"
    ServerName www.site2.local:80
</VirtualHost>

3. Create folder sites under drupal/sites

www.site1.local
www.site2.local

Note: Each site folder can have a file, tmp, modules and themes subfolders.

4. Copy settings.php from drupal/sites/default to each site folder.
5. Modify $db_url and $db_prefix in settings.php in each site folder.

For www.site1.local: Single database and db user.

$db_url = 'mysql://drupal:drupal@localhost/drupal';
$db_prefix = 'site1_';

For www.site2.local: Single database and single db user.

$db_url = 'mysql://drupal:drupal@localhost/drupal';
$db_prefix = 'site2_';

For www.site1.local: Multiple databases and single db user.

$db_url = 'mysql://drupal:drupal@localhost/site1';
$db_prefix = '';

For www.site2.local: Multiple databases and single db user.

$db_url = 'mysql://drupal:drupal@localhost/site2';
$db_prefix = '';

Note: Always use the same db user (the one that you used to install drupal for the first time) independently if you want to have a single or multiples db’s.

6. Open your web browser and point to the install.php file for each site

http://www.site1.local/drupal/install.php
http://www.site2.local/drupal/install.php

7. Your new sites are ready using a single code base, single db user and single or multiple db’s.

http://www.site1.local/drupal/
http://www.site2.local/drupal/

Drupal 5.1 Multi-Sites Configuration -- comment

loyeyoung - May 7, 2007 - 20:37

ant01's description is extremely helpful and cogent.

It appears that the instructions contemplate that each site has other content not controlled by Drupal. Thus, www.site2.local and www.site2.local/drupal would have different content. Perhaps the site owner has a static page for product information at the root URL, and the Drupal site is for employees, vendors, or customers.

However, for many of us, Drupal serves all content. If one wants the content for ALL traffic for www.site2.local to be served by Drupal, the following changes would be made:

Step 2: Add "/drupal" to the end of the DocumentRoot statement, so that it reads:

    DocumentRoot "C:/Program Files/xampp/htdocs/drupal"

Step 6: Remove "/drupal" from the path to install.php, so that it reads:
http://www.site2.local/install.php

Step 7: Remove "/drupal/" from the URL:
http://www.site2.local

Depending on your configuration, you may also need to change the RewriteBase from "/drupal" to "/". RewriteBase might be found in your Apache (or other httpd) configuration files or in htaccess, again depending on your configuration.

If you want to have non-Drupal content, but you want the Drupal content to be the default, use RedirectMatch:

     RedirectMatch ^/$ /drupal

The RedirectMatch alternative would still use "/drupal" in the URL of the Drupal site. The URL of www.site2.local would be redirected to www.site2.local/drupal. If the site had other content, such as www.site2.local/foo, content from "C:/Program Files/xampp/htdocs/foo" would be served.

Loye Young
http://www.iycc.net
Laredo, Texas

minor multi-site clarifications

to-john - October 2, 2007 - 19:56

Some minor clarifications for us neophytes

if you get

Warning: Table 'drupalsite1dbnamehere.access' doesn't exist query: SELECT CASE WHEN status=1 THEN 0 ELSE 1 END FROM access WHERE type = 'host' AND LOWER('127.0.0.1') LIKE LOWER(mask) ORDER BY status DESC LIMIT 0, 1 in C:\drupal\includes\database.mysql.inc on line 172

you went to

http://www.site1.local/drupal/

instead of

http://www.site1.local/drupal/install.php

Also, my hosts file got corrupted while messing with this, which may or may not be related to my mucking around with XAMPP and C:\WINDOWS\system32\drivers\etc\hosts, but if you can't seem to figure out why you can't go to http://www.site1.local/drupal, try recreating your C:\WINDOWS\system32\drivers\etc\hosts file. The entries should be

127.0.0.1 localhost [should already be there]
127.0.0.1 www.site1.local
127.0.0.1
www.site2.local

Here's a variation of the httpd.conf file entries that works for me (note the / instead of the \ in the path name)

#Listen 12.34.56.78:80
#Listen 127.0.0.1:80
Listen 80

<VirtualHost *:80>
   DocumentRoot "C:/xampp/htdocs"
   ServerName localhost
   ServerAlias www.site1.local, www.site2.local, www.site3.local
</VirtualHost>

Drupal 6 Multisite - Variable Overrides, Pathauto, mod_rewrite

kmadel - January 21, 2010 - 12:54

Let's say you want to use a single Drupal install to run your company's primary web site and your company's blog site (multisite), but you also have different themes and navigation hierarchies for the two sites. Sure, there are some Drupal modules that may provide most of this functionality. However, you can accomplish exactly the same thing with a plain vanilla Drupal install and the Pathauto module (a module that you should really be using anyways).

Check out the rest in my blog entry at: Drupal Multisite

Don't forget to change the RewriteBase

mennonot - February 8, 2010 - 21:54

If you're installing the second site in a sub-directoy, don't forget to change the RewriteBase in .htaccess. Here are the instructions that worked for me from http://drupal.org/getting-started/clean-urls:

However, if your sites are in different subdirectories, RewriteBase will not work. You will need to create a special rule for each subdirectory. For example, your Drupal installation may serve the following sites:

http://www.example.com/
http://www.example.com/mysite

In order to enable clean URLs for both sites, you will need to add

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/mysite/(.*)$
RewriteRule ^(.*)$ /mysite/index.php?q=$1 [L,QSA]

before the existing rewrite rules.

 
 

Drupal is a registered trademark of Dries Buytaert.