Git'n It with Drupal Multisite

Shakib Mostafa // July 2012

I recently set up a Drupal Multisite environment for a client where each of their departments needed their own subsites. The central IT team would maintain the Drupal core, but the departments would have full control over adding custom/contributed modules and themes, as well as, making configuration changes to their own site.

To set this up on Git I actually set up separate repositories for each of the sites and one for the Drupal core. Separate repositories for subsites were needed so that developers from individual departments could be given full control over the department specific modules and themes while having read access to the drupal core repo. 

Production Environment Setup

With that setup in Git here is how Drupal is structured in the production server:

1. Drupalcore:

/var/www/myorg.com

This is a checkout of the master of the drupalcore repository

2. Individual Subsite

/var/www/department1.myorg.com
/var/www/department2.myorg.com
...

Checkout of the master for the individual department repos

3. Linking it all up:

Symlinks in /var/www/myorg.com:

ln -s . department1
ln -s . department2
...

Symlinks in /var/www/myorg.com/sites:

ln -s /var/www/department1.myorg.com department1.myorg.com 
ln -s /var/www/department2.myorg.com department2.myorg.com 
...

4. Permissions

Members of the organization’s IT team have write permission to drupal core. Whenever the git master branch is updated, members of the IT team can run a git pull on the drupal core folder to update the code there.

Developers for individual subsites have write permission to their website’s directory. Again a git pull from master is all that is needed to update code.

Development Environment Setup

Development environment setup is almost the same as the production setup except that developers of a department only have to worry about the drupal core and the folder for their department’s subsite. So the basic setup would be something like this: 

1. Drupalcore:

/var/www/myorg.dev

This is a checkout of the master of the drupalcore repo

2. Individual Subsite

/var/www/department1.myorg.dev

This is a checkout of the master for the departmental repo

3. Linking it all up:

Symlink in /var/www/myorg.dev:

ln -s . department1

Symlink in /var/www/myorg.dev/sites:

ln -s /var/www/department1.myorg.dev department1.myorg.dev 

4. Permission:

Since this is a local environment, developers will have permission to update all files, however a git push to the drupal core repo is not permitted. Developers are allowed to push their department’s repository only.

5. Local serverconfig/Virtual Host:

For this setup to work locally two things need to happen:

a) Add an entry to the local hosts file (e.g. /etc/hosts) for:

127.0.0.1 department1.myorg.dev

b) Set up a virtual host for department1.myorg.dev, the docroot should be /var/www/myorg.dev/department1:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName department1.myorg.dev
        DocumentRoot /var/www/myorg.dev/department1
        <Directory />
                Options FollowSymLinks
                AllowOverride All
        </Directory>
        <Directory /var/www/myorg.dev/department1>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>
</VirtualHost>

 

Filed under: