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 https://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:

10 Responses

  1. 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…

  2. 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!

  3. 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.

  4. Hi, I’ve a little problem with it.
    I’ve been able to create two sites in drupal and access form the same machine with localhost/site1 and localhost/site2, following the steps you explain… However, if I try to access from other PC in the same lan with its IP/site1 or IP/site2, I always get the default Drupal’s site.

    Have you got any ideas?

    Thank you so much.