Here's how to get mutltiple sites working on localhost using Windows XP. NB: This post was originally written for Drupal 4.6.x but has been updated for 6.x so some of the comments below are now obsolete.

Preparation

This page assumes that you have PHP, Apache, MySQL and Drupal all installed and working and have a MySQL admin tool available; the free community edition of SQLyog will do nicely, or you can use phpMyAdmin if you prefer. Again, I'll assume you've got one of these installed and connected to your database server. I'll use SQLyog here.

If you don't yet have PHP, Apache and MySQL installed then XAMPP will help! See also http://drupal.org/node/161975

Finally, I'll assume you're starting with a working D6.x installation, have followed the installation instructions and got the default site up and running. If not, start here http://drupal.org/getting-started/install.

Multi-site setup

OK, to set up multi-sites there are four stages to go through, but it's not difficult:

  1. Set up your databases, one for each website
  2. Set up each site in Drupal
  3. Edit the virtual host settings in Apache
  4. Update the Windows hosts file

In the following example we will add a local site"http://testsite1" in addition to the default site. We'll assume Drupal is installed in c:/www (and that your web root is set to c:/www in the apache config file, apache\conf\httpd.conf).

1. Databases

Firstly we will set up a new database for 'testsite1'

  1. Use SQLyog and log into your DB server at localhost.
  2. Ctrl+D to create a new database. Type a name for your database in the 'create database' textbox ('testsite1' is as good as anything) then click the create button. A new database outline will be added.
  3. Repeat for each additional site you want to set up.

2. Drupal

  1. Create a new folder /sites/testsite1. i.e. you should now have two folders in your sites folder, default and testsite1.
  2. Make sure the folder /sites/default contains an unmodified copy of the file default.settings.php. The installer script will look for this file when installing your new site and the install will fail if it ain't there. If necessary, extract a copy from the drupal install package.
  3. Also place a copy default.settings.php in the testsite1 folder and rename it settings.php. Make sure the file is writeable (i.e. the 'read only' attribute is not set) because Drupal will modify this file as part of the installation process.

3. Apache

1. Open the apache config file '\apache\conf\extra\httpd-vhosts.conf'.

2. Scroll to the end of the file, where you will find the virtual hosting setup. Assuming your websites are all located in the folder c:/www then add the following lines (edit the paths as necessary)

NameVirtualHost *:80

<VirtualHost *:80>
   DocumentRoot c:/www/
   ServerName localhost
</VirtualHost>

<VirtualHost *:80>
   DocumentRoot c:/www/drupal6
   ServerName testsite1
</VirtualHost>

There are lots of other things you can add into your VHost settings - see the Apache documentation.

4. Windows

We now need to tell Windows that the domain 'testsite1' is hosted locally, i.e. not to look on the Internet for it. Open the 'hosts' file with notepad. It can usually be found in c:/windows/system32/drivers/etc

Edit the end of the file to read:

127.0.0.1 localhost
127.0.0.1 testsite1

Save the file.

When working offline -without any Internet connection- with a local test site, the Windows service DNS Client (see Control Panel -> Administrative Tools -> Services) can be necessary to read and parse the hosts file. This is optional when the PC is online.

Apache, again

OK, that's (almost) it. All that is left is to restart the Apache webserver. You could reboot your computer but a better way is to open a command prompt window and type 'net stop apache'. When the service has stopped, restart it using 'net start apache'. If you're using XAMPP then use 'xampp stop' and 'xampp start'.

Now when you open your favourite browser and enter 'http://testsite1' you should see the installation page for your new Drupal site. Enter the database details you created earlier and let the installer script set up the tables for you.

You can add as many sites as you need by following the process above.

Optional additional configuration

Although not essential, here are some things to help keep things tidy in a multi-site setup.

Use a separate files folder for each site

By default, all images and other uploaded files are kept in a single folder. Whilst this works, its a bit messy and better to set up a separate files folder for each site.

  • Set up a separate 'files' and 'files/tmp' folders by creating the folders in your sites directory, i.e. sites/testsite1/files and sites/testsite1/files/tmp, sites/testsite2/files, sites/testsite2/files/tmp etc.
  • Update the settings for each site by visiting 'admin/file system' and changing the path for the files and temp folders to sites/testsite1/files, sites/testsite1/files/tmp...etc.

Consider the best place to install modules and themes

  • If you have modules or themes that you want to share between all sites then store them in sites/all/modules and sites/all/themes respectively.
  • If you want them to be available only to one site then store them in sites/testsite1/modules and sites/testsite1/themes (replacing 'testsite1' with your actual site name)

Comments

druvision’s picture

Notes:
1. It's also possible to add sites as subdomains of localhost. Configuration is similar. Advantage: it's easier to distinguish between the local and the remote site if they have the same name.

2. I've tried running multiple sites from the same codebase using XAMPP. Here are my XAMPP multisite config tips.

Amnon
-
Drupal Focused Search Engine | Drupal Israel
Personal: Hitech Dolphin: Regain Simple Joy :)

peterbeauclerk’s picture

I have successfully installed a drupal local testsite with Xampp and I am attempting to set up 4 sites to run on localhost
Following the instructions at "Running multiple sites on a local PC (localhost) from a single codebase, using Windows" ( http://drupal.org/node/32715 ) I have created 4 databases and attempted to execute this instruction:
"3. Next we need to add the necessary tables. Click the 'sql' tab, then use the browse option to navigate to the 'includes' folder of your Drupal installation, e.g. c:/www/drupal-4.6.3/includes. Select the file 'database.mysql.inc' then 'go'."

When I did this it generated the following error message:
"

Error

"There seems to be an error in your SQL query. The MySQL server error output below, if there is any, may also help you in diagnosing the problem

ERROR: Unknown Punctuation String @ 1
STR: <?
SQL: <?php
// $Id: database.mysql.inc,v 1.89 2008/01/24 10:46:54 goba Exp $" (quotation marks added by me)

It then displayed the code for the database.mysql.inc file as installed by the drupal installation and unmodified by myself.

I have scrutinized the code, but with my very limited knowledge of PHP & HTML I haven't been able to spot any discrepancy. There were no problems loading the 'drupal' database on the original install, and I have not modified the file myself..

Could there be a compatibility problem with the instructions being for drupal 4.57 (I have drupal 6.6)?
As a newbie I do well with step by step instructions.
Any help much appreciated
Peter

chetdude’s picture

I'm not showing a Browse button...

Bummer...

I tried pasting in the contents of the database.mysql.inc file and got a puncuation error on the first line.

I suspect that you've skipped a step or they've changed phpMyAdmin since you ran this....

So...I'm stuck on the 2nd step...

Ok, the browse "option" was hidden under 2 more windows.

Now I'm getting the same error running the script that peterbeauclerk got...

Double-Bummer...

HELP???

Geared’s picture

I ran into the same MySQL database errors when trying to setup multiple sites using the guide above. I have a few ideas why that might be happening but like other following this tutorial not enough MySQL knowledge to troubleshoot the problem.

I found another guide that will help you manually setup the database. You can follow this guide through to create multiple sits or you can just use the database portion and finish this guide. They are both very similar, just slightly different MySQL steps for the most part.

This should work, because I had the same errors and I am now developing multiple sites locally.
Good Luck!

http://drupal.org/node/322363

murraybiscuit’s picture

Step one refers to a php include, not and sql include file. It looks like the database has to be set up from the drupal install page on your domain. Therefore, step two will not work.

nitetalker’s picture

... whereas this — Creating Multiple Sites On a Local Computer — did not.

Kecia’s picture

I have spent two nights trying to set up multi-sites to run locally. I followed these instructions and when I try to access the second site at http://127.0.0.1/litterbox/ I get:

The requested URL /litterbox/ was not found on this server.

Maybe I'm incorrect in thinking I can set up multiple sites that use a different database? I thought you could do that if you point the settings.php to the correct database.

If I go to: http://127.0.0.1/drupal/
Then I get the welcome page to Drupal. It seems that it's not even going to the sites folder.

If I type in a folder name within the sites folder I get URL was not found error.

My tree is set up like this:
www
drupal
sites
default
litterbox

All the instructions I have found sound easy and I understand what I am doing. However, nothing is working.

I'm using Drupal 6 with WAMP. Any help is greatly appreciated!!

Thanks!
Kecia

JoachimF’s picture

I found that is you alter the '\apache2\conf\httpd' as well as the '\apache\conf\extra\httpd-vhosts.conf' with the same virtual host settings then things should work...

NameVirtualHost *:80


DocumentRoot c:/www/
ServerName localhost


DocumentRoot c:/www/drupal6
ServerName testsite1

Jamie Holly’s picture

One thing that sucks with Windows is that you can't use wildcards in your hosts file. Every time you want to do a new site you need to go to your hosts file and add that domain in. In the past I ran Bind9 on my box you configured my own .dev zone for everything. Talk about overkill. Today I found Acrylic and it is the answer for all of us.

http://mayakron.altervista.org/support/browse.php?path=Acrylic

It's an open source DNS proxy and is very lightweight. You just configure it to use your regular name servers and then set your network's primary DNS to point to your localhost. The power of it is you now have a AcrylicHosts.txt hosts file which supports wildcards. In my case I just added *.dev to the list and now I got my own development TLD running here at home. For those wanting localhost just add *.localhost. Then all you have to worry about doing is adding in your new VHost to Apache. Can't get much simpler than that.

---------------------

HollyIT - Grab the Netbeans Drupal Development Tool at GitHub.

MehmetKozan’s picture

I try Acrylic dns proxy. It works well sometimes but I have to refresh the browser continuously because of server not found err.refresh the browser firefox ie explorer chorme whatever and it works. if I add .*dev to windows host file as
127.0.0.1 multisite1.dev
127.0.0.1 multisite2.dev
127.0.0.1 multisite3.dev
it works well and not need to refresh browser
can you fix that problem ?

Jamie Holly’s picture

I've been using it for a couple of years without any problems. I didn't write the program. I suggest contacting the author on the link I posted about the issue.

---------------------

HollyIT - Grab the Netbeans Drupal Development Tool at GitHub.

MehmetKozan’s picture

I just need suggestion only a user who use this program efficiently. I can fix the source code if the program written in c , c++ but written in pascal. In windows 7 if you turn off windows dns cache, the program not working any way. I think the problem is that the dns proxy response too fast for "*.dev" and windows 7 waiting for the response of server. If i add about 10000 fake entry in host file before "*.dev" it works perfect.

Jamie Holly’s picture

It could be something with the newer versions. My version is from January of 2009. I've been running that version on Win 7 64bit since October of that year and never had a problem.

Here's my INI file, in case that helps

[GlobalSection]

PrimaryServerAddress={removed}

SecondaryServerAddress={removed}

TertiaryServerAddress={removed}

AddressCacheNegativeTime=1

AddressCacheScavengingTime=5

AddressCacheSilentUpdateTime=5

LocalBindingAddress=0.0.0.0

LocalBindingPort=53

HitLogFileName=

HitLogFileWhat=BHCFR

[AllowedAddressesSection]

[CacheExceptionsSection]

[WhiteExceptionsSection]

As far as my regular Windows HOST file, all I have in there is an entry for localhost. That's just to get past the bug with PHP (5.3+) not wanting to connect to MySQL locally if it's not there. Then I have:

127.0.0.1 *.dev

In my acrylic hosts file.

---------------------

HollyIT - Grab the Netbeans Drupal Development Tool at GitHub.

mechdrupal’s picture

hi! im new to drupal and new in making websites. I have successfully installed multisites (virtual) w/ different databases. I have read many threads but can't seem to know (seemed lost)how to reach my goal.
Actually my goal is to make 4 really different websites A,B,C,D and be viewed in internet as different domains using one single PC webserver-using win7 & XAMPP.

multisite ---viewed
default >>> A.com
site1 >>>>> B.com
site2 >>>>> C.com
site3 >>>>> D.com

i know drupal can do this. can anyone give me the necessary links on how to do this? id be really thankful..

Anonymous’s picture

On my laptop (WAMP) I have set up a drupal 6 using drupal-6.17.tar.gz. It resides in directory \htdocs\drupal6.
The basic installation works fine, there are no additional modules and themes installed yet.

Now I want to turn this into a multisite installation following the steps above:

1. created a new database on mysql using phpmyadmin, using the option to create a new user and an equally named database, giving the new user all rights for this database.

2. copied the folder sites\default to sites\florenliste.de (the new subsite shall be adressed http://florenliste.de on my laptop). Deleted the settings.php and renamed default-settings.php to settings.php. checked, that it has write-permission.

3. Added this to httpd.conf (and restarted apache-service):

# Use name-based virtual hosting.
#
NameVirtualHost *:80


DocumentRoot c:/programme/apachegroup/apache2/htdocs/
ServerName localhost


DocumentRoot c:/programme/apachegroup/apache2/htdocs/drupal6
ServerName florenliste.de

4. added this to \etc\hosts:

127.0.0.1 localhost
127.0.0.1 florenliste.de

When entering -http://florenliste.de- in a browser, the install.php is started as expected.

These steps I pass:
- choose a profile (Drupal)
- choose a language (I tried both English (built in) and German
- verify requirements is passed with green checkmark
- and I get to the screen for Database configuration

I enter database name, database username and database password for the newly created user and database. After hitting "save and continue" I get the same entry form again. At this point the install.php hangs and I can continue entering the three required parameters again and again. (Writing typo's on purpose produces the correct error messages: failed to connect to mysql database server ....)

Looking at phperrors.log I find this warning, resulting from the posting of the database configuration form:
[06-Jul-2010 12:12:52] PHP Warning: fopen(./sites/default/default.settings.php) [function.fopen]: failed to open stream: No such file or directory in C:\Programme\ApacheGroup\Apache2\htdocs\drupal6\includes\install.inc on line 188

Has anybody got an idea what might be wrong? Did I miss an important thing that is so self-evident that no-one needs to write it down?
Quick help will very much be appreciated.

Rudolf

MarkRennes’s picture

When you try to edit the Windows Apache config file '\apache\conf\extra\httpd-vhosts.conf', you may find that you cannot save the file; the error message will be something like:

"
Save failed
Please check whether if this file is opened in another program.
"

This is because it is necessary for the software changing this file to run at an elevated level of security. You should normally only change system files with an editor such as Notepad++ (rather than Notepad); on the assumption that you have previously installed Notepad++:

* type notepad++ (in the search bar) to find the program
* right click notepad++ in results
* select 'run as administrator'
* within notepad++ you can then open/edit/and save the hosts file

supradhan’s picture

Hi,

I followed the step (Drupal 7.2.***) and it worked as expected. But my problem is it is working only when I am not connected to internet. Whenever I connected to internet it is giving me error 'Description: Unable to locate the server named "drupal2" --- the server does not have a DNS entry. Perhaps there is a misspelling in the server name, or the server no longer exists. Double-check the name and try again. '
I tried making apache online/offline but it didn't work.

Please help.

Some of the world's greatest feats were accomplished by people not smart enough to know they were impossible...- Doug Larson