Setting up Drupal multisites under Passenger, with Git
Here’s my steps for setting up a Drupal production and development site, with Drupal core and modules under separate Git control and running the whole thing under Passenger. I got most of this framework from Version Control Blog, but instead of using separate repositories for Drupal core and modules, I use branches. In addition, I include the details of my Passenger setup.
One thing I really like about how Version Control Blog illustrates this process, is setting up the project with an older version of Drupal and then upgrading at the end, to show how simple it is. I will definitely follow that path.
So, to begin with, create a folder with a fresh download of Drupal and commit it to Git. At the command line:
$ drush dl drupal-6.15
$ mv drupal-6.15 my-project
$ cd my-project
$ git init
$ git add .
$ git commit -m "Drupal 6.15 imported"
Now create the branch for your modules and download some modules for it:
$ git checkout -b "modules"
$ drush dl cck
$ git add .
$ git commit -m "CCK 6.x-2.6 imported"
$ drush dl views
$ git add .
$ git commit -m "Views 6.x-2.8 imported"
$ git status
Now create the branch for your actual Drupal project:
$ git checkout -b application
Create two sites folders, one for a dev site, one for production:
$ mkdir sites/dev.my-projectlocal
$ mkdir sites/my-project.local
Copy and rename sites/default/default.settings.php over to the two new sites folders:
$ cp sites/default/default.settings.php sites/dev.my-project.local/settings.php
$ cp sites/default/default.settings.php sites/my-project.local/settings.php
Create the two databases in mysql:
mysql> create database my_project;
mysql> create database my_project_development;
The next step is to configure Passenger to send requests for my-project.local and dev.my-project.local to our Drupal application. For this, I need to edit my /etc/hosts file, adding these lines:
127.0.0.1 my-project.local
127.0.0.1 dev.my-project.local
I setup Passenger via Peepcode’s Phusion Passenger screencast, so my VirtualHost entry goes in a passenger_vhost.conf file and looks like this:
<VirtualHost *:80>
ServerName my-project.local
DocumentRoot /Library/WebServer/Documents/my-project
</VirtualHost *:80>
<VirtualHost *:80>
ServerName dev. my-project.local
DocumentRoot /Library/WebServer/Documents/my-project
</VirtualHost *:80>
Don’t forget to restart your server:
$ sudo apachectl graceful
Now you should be able to navigate to http://my-project.local and http://dev.my-project.local and install these apps as usual.
When you are done, check the two sites folders into Git:
$ git add .
$ git commit -m "Setting up development and production sites"
Don’t forget to block your webserver from exposing your Git files. Add this line to your .htaccess file:
RewriteRule ^\.git - [F]
Check it into Git as well. When I update from Drupal 6.15 to Drupal 6.16, Git nicely merges the changes to htaccess from the upgrade with my manual addition of this RewriteRule.
Now, here’s how to upgrade Drupal core. I have a copy of the latest Drupal release in my Downloads directory. I first switch back to my master branch, then copy the new Drupal files over to my project and then see what the changes are, just out of curiosity. I add them all in to master, then checkout modules and merge master into that. Then, I checkout application and merge modules into it.
$ git checkout master
$ cp -Rf ~/Downloads/drupal-6.16/ .
$ git status
$ git add .
$ git commit -m "Drupal 6.16 imported"
$ git checkout modules
$ git merge master
$ git checkout application
$ git merge modules
I’ll need to run the update.php script for each site, to update the databases, then I’m all set.

Discussion Area - Leave a Comment