Managing and deploying Drupal sites using SVN & MAMP

It's simple: Drupal + SVN = happy web developer.

This is the story of how I generally structure my Drupal based sites using Subversion (SVN) to make development, versioning and deployment easy and well-organized. A quick note: this post assumes that you already know the nitty gritty of how to use SVN and the basic setup and structure of a Drupal-based site.

Setting up my local development environment

For this I have installed MAMP on my mac (use XAMP for windows) and for each development site I edit the ~/Applications/MAMP/conf/apache/httpd.conf by adding a vhost at the very end:

DocumentRoot /Users/alex/Sites/

Don't forget to restart MAMP. I also edit my /etc/hosts file (mac users: you may need to use sudo; windows users: look in c:\windows\system32\drivers\etc\hosts) by adding the following line at the end of the file: local.bleen.netNow create a database in MAMP for the development site to use (if you're not sure how to do this, check out phpMyAdmin which is installed with MAMP). Ok, local development environment setup complete.

Why do this?

if we didn't then any time anything was added to that folder it would need to be added to our SVN repository and that is both annoying and unnecessary.

Installing Drupal

Download and install Drupal to the new local site you just created. In my example your install path should be /Users/alex/Sites/ Go through the Drupal install by browsing to (or whatever vhost you created). The next thing to do is make sure your /sites/default/files is not in your webroot directory. I generally create a folder at the same level as my webroot: /Users/alex/Sites/bleen_files. Then I replace the /sites/default/files folder with a symlink: ../../../bleen_files. Why do this?

Why do this?

this ensures that your site will always use the correct database

The other change I always make is to the /sites/default/settings.php file. Find the line that defines the $db_url variable. Replace that line with something that looks like this:
$dev = ($_SERVER['HTTP_HOST'] == '');
$db_url = $dev ? 'mysqli://root@localhost/db_name' : 'mysqli://username:pAsSwOrD@mysqlhost/db_name';
$db_prefix = '';


This part is simple. Create your SVN repository and add your drupal site.

Deploying your Site

  1. First time only: Put your devel site in maintenance mode
  2. First time only: Dump your development database and then move it to your production DB
  3. First time only: do an SVN checkout to your production server
  4. Not first time only: Put your production site in maintenance mode
  5. Every time: do an SVN update on your production server
  6. Every time: Take your site out of maintenance mode