Multisite CVS Drupal Installation on Ubuntu

Want to support HowtoForge? Become a subscriber!
 
Submitted by soniah (Contact Author) (Forums) on Mon, 2007-08-06 18:10. :: Ubuntu

Multisite CVS Drupal Installation on Ubuntu

Introduction

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 www.example.com and www2.example.com (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 "127.0.0.1 www.example.com www2.example.com" >> /etc/hosts
exit

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

$ ping -c 2 www.example.com

PING www.example.com (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.035 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.036 ms

--- www.example.com 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):

cd
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:anonymous@cvs.drupal.org:/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:

cd
echo "cd /var/www/drupal; cvs -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal -nq update -dP" >> show_changes.sh
echo "cd /var/www/drupal; cvs -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal update -dP" >> get_changes.sh
chmod u+x show_changes.sh get_changes.sh
./show_changes
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
exit

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
exit

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 www.example.com
cp -a default www2.example.com
exit

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 127.0.0.1" >> 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 serveradmin@example.com
        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
exit

 

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/www.example.com
chmod a+w settings.php
exit

Open your web browser, and browse to http://www.example.com. 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/www.example.com
chmod go-w settings.php
exit

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!


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by cris2per (registered user) on Fri, 2010-06-25 18:52.
At this point in your SEO life cycle, you just began using Drupal to manage your site and are looking to properly set up the correct, basic modules from it’s core package. Drupal Core comes with some useful modules that will enable your site to establish a healthy, ongoing relationship with all the search engines and their algorithmic spiders. Drupal comes very friendly out of the box, but it may take a few modules to get you the momentum you are looking for to climb up the SERPs. Here are three necessary Drupal SEO module activations you should make, in order to help achieve the Drupal SEO success you want for your site.
Submitted by James (not registered) on Sun, 2009-03-01 19:54.

This is the prefect tutorial.  I found it to be very clear and it totally worked.  I always wondered what the best way to deal with Apache, directory structure, etc. to make Drupal multisite work.  I was able to use this information and configure my Dreamhost account for a multisite Drupal install.  I didn't have to modify the apache config directly.  I went through Dreamhost's control panel to achieve the same functionality.

Thanks!

Submitted by Anonymous (not registered) on Tue, 2008-12-23 07:55.
This looks really like a neat way to do this, but i couldn't get it to work..Is there a command line to uninstall all this stuff? there has to be an easier way
Submitted by knd (not registered) on Thu, 2008-09-11 08:22.
Accessing the page www.example.com (last step)throws an 500 internal server exception.The /var/log/apache2/error.log file says " Option indexes not allowed here in .htaccess ".Anyone knows how to handle that ?
Submitted by knd (not registered) on Tue, 2008-09-16 09:09.

Got it !

1. Option indexes to be used under <Directory/></Directory> tags.

2. Make sure to run www.example.com/install.php the first time you access your site otherwise you'll get a ugly "table.access doesn't exist..." 

 Thx for the how-to Sonia

Submitted by SamTzu (registered user) on Thu, 2007-08-09 16:01.

I have been thinking how to adapt something like this to fit ISPConfig.
I have a hobby site that allready has several sub categories for different hobbies and I'm starting to get in to trouble keeping them all straight with ISPConfig. I'm currently using Joomla because it's broad user base and support. All the different sub categories should be fairly autonomous with their own admins.

 

Sam 

Submitted by soniah (registered user) on Tue, 2007-08-14 03:20.
I doubt I'll get around to rewriting this for ISPConfig - I tend to do most stuff by hand - easier to troubleshoot in the longterm.
Submitted by majikins (registered user) on Tue, 2007-08-07 14:57.

Hi

Thanks for the How-to:

I had a problem at the Drupal database configuration.  wwwdb(haven't tried www2db yet) did not have access granted.  I went through my previous commands to see if I misstyped anything and can't find a fault.  I had to grant rights via phpadmin.  

 Anyone else?

 Otherwise - she's up and running!!

Thanks 

 

 

Submitted by blarneyrabble (registered user) on Fri, 2007-09-14 00:15.

I had to use:

grant all on wwwdb.* to 'wwwuser'@'localhost' identified by 'password';

 

 

Submitted by soniah (registered user) on Wed, 2007-08-08 10:45.

Thanks for your comments . You might've made a typo, but it could be an error in my explanation; did you do the flush privileges command?

Basically, you want to give the wwwuser all rights to the wwwdb database, hence the grant all statement. Also, we shouldn't really be doing a grant all as that gives the wwwuser too many permissions, but the permissions recommended in the drupal install doco are too tight and give errors, and I haven't had time to work out the correct combo - anyone know what they should be?

Sonia.