July 19th, 2009
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.
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:<VirtualHost 127.0.0.1>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:
ServerName local.bleen.net
DocumentRoot /Users/alex/Sites/bleen.net
</VirtualHost>127.0.0.1 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.
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.
Download and install Drupal to the new local site you just created. In my example your install path should be /Users/alex/Sites/bleen.net. Go through the Drupal install by browsing to http://local.bleen.net (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?
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'] == 'local.bleen.net');
$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.