How To Enable Multiple Sites on a Drupal Installation On Ubuntu 12.04

Published on September 26, 2013
How To Enable Multiple Sites on a Drupal Installation On Ubuntu 12.04

Status: Deprecated

This article covers a version of Ubuntu that is no longer supported. If you are currently operate a server running Ubuntu 12.04, we highly recommend upgrading or migrating to a supported version of Ubuntu:

Reason: Ubuntu 12.04 reached end of life (EOL) on April 28, 2017 and no longer receives security patches or updates. This guide is no longer maintained.

See Instead: This guide might still be useful as a reference, but may not work on other Ubuntu releases. If available, we strongly recommend using a guide written for the version of Ubuntu you are using. You can use the search functionality at the top of the page to find a more recent version.


Drupal is a popular content management system (CMS) that is used to quickly deploy websites on sites in an easy to use framework.

This guide will cover how to deploy multiple sites from within a single Drupal installation. We will be installing the latest version of Drupal as of this writing (7.23), on an Ubuntu 12.04 VPS. We will create two separate sites served from a single installation.

Install the Prerequisites

Drupal needs a LAMP (Linux, Apache, MySQL, and PHP) stack installed in order to function properly. We will install the necessary components by typing:

sudo apt-get update
sudo apt-get install apache2 mysql-server libapache2-mod-auth-mysql php5-mysql php5 libapache2-mod-php5 php5-mcrypt php5-gd

You will be asked to create and confirm an administrative password for the MySQL portion of the installation. Remember this for later, as you will have to use it in a moment.

Configure apache to preference .php files over .html files by typing:

sudo nano /etc/apache2/mods-enabled/dir.conf

Add a parameter reading “index.php” as the first item after “DirectoryIndex”:

<pre> <IfModule mod_dir.c>

      DirectoryIndex <span class="highlight">index.php</span> index.html index.cgi index.pl index.php index.xhtml index.htm

</IfModule> </pre>

Save and close the file.

Implement these changes in Apache by restarting the server:

sudo service apache2 restart

Configure MySQL

You can perform a preliminary database initialization and lock down some insecure settings by typing:

sudo mysql_install_db && sudo mysql_secure_installation

You will be prompted to enter the administrative password that you configured during the MySQL installation.

You will then be asked some questions to secure your install. Press “Enter” to answer yes to all of the questions besides the first (changing the admin password again).

Log into MySQL by typing the following:

mysql -u root -p

You will be given a MySQL prompt to input further commands. We need to create one database for each site we will be creating:

<pre> CREATE DATABASE <span class=“highlight”>firstsite</span>; CREATE DATABASE <span class=“highlight”>secondsite</span>; </pre>

Next, create a user and password combination for each site and grant it privileges on the databases you just created:

<pre> GRANT ALL ON <span class=“highlight”>firstsite</span>.* TO <span class=“highlight”>firstuser</span>@localhost IDENTIFIED BY ‘<span class=“highlight”>firstpassword</span>’; GRANT ALL ON <span class=“highlight”>secondsite</span>.* TO <span class=“highlight”>seconduser</span>@localhost IDENTIFIED BY ‘<span class=“highlight”>secondpassword</span>’; </pre>

Apply the changes and exit the MySQL environment by typing the following commands:


Download and Configure Drupal

We will download the Drupal sources into our home directory from the project’s repositories:

cd ~
wget http://ftp.drupal.org/files/projects/drupal-7.23.tar.gz

Extract the files and then more them into the webroot of the server. We will store all of the drupal files inside a separate “drupal” directory:

tar xzvf drupal-7.23.tar.gz
sudo mv drupal-7.23 /var/www/drupal

Next, we will copy the default settings file into a valid settings file:

cd /var/www/drupal/sites
cp default/default.settings.php default/settings.php

Drupal needs write access to the directory and the files within during installation. We can assign write permissions like this:

sudo chmod -R a+rw default

Next, we will have to figure out how we are going to serve the sites from subdirectories or sub domains. Choose the appropriate section to follow below.

Serving Multiple Sites Using Subdirectories

Drupal can be configured to serve separate sites out of subdirectories from a centralized domain. For example, you could have “example.com/site1” and “example.com/site2”, each having separate content, themes, etc.

How Drupal Associates Requests with Directories

First, you need to understand that Drupal resolves requests for domains that get passed to it by looking at the directory structure within the “sites” directory.

The “default” directory describes its function perfectly. It is contains the default content served if no other matches are found.

We want to create other directories that will match our site subdirectories, however. We do this by simply specifying the main domain name for the site (without the “www”), followed by a dot instead of a slash, and the subdirectory name.

For instance, a site that is accessed by going to “http://www.example.com/firstsite” should be given a directory called “example.com.firstsite”.

