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.
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.
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.
OK, to set up multi-sites there are four stages to go through, but it's not difficult:
- Set up your databases, one for each website
- Set up each site in Drupal
- Edit the virtual host settings in Apache
- 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).
Firstly we will set up a new database for 'testsite1'
- Use SQLyog and log into your DB server at localhost.
- 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.
- Repeat for each additional site you want to set up.
- Create a new folder /sites/testsite1. i.e. you should now have two folders in your sites folder, default and testsite1.
- 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.
- 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.
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)
There are lots of other things you can add into your VHost settings - see the Apache documentation.
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:
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.
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)