Last updated March 7, 2013. Created by phangu on June 10, 2010.
Edited by 2020media, lisarex, Fiable.biz, Tor Arne Thune. Log in to edit this page.

This page describes the minimum required steps for configuring a multisite development environment on a Linux machine. The steps go through how to set up two development sites with the names testsite and testsite2. By replacing these names with ones of your choice, you can set up your personalized multisite testing environment in Linux. The sites will share the same Drupal installation, but will use different databases. These instructions assume that you have the necessary system requirements for Drupal and know how to use a Linux command prompt.

Step 1: Download and uncompress Drupal

It is not recommended to install Drupal through your package manager, as the available Drupal package is usually outdated. You can download and uncompress Drupal by following the steps on the Download and uncompress Drupal page of the Installation guide, as this step does not differ from a normal installation.

Step 2: Set up your hosts file

Add the following lines to /etc/hosts:

127.0.0.1    testsite.localhost
127.0.0.1    testsite2.localhost

Step 3: Set up Virtual Hosts

Add the following code to /etc/apache2/httpd.conf:

<VirtualHost *:80>
   DocumentRoot /var/www/html
   ServerName localhost
</VirtualHost>
<VirtualHost *:80>
    DocumentRoot /var/www/drupal
    ServerName testsite.localhost
</VirtualHost>
<VirtualHost *:80>
    DocumentRoot /var/www/drupal
    ServerName testsite2.localhost
</VirtualHost>

The stanza (paragraph) about /var/www/html is there to preserve the possibility to put non-Drupal sites in that directory. If you want only Drupal sites to be served, you can ignore it. You should also change the directory /var/www/drupal to the location you uncompressed Drupal in step 1.
After this, restart Apache:
sudo /etc/init.d/apache2 restart

Step 4: Set up your databases

Create two databases using the instructions found on the Create the database page of the Installation guide. Name one of them testsite and the other testsite2.

Step 5: Set up your sites folders

  1. From the command prompt, navigate to /var/www/drupal/sites/ or wherever you have your sites folder installed.
  2. The default directory will serve as a template for our other sites. Create a writable files directory in the default directory to make sure every one of your site folders get this directory:
    sudo mkdir -pm 777 default/files
  3. Copy the default directory to create your new site directories:
    sudo cp -a default/ testsite.localhost
    sudo cp -a default/ testsite2.localhost
  4. Rename the default.settings.php files to settings.php and change the permissions to make them writable, so that the web server can access them in step 7:
    sudo mv testsite.localhost/default.settings.php testsite.localhost/settings.php
    sudo mv testsite2.localhost/default.settings.php testsite2.localhost/settings.php
    sudo chmod a+w testsite.localhost/settings.php
    sudo chmod a+w testsite2.localhost/settings.php

Step 6: Configure your sites to use the appropriate databases

  1. In the /var/www/drupal/sites/testsite.localhost/ directory, edit the settings.php file as follows (assuming you are using MySQL):

    For Drupal 6:
    $db_url = 'mysql://testuser:password@localhost/testsite';

    For Drupal 7:

    $databases = array (
      'default' =>
      array (
        'default' =>
        array (
          'database' => 'testsite',
          'username' => 'testuser',
          'password' => 'password',
          'host' => 'localhost',
          'port' => '',
          'driver' => 'mysql',
          'prefix' => '',
        ),
      ),
    );
  2. Repeat for /var/www/drupal/sites/testsite2.localhost/, except replace testsite with testsite2.

Step 7: Run the installation script for your sites

In a web browser, visit http://testsite.localhost/install.php and follow the instructions found on the Run the installation script page of the Installation guide. Repeat for http://testsite2.localhost/install.php.

Step 8: Remove write permissions from your sites' settings.php files

You don't really need to do this, since this is only a development environment, so we're not really concerned about security. Nevertheless, it's a good habit to get into:
From the command prompt, navigate to /var/www/drupal/sites and remove the write permissions for the settings.php files:
sudo chmod a-w testsite.localhost/settings.php
sudo chmod a-w testsite2.localhost/settings.php

Step 9: You're done!

You can visit your sites at:
http://testsite.localhost/index.php
http://testsite2.localhost/index.php

Other resources

Local multi-site installation of Drupal 7 on Linux

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

Hi

Just in case, for people using LAMPP (Xampp for Ubuntu), there is no:

/etc/apache2/httpd.conf

Instead, you can find httpd.conf on:
/opt/lampp/etc/

Greetings!

Nelson C.

Setting up extra config for every virtual host is ok, and certainly if you need specific config that's the only way to go.

However, a lot of projects can actually work on per-server config - and in that case it's much easier to use vhost_alias and VirtualDocumentRoot to map subdirectories to subdomains. I wrote a guide about that:

http://otaqui.com/blog/1652/setting-up-a-virtualbox-virtual-machine-for-...