Comments

ants01’s picture

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/

loyeyoung’s picture

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

to-john’s picture

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>
streulma’s picture

Hello,

here's how to do that with Direct Admin:

- create a subdomain in Direct Admin example: sub.example.com
- you have a subfolder in public_html, delete that folder with the contents
- chmod only the public_html folder to 777 to create the symlink
- create a symlink between public_html and the name of the sub = sub
upload ln.php to the public_html folder and go to http://www.example.com/ln.php
- make a new database in Direct Admin
- copy the /sites/default folder to /sites/sub.example.com
- edit settings.php and correct the database settings
- go to http://sub.example.com, you get errors with table not found, that's good!
- go to http://sub.example.com/install.php and run the install
- That's it!
- to delete a link upload unlink.php to public_html folder
- chmod only the public_html folder to 777
- run http://www.example.com/unlink.php and that's it.

Here's the php code to create the symlink:

$target = '/home/username/domains/example.com/public_html/';
$link = '/home/username/domains/example.com/public_html/sub';
symlink($target, $link);

echo readlink($link);

Here's the code to unlink the symlink:

//set the name of the link 
    $link = "dev";
 
//remove the symbolic link we created before
    unlink("/home/username/domains/example.com/public_html/{$link}");
kmadel’s picture

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

mennonot’s picture

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.

sjdavis’s picture

In an effort to host multiple sites using urls like http://www.mysite.com/drupal_1 I found I needed to have Alias's and rewrite rules for each sub-site in my vhost file:

Alias /drupal_1 /var/www
Alias /drupal_2 /var/www

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

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

Here's a helpful page explaining Drupal multisite in subfolders.

Michael_Lessard_micles.biz’s picture

In the same line of thought, if you use a subdomain for multisites, remember to 'hash' the following .htaccess option:
# RewriteBase /my_drupal_install_folder

Since my Drupal installation is in a subdirectory, I had activated this part in .htaccess :
RewriteBase /my_drupal_install_folder

My multisite subdomain dev.mysite.org has as root /my_drupal_install_folder, so it made no sense for the .htaccess to call for /my_drupal_install_folder

Once I added # before RewriteBase, all worked fine.

Nb - Tip : To create my multisite tables, I simply create a new database and use the phpMyAdmin option to copy all tables to another database. By doing this, you suddenly have an exact copy of your production site! But you'll need to flush all caches for your new multisite (ex.: dev.mysite.org) to work.

Michael Lessard
webmaster of Quebec City "democracy in action" media

rj.seward’s picture

Please see my post at http://drupal.org/node/1032286#comment-4110298 for a D7 multisite install.

donSchoe’s picture

drupal 7 multi-site configuration is very simple, all you need is to read and understand the sites.php

radamiel’s picture

yngens’s picture

There is an alternative Drupal-multisite setup done by Drupion: http://drupion.com/resources/general-information/multi-site-directory-an...