Multisite CVS Drupal Installation on Ubuntu
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.
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:
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.
sudo aptitude install apache2-mpm-prefork mysql-server php5-mysql cvsThis 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):
Test MySQL Installation
Test MySQL has installed OK by opening a command prompt and typing:
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:
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:
Let's do the install:
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.
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:
Create Additional Directories
Let's create some directories to store our work in:
Let's also customize the default site directory, as we'll be using this as a template for new sites:
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:
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
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):
Then, edit the "default" configuration file, so it can be used as a template on a multi-site server:
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:
Using the default file as a template, copy it and set up the required links:
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):
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:
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:
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!