Multisite CVS Drupal Installation on Ubuntu


This howto shows you how to do a multi-site Drupal install on Ubuntu. It also covers how to layout your directories for ease of maintenance, and how to ensure that you can update Drupal easily from CVS.

Why go to all this bother? Why not just install Drupal using sudo aptitude install drupal? The answer is that as your website gets more popular, you're going to need to keep up to date with security patches, as well as manage all the custom modules you've installed. Also, it's nice to have one website as your main site, and a second one where you can test new Drupal features, modules or ideas. And who knows, after your first successful website, you'll probably want a second and third one (I know I did), so let's make it easy from day one.

I developed and tested this howto on an Ubuntu Edgy Desktop VMWare image downloaded from the VMWare Appliances Directory - it should also work (with minor changes) on other versions of Ubuntu and Debian.


Configure DNS

We're going to create websites for and (change these domain names to suit your requirements). Let's configure DNS so that you can start developing immediately - you can setup Bind and register your site later.

Enter these commands:

sudo bash
echo "" >> /etc/hosts

Check this has worked by using the ping command - you should get a reply back from localhost (

$ ping -c 2
PING ( 56(84) bytes of data.
64 bytes from localhost ( icmp_seq=1 ttl=64 time=0.035 ms
64 bytes from localhost ( icmp_seq=2 ttl=64 time=0.036 ms

--- ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.035/0.035/0.036/0.006 ms


Install Packages

sudo aptitude install apache2-mpm-prefork mysql-server php5-mysql cvs

This command may seem quite small, but it will install quite a few other packages - this is normal.

The command may have caused the postfix mailserver to be installed - if so, choose "No Configuration" in the menu (unless you want to setup a mailserver too).


Test Apache2/PHP Installation

Test Apache2 has installed OK by opening your favourite web browser and navigating to http://localhost. You should see a page that says "Index of /" , together with a link to apache2-default. Clicking on this link will take you to a webpage that says "If you can see this, it means that the installation...".

To test that php has installed OK, create a new web page:

sudo vi /var/www/apache2-default/index.php

Put the following content in the page, save and exit:

hello php world
<?php phpinfo(); ?>

Browse to http://localhost/apache2-default/index.php. You should see a webpage that says "hello php world" on the first line, then pages of php5 debugging information. If Firefox prompts you to download the php file instead of displaying it, restart Apache to force php to run - sudo /etc/init.d/apache restart.

We don't need the default site anymore, so let's move it to our home directory rather than deleting it (in case we need it in the future):

sudo mv /var/www/apache2-default .


Test MySQL Installation

Test MySQL has installed OK by opening a command prompt and typing:

$ mysql
mysql> use mysql;
mysql> show tables;
| Tables_in_mysql |
| columns_priv |
| user |
17 rows in set (0.00 sec)
mysql> \q

If this fails, ensure that mysql is running:

$ sudo /etc/init.d/mysql restart

We should also secure MySQL by setting a password for root:

$ mysql
mysql> SET PASSWORD=PASSWORD('supersecret')
mysql> flush privileges;
mysql> \q

Check your new password:

$ mysql -u root -p


Install Drupal Using CVS

As I said in the introduction, we're going to be installing Drupal using cvs, rather than downloading a package or .tgz file. There are several advantages to doing this:

  • you can apply security patches more easily than downloading the patches manually, and often before they're released.
  • you can upgrade to the next version more easily.
  • because all the cvs metadata is included, conflicts between your changes and upstream changes can be easily handled (you shouldn't be modifying the Drupal core code unless you know what you're doing - investigate module hooks and templates instead).
  • all those modules you've downloaded - you can also upgrade them easily.

Let's do the install:

cd /var/www
sudo cvs -d:pserver:anonymous:[email protected]:/cvs/drupal checkout \
-r DRUPAL-5 -d drupal drupal

The key option here is -d drupal. This specifies the target installation directory - change it to install to a different directory. Also, be aware that you can have multiple websites running from one drupal install - there's usually no need to install drupal multiple times on the same server.


CVS Updates

The next step is to test viewing and getting the latest CVS updates. To make it easier for you to get updates in the future, we'll create some batch files:

echo "cd /var/www/drupal; cvs -d:pserver:anonymous:[email protected]:/cvs/drupal -nq update -dP" >>
echo "cd /var/www/drupal; cvs -d:pserver:anonymous:[email protected]:/cvs/drupal update -dP" >>
chmod u+x
sudo ./get_changes

See Using CVS to maintain a Drupal Website and Ximbiot CVS Documentation for more information on using CVS with Drupal.


Create Additional Directories

Let's create some directories to store our work in:

sudo bash
cd /var/www/drupal/sites
mkdir -p all/modules
echo "put modules (for all sites) here" >> all/modules/readme.txt
mkdir -p all/themes/{engines,custom,drupal-contrib}
echo "put theme engines here (smarty, etc)" >> all/themes/engines/readme.txt
echo "put downloaded themes (for all sites) here" >> all/themes/drupal-contrib/readme.txt
echo "put customised themes (for all sites) here" >> all/themes/custom/readme.txt

Let's also customize the default site directory, as we'll be using this as a template for new sites:

sudo bash
cd /var/www/drupal/sites
mkdir -p default/modules
echo "put modules (this site only) here" >> default/modules/readme.txt
mkdir -p default/themes/{custom,drupal-contrib}
echo "put downloaded themes (this site only) here" >> default/themes/drupal-contrib/readme.txt
echo "put customised themes (this site only) here" >> default/themes/custom/readme.txt

Now, if you run the cvs update scripts we created previously, you'll see that nothing in these directories is overwritten, but any changes will be downloaded.


Create the Drupal Sites

Create the web directories for the two sites:

sudo bash
cd /var/www/drupal/sites
cp -a default
cp -a default

The next step is to create the mysql databases. In these steps, wwwdb and www2db are the databases for the website, wwwuser and www2user are the accounts used by Drupal when accessing MySQL, and password is the password for each user:

mysqladmin -u root -p create wwwdb
mysqladmin -u root -p create www2db
mysql -u root -p
mysql> use wwwdb;
mysql> grant all on wwwdb to 'wwwuser'@'localhost' identified by 'password';
mysql> use www2db;
mysql> grant all on www2db to 'www2user'@'localhost' identified by 'password';
mysql> flush privileges;
mysql> \q

We now need to configure Apache to serve up the two websites. The first step is to allow multiple websites on the same server (virtual websites):

sudo bash
cd /etc/apache2
echo "NameVirtualHost *" > conf.d/virtual
echo "ServerName" >> conf.d/virtual

Then, edit the "default" configuration file, so it can be used as a template on a multi-site server:

vi sites-available/default

Remove the command "NameVirtualHost *" from line 1 of the file sites-available/default; to tighten security, remove the cgi-bin and doc ScriptAlias and Directory, change "ServerSignature" to "Off"; also change the email address of ServerAdmin, and optionally remove any comments; change any references from /var/www to /var/www/drupal.

When completed, the sites-available/default file should look like this:

        ServerAdmin serve[email protected]
        DocumentRoot /var/www/drupal
                Options FollowSymLinks
                AllowOverride None
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        ErrorLog /var/log/apache2/error.log
        LogLevel warn
        CustomLog /var/log/apache2/access.log combined
        ServerSignature Off

Using the default file as a template, copy it and set up the required links:

sudo bash
cd /etc/apache2/sites-available
cp default www
cp default www2
cd ../sites-enabled
rm 000-default
ln -s ../sites-available/www 001-www
ln -s ../sites-available/www2 002-www
/etc/init.d/apache2 restart


Configure Drupal

The last step is to run Drupal for the first time and configure it. You'll need to temporarily relax the permissions on the file settings.php (don't leave it like this too long):

sudo bash
cd /var/www/drupal/sites/
chmod a+w settings.php

Open your web browser, and browse to You should get the Drupal configuration page - a web page with a large drupal icon top left, and the heading "Database Configuration". Fill out these settings and submit them:

  • Database type: mysql
  • Database name: wwwdb
  • Database username: wwwuser
  • Database password: password

A web page should now come up saying 'Drupal Installation Complete'; as the web page says, we need to tighten up permission on settings.php:

sudo bash
cd /var/www/drupal/sites/
chmod go-w settings.php

Follow the link to your new site, and then follow the instructions for setting up your new Drupal site. Repeat all the instructions in 'Configure Drupal' on www2 to setup the second web site.

Congratulations, you're now finished!

Share this page:

10 Comment(s)