Multi-site Drupal configuration

Are you using the Drupal content management system?

Want to run more than one Drupal site from your server? This should get you started. I'm presuming that you have root access to your Drupal box and it is called sandbox.local .

0. Set up a single site Drupal installation

Start a default, single site installation working by following the excellent instructions. Make sure that you can browse it by hostname. You do have local DNS , or a hosts file, right? You have it right when you can browse the site at sandbox.local .

How do we add the extra sites? There are only three things that have to be done.

  1. Add tables for the new site to the existing database
  2. Add a settings.php file for the new site
  3. Make sure you can find it

1. Add tables for your new site to the database

You'll need a distinctive prefix for the new tables. I'll use "xyzzy". And you'll have to put it in a few dozen places in the mysql install file (96 places in mine).

If your default installation used /database/database.4.1.mysql, copy it to /database/database.4.1.mysql.xyzzy or something else distinctive.

Modify /database/database.4.1.mysql.xyzzy so that every instance of
CREATE TABLE tablename ... becomes
CREATE TABLE xyzzy_tablename

Modify the database insert statements too.
INSERT INTO tablename
INSERT INTO xyzzy_tablename

As I said, in my set up I made the changes in 96 lines. Your file may be different.

2. Add the settings.php file for the new site

Your current settings.php file is /sites/default/settings.php You took the time to get it right for your default installation, so back it up now. If you install over Drupal, it will wipe your settings. Copy settings.php to settings.php.working for example.

Now add a directory for your new site in the sites directory. Then copy settings.php to this new directory. Your sites portion of the tree shuold look like this:

/sites/default/settings.php
This settings.php handles the default installation
/sites/xyzzy.sandbox.local/settings.php
This settings.php handles the xyzzy_ site.

Now modify /sites/xyzzy.sandbox.local/settings.php it already has your database and password settings, because you copied them in the previous step. Change
$db_prefix = '';
To
$db_prefix = 'xyzzy_';

3. Find it

Add xyzzy.sandbox.local to your hosts file, or local DNS. It's just another alias for the sandbox.local box.
You'll know that you have it right when you see the default, new site welcome page when you browse xyzzy.sandbox.local

Syndicate content Syndicate content