User:Misterhaan/Dreamhost SVN Setup

From auWiki
Jump to navigation Jump to search

the live site automatically updates to the latest code in svn after every time i commit something. it’s a little strange getting that part to work, so here are the steps in more detail:

1. if you don't already have your site code in an svn repository, do that. both your dev site and your live site then get checked out from svn. i put my code under /live/ in my repository, so if i want to i can also create other branches for development of larger projects. the live site then should always match what's in svn under /live/, and i do my development on the dev site and then commit changes to svn.

2. you can manually update your live site by running svn update for the directory -- svn knows to update from the same place you checked out.

3. create a cgi script that updates the live site. it's just going to run the svn update command on the directory the live site uses. here's my script:

  1. !/bin/sh
  2. disable filename globbing

set -f echo Content-type: text/plain echo echo Updating live site /usr/bin/svn update /path/to/

you will need to change /path/to/ to the actual path to your site (use the linux path, not the apache path), and may need to change the svn path.

4. put the script on your web server. i actually created a subdomain that contains only this script, saved as svnupdate.cgi. the file should be owned by the same user who owns the directory it's going to be updating, with 755 permissions. to test the script, you can commit some changes to svn from your dev site, then visit, then see if your live site reflects the change.

5. i don't want to let anyone on the internet be able to make my site update itself, so i locked down my cgi subdomain so it's only accessible to the svn server. this is just an .htaccess file, and since my svn server is always named * i use the following:

order deny,allow allow from deny from all

6. now nobody can call the cgi script except the svn server, so you have to tell the svn server to call it. that's done by another script, which needs to be placed in hooks/ under your repository, and named post-commit. again it should be owned by the same user as the directory getting updated, with 755 permissions. this script simply uses wget to request the svnupdate cgi script:

  1. !/bin/bash

REPOS="$1" REV="$2" wget -O -

you will of course need to change that url to whatever you've set up.

hope that helps! let me know if you have more questions.