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.
- 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:
So if the URL were to be https://happywebdiva.com/drupal/site2, then the new directory would have to be happywebdiva.com.drupal.site2/
- Copy the “settings.php” file found in “sites/default/” into the new directory.
- 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.
- 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’;
- 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.
- 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: