Drupal 6 Multisite

Submitted by Emil on Fri, 07/04/2008 - 08:12

Yesterday, I decided to upgrade from Drupal 5 to 6. After reading some documents, the process was really easy to perform. The upgrade documents are available here and are easy to follow: http://drupal.org/upgrade/.

First of all, back up your data! I went into phpMyAdmin and exported the whole database. Structure and data! Then, I went to the site's root folder and moved all drupal files to a backup directory on my PC.

Now, I was ready to install the new version. I went to http://drupal.org/ and downloaded the latest release of Drupal 6 (6.2). After uploading all the new files, I needed to edit the new /sites/default/settings.php file to have it find my database. In the same way Drupal 5 wouldn't run on http://one.com's servers, version 6 wouldn't either without commenting out these lines in /.htaccess:

Options -Indexes
Options +FollowSymLinks

Now, i was ready to upgrade the database via /update.php. Or at least so I thought. I couldn't login as the site administrator! Nothing to worry about, simply set the variable $update_free_access = TRUE; in /sites/default/settings.php. This means you can run the update script without logging in. Change it back to $update_free_access = FALSE; when you are done!

The update script ran for about a minute and then I had the latest version of Drupal installed on http://klargodut.com. After logging in, the /admin page suggested that I should enable the Update Status module which simplifies future updates and so I did. That's it, all needed to do now was to delete these files from the web root to avoid being hacked:

install.php
CHANGELOG.txt
INSTALL.txt
INSTALL.mysql.txt
INSTALL.pgsql.txt
LICENSE.txt
MAINTAINERS.txt
UPGRADE.txt

Earlier, I had one Drupal installation for each site here at klargodut.com. /sudoku had its own as well as /htw and /resolution. This is quite inconvenient so I decided to create a multisite configuration instead. In such a configuration, each site lives its own life but they all share the same code base. Upgrading and maintenance is a lot easier!

To get multisite working, you add new directories to /sites. I wanted the sites /sudoku, /htw and /resolution, why I copied the /sites/default folder to /sites/klargodut.com.sudoku, /sites/klargodut.com.htw and /sites/klargodut.com.resolution. Each site should have its own database tables, so I set the $db_prefix variable in /sites/klargodut.com.XXX/settings.php to match the tables that were already in my database from the old sites.

Having configured the sites, I went to web root and moved /sudoku, /htw and /resolution to my local backup directory. However, I needed to do some additional hacking in order to get multisite working. Symbolic links had to be created for sudoku, htw and resolution in the web root. These symbolic links should all point to the web root itself. This way, the one and only Drupal installation is used no mather what site you are browsing. Drupal parses the requested URL and sets the database prefix accordingly. I used the php function symlink to create these links as I do not have access to any SSH terminal.

The only thing left to do now was to run update.php for each site. I altered the $update_free_access variable in the same way I did for the default site, ran the script and changed it back. All left to do was to login as site administrator at each site and enable the update module.

Done! Four different sites running on one upgraded code base.