Of Tornadoes and Drupal Multi-site Installs

Late last night, in the time between running down to our nasty basement to avoid tornadoes and some big storm action, I got to coding. I couldn’t sleep and it was a pleasant distraction — not to mention my laptop wasn’t plugged in, so I didn’t have to worry about electricity. My Drupal-enthusiast friends and I have been trying to do a multi-site install for a few weeks, and to my amazement, with a howling wind, hail, etc., the last piece finally fell into place. One of my pals had said the issue was symbolic links. Bingo. That was it.

To back up, a multi-site install means you set up the core of Drupal just once, and then you can easily create lots of other sites using that one installation. The other sites don’t even have to have the same domain. It’s very cool. For example, at work I hope to set up one master Drupal site, and then create instances for each of the labs. After that, the labs can maintain their own sites.

For now all I’ve done is to set it up on my Macbook using localhost. I made it as modest as possible — just using one database and subdirectories. But having worked through this, it will be much easier to get it working in production.

Here are the gory details.

  1. Go to the “sites/” directory and set up your new directory. At first, I named it “sites/site2/”, but that turned out to be a mistake. Given that the URL I was going for was http://localhost:8888/drupal/site2/, the correct name was “sites/8888.localhost.drupal.site2/”. It still looks weird to me, but that’s how you do it. The pattern is:
    [Port #.]domain[.directory][.subdirectory]/
    So if the URL were to be http://happywebdiva.com/drupal/site2, then the new directory would have to be happywebdiva.com.drupal.site2/
  2. Copy the “settings.php” file found in “sites/default/” into the new directory.
  3. Edit the new “settings.php” file. Leave the $db_url the same, but on the next line, give $db_prefix a value. I cleverly edited mine to read:
    $db_prefix = ’site2_’;
    This way you won’t have to set up a new database. Once you install the second site (step 6 below), the database size will double — from 40 tables to 80 tables.
  4. Further down in the “settings.php” file, look for a line that’s something like:
    # $base_url = ‘http://www.example.com’;
    Uncomment this and change it to your desired URL. In my case this was:
    $base_url = ‘http://localhost:8888/drupal/site2′;
  5. Next it’s time to create the dreaded symbolic link. Open Terminal (on a Mac) and use the ln -s command followed by first the full path of your base install and then the full path of the second sites’ directory (leaving off the characters before the periods in the final directory, e.g. changing “8888.localhost.drupal.site2″ to just “site2″). In my example, it was:
    ln -s /home/username/public_html/drupal/ /home/username/public_html/drupal/site2
    One caution: be sure there’s not a file or directory in the first directory that’s the same name as your new install. You don’t want the symbolic link overwriting something critical.
  6. The last step…. In your browser, go to the new site’s URL followed by install.php, e.g. http://localhost:8888/drupal/site2/install.php

That’s it. You should now have a second site (and soon a third and fourth) to play with.

Addendum: In the myriad of multi-site documentation that’s on the web, these three pages helped me the most:

8 comments ↓

#1 Geek Glue on 02.11.08 at 10:21 pm

Glad to hear my humble post was of use to someone else besides myself.

#2 Anna Belle on 02.12.08 at 6:39 pm

Absolutely! You gave me confidence I was on the right track, and sure enough.

#3 Heather Mitchell on 02.12.08 at 6:44 pm

Congratulations! Just a small typo in step 5, though — it should be “use the ln -s command” instead of “use the ls -s command.” It’s right in the example.

#4 Anna Belle on 02.12.08 at 6:54 pm

Thanks, Heather! Typo now corrected.

#5 avolve on 03.09.08 at 10:34 pm

i am having a little trouble with this and have a couple questions (drupal 6). This is my first attempt at multisite…

For my localhost install (i have set MAMP to the default Apache and MySQL ports) I have my drupal install at

‘Sites/local/drupal’ and the second site ‘Sites/local/drupal/site2′

The main install is available at ‘localhost/drupal’

The ’site2′ folder is named ‘localhost.drupal.site2′

i (attempted to?) created a symlink: ln -s Sites/local/drupal Sites/local/drupal/site2

An alias shows up in the drupal folder (as ’site2′), though on trying to access it through a browser i get a ‘don’t have permission’ and a 403 Forbidden error.

I am a bit lost as to what is going wrong/what i am doing wrong…

#6 Stephen Schneiter on 05.22.08 at 9:16 pm

Great job! I have been looking for assistance in setting up another site off of our community site and I came across your site! It is awesome.

I used your instructions for setting up the new site and everything worked as it should except for one hang up with the symbolic link. Unfortunately, Drupal is running on a Windows server with Apache. Windows does not support symbolic links as Linux or UNIX so I had to play around with the Junction command which to me works backwards then the ln command but that is me. Once I had this figured out everything works just as you said!

It was great! Now I am off to set up the rest of the site and add content.

Thanks, Again and I look forward to reading more of your work!

#7 Anna Belle on 05.23.08 at 5:43 pm

avolve — I’m sorry to hear about your difficulties. I find multisite to be quite quirky. If you haven’t figured it out yet, I’d suggest trying the forums on drupal.org.

Stephen — So glad to hear it worked for you! And that’s a great tip about using Junction with Windows/Apache.

#8 Mark on 08.26.08 at 2:49 pm

I’ve got the MAMP setup and I’ve followed the steps above, however, whenever I log into my new site, it automatically redirects me to http://localhost/drupal/node as if I had logged into the default site. Any ideas?

Leave a Comment