Setup Subversion to use HTTP Protocol on Ubuntu Server 11.04 with post-commit Hook
By Shay Anderson on March 2012
In this example I am setting up subversion to be accessed via HTTP protocol, as in 'http://[server]/svn/example_project', and I commit to the subversion repository I am having the post-commit hook update a local website project. This example assumes you already have subversion installed on your server.
First, Install 'libapache2-svn': >> apt-get install libapache2-svn
Restart Apache: >> service apache2 restart
Edit file '/etc/apache2/mods-available/dav_svn.conf' and add:
DAV svn
SVNParentPath /home/svn
SVNListParentPath On
AuthType Basic
AuthName "My Subversion Server"
AuthUserFile /etc/subversion/passwd
Require valid-user
This will allow anonymous read-only checkouts, and authorized users are allowed to read/edit (write permissions)
To disallow anonymous checkouts, replace this:
Require valid-user
Restart Apache: >> service apache2 restart
Create password file: >> htpasswd -c /etc/subversion/passwd [new user name]Then add any additional user to file with: >> htpasswd /etc/subversion/passwd [additional user name]You can check if user exists in '/etc/subversion/passwd' file with: >> cat /etc/subversion/passwd
Now you can checkout you project with: >> svn checkout http://[your server location/svn/example_project /var/www/example_projectTest making changes and commit the changes: >> cd /var/www/example_project
>> svn commit -m 'test commit'
If you attempt to commit and receive an error like:Commit
Commit failed (details follow):
Can't open file '/home/svn/example_project/db/txn-current-lock': Permission deniedYou need to change the permissions for the subversion repository: >> chown -R www-data:www-data /home/svn/example_projectOr you can change the permissions for all subversion repositories with: >> chown -R www-data:www-data /home/svn
If you are using a hook, for example a hooks/post-commit like:#!/bin/sh
/usr/bin/svn update /var/www/example_project
You will want to set correct permissions for '/var/www/example_project': >> chown -R www-data:www-data /var/www/example_project-- OR --
If you are using a hook, for example a hooks/post-commit like:#!/bin/sh
sudo -u [your user] /usr/bin/svn update /var/www/example_project
You will need to add this to the end of the '/etc/sudoers' file:www-data ALL=(ALL) NOPASSWD: /usr/bin/svn
NOTE: if you are not allowing anonymous read-only checkouts (explained above), then you would need to add this to your post-commit:/usr/bin/svn update /var/www/example_project --username [your subversion user name] --password [your subversion password]-- OR -- sudo -u [your user] /usr/bin/svn update /var/www/example_project --username [your subversion user name] --password [your subversion password]