Multisite Drupal Set-up on WAMP
Creating a multi-site set-up on your local server or development PC is a must for local development and testing.
A handy practice is to set up one drupal installation and then create your development sites as individual sites on a multi-site set-up.
So say you have a number of sites that you are working on:
Create ons multi-site installation with the following aliases:
and you will have one Drupal installation to manage (modules, themes and core updates etc) and individual sites to work on locally.
Although this tutorial covers WAMP the principle is the same for LAMP and MAMP.
Note: this is relevant to Windows user on non server PCs. Alternative methods are available if you have a Windows 200x server install. This covers both XP and Vista. Windows Server users can set up the DNS host records for each site. A good method for this is to give each the same IP address and use the NameVirtualHost *:80 (substituting the IP address for the *).
Locate your hosts file (C:\windows\system32\drivers\etc) and add a line for the each new site (this is called a 'host' entry) and save the file (note that you will have to associate this with Notepad - I create a shortcut on my desktop for this file since it is used often and saves drilling down to it - the shortcut is C:\WINDOWS\SYSTEM32\notepad.exe "C:\WINDOWS\SYSTEM32\DRIVERS\ETC\HOSTS").
The resulting host file will look something like:
# Copyright (c) 1993-1999 Microsoft Corp. # # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. # # This file contains the mappings of IP addresses to host names. Each # entry should be kept on an individual line. The IP address should # be placed in the first column followed by the corresponding host name. # The IP address and the host name should be separated by at least one # space. # # Additionally, comments (such as these) may be inserted on individual # lines or following the machine name denoted by a '#' symbol. # # For example: # # 220.127.116.11 rhino.acme.com # source server # 18.104.22.168 x.acme.com # x client host 127.0.0.1 localhost 127.0.0.1 drupal 127.0.0.1 local.Antiques.com 127.0.0.1 local.fishing.com 127.0.0.1 local.LocalSoccerTeam.com 127.0.0.1 local.schoolsite.org
1) The next step is to enable the Virtual Host Module in Apache.
To Enable the vhosts_alias_module in Apache (click the WAMP system tray icon browse to Apache->Apache Modules - scroll down to the module and click.
2) Then locate the vhosts config file (e.g. c:\wamp\bin\apache\Apache2.2.11\conf\extra\httpd-vhosts.conf) in your WAMP install folder.
At the top of the file add a line (there is one already for *:80) to allow virtual host resolution by name for your IP address.
Edit this file and add a section for your new sites to correspond with your hosts entries
ServerAdmin info [at] somemail.com DocumentRoot "C:/WAMP/websites/drupal" ServerName drupal ServerAlias drupal ErrorLog "C:/websites/drupal/errorlogs/drupal-error.log" CustomLog "C:/websites/drupal/errorlogs/drupal-access.log" common ServerAdmin info [at] Antiques.com DocumentRoot "C:/WAMP/websites/drupal" ServerName local.Antiques.com ServerAlias local.Antiques.com ErrorLog "C:/websites/drupal/errorlogs/local.Antiques.com-error.log" CustomLog "C:/websites/drupal/errorlogs/local.Antiques.com-access.log" common
Repeat this for each site changing the Server name and Serveralias for each but keeping the document root the same. You can give each a unique error and access log file name too.
3) create an include file in the wamp/alias file - this gets included in the http.conf by the last line Include "c:/wamp/alias/*"
create a file (drupal.conf) to include rights to the new folder That should contain
Options Indexes FollowSymLinks MultiViews AllowOverride all Order Deny,Allow Deny from all Allow from 127.0.0.1
4) Also check that the vhosts conf is set to be included in the httpd.conf file (this should happen when the module is enabled.
# Virtual hosts Include conf/extra/httpd-vhosts.conf
7) restart all services in WAMP
8) I create a folder away from the WAMP install web root (c:\wamp\www\ the default) e.g. c:\websites\drupal and we will install drupal here.
For now create a simple hello world .htm file to go in this folder before adding Drupal files to show the hosts assignment is working.
Browse to http://drupal and this should now go to the drupal install folder and then make sure you can browse to this for each site.
e.g. http://local.antiques.com/hello.htm etc
you keep getting the wamp-www folder directory - this may be due to a number of issues but most likely to an issue with the host assignment
you get a 403 access denied - this is due to the folder permissions. I will create another post to show how to use nested include files to manage this
9) Install/ Copy the drupal files to that new folder c:/websites/drupal/
10) create the databases you are going to use in MySQL and update the settings.php file in c:/websites/drupal/sites/default (remember to keep both default.setting.php and the new settings.php)
Once you have that working you can repeat this step for each of the other sites.
Copy the settings.php (and the default.settings.php) into the root of each and update to use a new database (you can share tables and users by prefixing the tables for each new site and sharing the core tables - see below)
run install.php for each site
Now you should have multiple sites under one code-base (with separate dbs or shared dbs with or without shared tables).
Say you would like to have one database for all sites and share users but keep all other data separate.
1) create a database 'shareddb' and add the following to each of the settings.php files for each shared site.
In this example one site is prefixing the tables with 'ant'. For each other site that will share users choose a different prefix.
See the comments in the settings.php for more details.
$db_url = 'mysql://username:password@localhost/shareddb'; $db_prefix = array( 'default' => 'ant_', 'users' => 'shared_', 'sessions' => 'shared_', 'role' => 'shared_', 'authmap' => 'shared_', 'sequences' => 'shared_', 'profile_fields' => 'shared_', 'profile_values' => 'shared_', 'users_roles' => 'shared_', );
Pros and cons of this approach:
Great for local test setups where you don't want to maintain multiple drupal installs.
Useful for hosting that limits the number of databases you can create or limits disk space (move to a better host is my advice - since most good hosts give unlimited MySQL databases these days - as we do ; )
Shared Databases can be in an issues in terms of single point of failure for multiple sites, hard to deploy from test to live as you can't disentangle the databases if one site needs updating and not others.
Multi-site setups share the same code base and therefore modules. Not all sites have to have the same modules enabled but you can't update one sites module without updating all sites - which may be an issue if one site doesn't support a later module release.
Also multi-sites can access resources on each others file paths.
My own feeling is they are great for test/development suites and less good for production.
- info [at] blue-bag.com
- Telephone: 0843 2894522
- Blue-Bag HQ:
The Garage, Manor Farm
Somerset, BA3 4HP, United Kingdom
- Telephone: (+44) 01761 411542
- Blue-Bag Brighton:
Unit 35 Level 6 North, New England House
New England Street, Brighton
BN1 4GH United Kingdom
- Telephone: (+44) 01273 687900
- VAT GB 748125034
- UK Company Reg: 3932829