Create the Site Directories

We will copy the default directory we configured earlier to two separate directories within the “/var/www/drupal/sites” directory.

We will use the “-a” flag to preserve permissions, since we will also need those same permissions for each of the Drupal sites we are creating:

<pre> cp -a default <span class=“highlight”>example.com</span>.<span class=“highlight”>firstsite</span> cp -a default <span class=“highlight”>example.com</span>.<span class=“highlight”>secondsite</span> </pre>

We now have the directory structure that will handle the requests for those sites, but we haven’t made any changes that will direct the traffic Apache is sorting through into Drupal.

We will do this by creating symbolic links to the drupal root directory from within the web root directory, each describing our sites:

<pre> sudo ln -s /var/www/drupal /var/www/<span class=“highlight”>firstsite</span> sudo ln -s /var/www/drupal /var/www/<span class=“highlight”>secondsite</span> </pre>

Now, you can set up your separate Drupal installations by navigating to:


Be sure to enter the separate database information you configured for each site.

Serving Multiple Sites With Independent Domains

If you have bought two completely separate domains, you will preform most of the same procedures that are used in the subdirectories method above, but you will have to name the directories differently, and you must modify the Virtual Hosts file to configure the domains.

We will assume in this section that your domains have both been pointed at your VPS. We will use the names “firstsite.com” and “secondsite.com” to distinguish.

Go to the Drupal sites directory if you are not already there and copy the default again to appropriately named sub-directories. Remember, do not include the “www” in your naming convention.

<pre> cd /var/www/drupal/sites cp -a default <span class=“highlight”>firstsite.com</span> cp -a default <span class=“highlight”>secondsite.com</span> </pre>

Configure Apache Virtual Hosts

Again, we need to be able to inform Apache how to pass the correct domains to Drupal. We will do this with a Virtual Hosts file.

Go to Apache’s sites available directory and create a new Virtual Hosts file for Drupal:

cd /etc/apache2/sites-available
sudo nano drupal

You need to point both of your names to the drupal folder in the webroot in this file. Use this format:

<pre> <VirtualHost *:80> DocumentRoot /var/www/drupal ServerName <span class=“highlight”>www.firstsite.com</span> ServerAlias <span class=“highlight”>firstsite.com *.firstsite.com</span> </VirtualHost>

<VirtualHost *:80> DocumentRoot /var/www/drupal ServerName <span class=“highlight”>www.secondsite.com</span> ServerAlias <span class=“highlight”>secondsite.com *.secondsite.com</span> </VirtualHost> </pre>

Save and close the file.

Enable the new site configuration by typing:

sudo a2ensite drupal

Reload the server configuration:

sudo service apache2 restart

Your sites should be available to set up in your browser (assuming you set up your domain names correctly) by visiting:


Serving Multiple Sites Using Subdomains

A third way that you can configure this to serve separate sites is through the use of subdomains within a single parent domain.

For instance, we could have one site located at “first.example.com” and a second located at “second.example.com”.

To complete this, we start again with creating the appropriate site directories:

<pre> cd /var/www/drupal cp -a default <span class=“highlight”>first.example.com</span> cp -a default <span class=“highlight”>second.example.com</span> </pre>

Create an Apache Virtual Host file to point your base domain to the “drupal” subdirectory within the document root:

cd /etc/apache2/sites-available
sudo nano drupal

Put the following basic configuration in the file:

<pre> <VirtualHost *:80> DocumentRoot /var/www/drupal ServerName <span class=“highlight”>www.example.com</span> ServerAlias <span class=“highlight”>example.com *.example.com</span> </VirtualHost> </pre>

Save and close the file.

Enable the new site by typing:

sudo a2ensite drupal

Reload the server configuration:

sudo service apache2 restart

Your sites will be available for set up in your browser by visiting:



You now know how to configure multiple, unrelated sites on a single Drupal instance. Keep in mind that this might not be the best solution in all instances.

Because the core Drupal logic is shared, you must trust the administrators of all of the separate domains. If you are managing all of the sites and they have similar requirements, then this might be a great solution.

<div class=“author”>By Justin Ellingwood</div>

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

As an alternative you can try use Wodby. It works like that: you connect your DigitalOcean account and Wodby creates CoreOS droplet and install docker infrastructure on it. Then you deploy your Drupal website in a click from the Wodby dashboard, every drupal website has integration with varnish and redis out of the box.

Also, you can deploy many websites on one server and they will be completely isolated thanks to Docker.

When times comes to run updates, do I need to run the updates on each site separately or is there a way to update both sites (multiple sites with independent domains) at once?

Lets try that again.


The only change I would recommend to this tutorial is granting


This is a much more secure method.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel