Deploying a Multisite Drupal Install - Even on Windows

I wrote previously about using Drush and Git to deploy Drupal websites from development to production, and that all works fine if you have a single-site Drupal install, but what if you have a multi-site setup? Leaving aside for the moment how you partition your version control repository, the main issue with deploying Drupal multisites is that they are name-based. That is, you typically create a multisite Drupal install by making a new subfolder in the sites folder that has the same name as the hostname of your subsite. For example, if you have a Drupal site hosted at www.example.com and you want to create subsite for mysubsite.example.com using the same Drupal instance, you create a folder in the sites directory called mysubsite.example.com. The trouble with this is, your development server usually has a completely different hostname from your production server.

The easiest way to get around this is to use a symbolic link. So, if you have a development server with the hostnames example.local and mysubsite.example.local, then you can set up your sites directory something like this:

example.local@ -> www.example.com/
mysubsite.example.com/
mysubsite.example.local@ -> mysubsite.example.com/
www.example.com/

You can even use symbolic links on Windows, although it won’t work on Windows XP (or anything prior to that). The command is:

mklink /D example.local www.example.com

The /D tells the system that the symbolic link is a directory.

One thing you have to watch out for under Windows though, is that Git will treat the links exactly like directories, so it is best to put them into your .gitignore file. Under Linux (in my experience at least), Git treats the symbolic links as a single file, so you can leave them in version control if you wish.

Another thing to note is that if you want to keep files uploaded to the subsite separate from the parent site, you should probably tell Drupal to use the production file path rather than the development file path. That is, on the /admin/settings/file-system page (/admin/config/media/file-system page in D7), enter sites/mysubsite.example.com/files rather than sites/mysubsite.example.local/files.

Aside from those little caveats, using symbolic links is a neat solution to the issue of deploying multisite Drupal installations.

Add new comment