Configuring a basic multi-site development environment in Linux
This page describes the minimum required steps for configuring a multi-site development environment on a Linux machine. The steps go through how to set up two development sites with the names
testsite2. By replacing these names with ones of your choice, you can set up your personalized multi-site 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
127.0.0.1 testsite.localhost 127.0.0.1 testsite2.localhost
Step 3: Set up Virtual Hosts
Add the following code to
<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
Step 5: Set up your sites folders
- From the command prompt, navigate to
/var/www/drupal/sites/or wherever you have your sites folder installed.
- Copy the default.settings.php to
The resulting directory structure should contain a folder for each domain name (like
yourdomain.com) with a settings.php file in each folder.
Step 6: Configure your sites to use the appropriate databases
- In the
/var/www/drupal/sites/testsite.localhost/directory, edit the
settings.phpfile 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' => '', ), ), );
- Repeat for
/var/www/drupal/sites/testsite2.localhost/, except replace
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
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/sitesand remove the write permissions for the
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: