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:
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:
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.
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.
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?
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.
Deploying your Site
- First time only: Put your devel site in maintenance mode
- First time only: Dump your development database and then move it to your production DB
- First time only: do an SVN checkout to your production server
- Not first time only: Put your production site in maintenance mode
- Every time: do an SVN update on your production server
- Every time: Take your site out of maintenance mode