Setting up a Multi-Host Drupal site is so easy it is hard for me to justify using the dedicated configuration. Many web pages document this process and these notes are just a quick reference. Again I assume A LAMP stack, modify as needed. The configuration steps are nearly identical and I will cover both types here.

Slight differences between Dedicated, Virtual host and Multi-Host

The configuration steps can be identical for all three! The main difference is how you point Apache to Drupal area. In all cases I use the multi-host configuration style.

Dedicated One Drupal site per server.
Virtual Each Drupal site gets its own document area, there is no shared code
Virtual All sites use the same document area, but have separate settings files

Create a DNS entry for the site

Don;t forget to create a DNS entry for the site, or use a domain wildcard. Your hosting company probably did this for you already, but it its a good thing to check. Can you ping {your-domain} for example ping If the ping does not resolve to an IP (the ping itself could fail due to firewalls) then contact your ISP or otherwise fix your DNS. You can continue with these steps while that work is in progress but without working DNS your site will NOT WORK. Reverse DNS is not required for this configuration.

Create a home for Drupal

  • Create a directory in your DocumentRoot for your Drupal home. I tend to use the following structure as it make sit much easier in my development environment. Assuming a DocumentRoot of _/var/www
    • mkdir -p /var/www/drupal/sites/my-domain/www
    • This keeps all my Drupal configurations within a single directory with sites being virtual sites with isolated code bases. Each site has its own directory and within that a www. This allows me to keep utilities and other non-Drupal elements with the site but out of Drupal space. Also user if using a source code management system.
  • Unpack the latest Drupal package such that the Drupal root (index.php) resides in the www directory created above

drupal/sites                Area for sites with isolated code bases
  www_canfield_com    Directory named per domain, contains utilities and other elements local to the site
    www                        Drupal home, index.php will reside here
drupal/shared            Area for sites sharing the same code base
    www                        Drupal home, index.php will reside here

Create a site directories

The next step is to create a directory for contributed modules, custom modules, and the local site settings.php file. The following are all relative to the Drupal root (‘www’ in my examples).

  all/                                  All elements shared for all Drupal sites defined in this document root
    modules/                      All modules outside of the Drupal core
      contrib/                      All modules not maintained by me are placed in subdirectories here
        views/                       Views
        cck/                          CCK
        etc...                        Other modules desired
     themes/                      All themes that are shared for sites defined in this document root
       zen/                          etc...         Each site has it's own directory, named per the domain
    settings.php               A custom settings file that holds database connection data

The only trick is the per-domain directory ( in this example). When Drupal processes a request it looks at the host name passed to it from Apache. It will then try and locate the best matching site/* directory it can. It starts using the full domain and then continues to remove sub-domains from the left side until a match is found. If no match is found then the default (part of Drupal) configuration is used. For ease we could have used and then any access to,, would use the configuration. I tend to do all redirection within Apache so my access logs are consistent and search engines all have the same URL. By using the full domain I also allow for other sub-domains to be easily added without having to rename any directories.

Creating a settings.php file

The settings.php file tells Drupal some critical things about your configuration, namely how to access the database. I use the following template for my settings file where the {....} match the values I will use when creating the database.

 # Start with the core (relative to starting directory) – this grabs all of the server wide settings

# Now modify per this site # Quick notes on creating DB # mysql -u root -p # CREATE DATABASE {domain}_com # GRANT ALL ON {database}.* TO {user}’@‘localhost’ IDENTIFIED BY ‘{password}’; $db_url = ‘mysql://{user}:{password}@localhost/{database}’; # Uncomment this to perform an upgrade without a login – should be INACTIVE when running normal #$update_free_access = TRUE;

Create a database

I use MySQL as it is the most popular choice for Drupal and Drupal module writers. While all Drupal code shoudl be databse agnostic, it often isn’t. For high volume sites I prefer PostgreSQL as I find it much faster in overall performance. If using PostgreSQL be prepared to fiddle with some modules or better yet scan for all SQL and verify it works well.

  • Secure your MySQL database – you did that when you installed MySQL, right?
    • I also disable TCPIP in MySQL, I have no need for remote connections in most of my configurations by adding the follwing to /etc/my.cnf
    • skip-networking
  • mysql
-- I use the full domain for the database thus _www_canfield_com_. Again this eases migration from one server to another.
GRANT ALL ON {database}.* TO '{user}'@'localhost' IDENTIFIED BY '{password}'

Creating a named virtual host for Apache

Create a virtual host configuration in Apache. Again, the following is just a quick reference guide

  • I place all virtual host configurations in /etc/httpd/conf/vhosts.d/
    • Modify /etc/httpd/conf/httpd.conf to append the line Include conf/vhosts.d/*conf
    • Create the vhost file, again I use the domain name as the configuration name, in this example
  • The only unusual component is the redirection I use. This causes any sites accessed via the ServerAlias name to be redirected to the ServerName

  <VirtualHost {IP}:80>

DocumentRoot /var/www/drupal/sites/ # I like per-site access logs (but prefer a combined error log, so I leave the error log at defaults) CustomLog logs/ combined # A simple alias that redirects all aliased names to my primary name making thins consistent RewriteEngine On RewriteCond %{HTTP_HOST} !^$ [NC] RewriteRule ^(.*)$$1 [L,R=permanent] </VirtualHost>

Check the configuration (/etc/init.d/httpd configtest) and after correcting any errors reload /etc/init.d/httpd reload.

Initialize Drupal

The final step is to initialize Drupal. Browse to your site via your favorite web broswer and following the directions making any corrections in the configuration as needed.


The following were not discussed and probably should be

  • Securing the site so only you can reach it during initialization, Basic Authentication is a good choice for that.
  • Other security related matters.