How To Configure Web Access To Subversion Repositories Using Apache

Want to support HowtoForge? Become a subscriber!
 
Submitted by softr8 (Contact Author) (Forums) on Mon, 2007-03-12 17:47. :: Apache | FreeBSD

How To Configure Web Access To Subversion Repositories Using Apache

This how to is going to describe the steps to get the mod_dav_svn module to work in an Apache web server. First I'll assume that we don't have Apache and Subversion installed on our FreeBSD box, in a second part I'll explain how to add the module using our current installation.

First we have to install our Apache 2.0.x with Berkeley DB support (because Subversion will use Berkeley DB to save the repositories). To do this we have to go to the ports dir and do this:

box# cd /usr/ports/www/apache20/
box# make -DWITH_BDB4 install clean
some installation steps...

Add apache ability to start automatically at boot time:

box# echo 'apache2_enable="YES"' >> /etc/rc.conf

After we have apache20 installed with bdb support, we'll have to install Subversion:

box# cd /usr/ports/devel/subversion
box# make -DWITH_MOD_DAV_SVN install clean
some installation steps...

After installation we'll have to ensure that mod_dav_svn module was properly installed on apache.

box# cat /usr/local/etc/apache2/httpd.conf | grep svn

LoadModule dav_svn_module     libexec/apache2/mod_dav_svn.so
LoadModule authz_svn_module   libexec/apache2/mod_authz_svn.so

We have apache with mod_dav_svn module installed properly. At this point we can create a repository. This will help us to test our instalation:

box# mkdir /usr/home/svn
box# mkdir /usr/home/svn/repos
box# svnadmin create /usr/home/svn/repos/test

Then we have to create the files that are going to be used to authenticate the users.

box# mkdir /usr/home/svn/access
box# cd /usr/home/svn/access
box# htpasswd -cm users root
password:****
box# htpasswd -m users viewer
password:*****

box# vi control

[test:/]
root = rw
viewer = r

At this point we have apache with bdb support, subversion with mod_dav_svn module installed, our repository created, the users and the control to our repository. Now we will configure apache to read the repositories:

box# cd /usr/local/etc/apache2/Includes/
box# cat svn.conf

<Location /svn/repos>
DAV svn
SVNParentPath /usr/home/svn/repos
SVNIndexXSLT "http://svn.example.com/svnindex.xsl"
AuthzSVNAccessFile /usr/home/svn/access/control
# anonymous first
Satisfy Any
Require valid-user
# authenticating them valid ones
AuthType Basic
AuthName "Subversion Repositories at example.com"
AuthUserFile /usr/home/svn/access/users
</Location>

Apache will read all the files that are under the Includes directory, so our svn.conf will be loaded when apache starts, note that we are  loading svnindex.xsl that is the file where the transformations are done, if you would like to give to your repository some look and feel work these file will be the appropiate. The file skeletons are under /usr/local/share/subversion/xslt/ directory, there are two files, one .xsl and another .css. Copy these files to your document root.  I have a virtual server called svn.example.com in my machine. I have all my virtual servers under /usr/local/www/pages, so I have svn.example.com directory and I've configured that virtual server in /usr/local/etc/apache2/httpd.conf.

NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin ecruz@example.com
ServerName svn.example.com
DocumentRoot /usr/local/www/pages/svn.example.com
CustomLog /var/log/svn.example.com-access_log common
</VirtualHost>

Restart the web server:

/usr/local/etc/rc.d/apache2.sh restart

If all went ok, we have our web server working properly, to test it, open in your Firefox or whatever browser and go to http://svn.example.com/svn/repos/test. It will ask you for the credentials, so use root or viewer. It must display the test repository at revision 0. I'll suggest to install TortoiseSVN on Windows boxes to get access to the repositories.

Now, as a plus, we will configure an alert in our subversion test repository to send a notification when a commit was done. To do this we will have to create an executable file under the hooks directory:

box# cd /usr/home/svn/repos/test/hooks/
box# cat post-commit

[code]
#!/usr/local/bin/php
<?
$message = "SubVersion Commit
Project: Test
http://svn.example.com/svn/repos/test full repository
==============Comments==============
";
$repos = $argv[1];
$version = $argv[2];
$message .= `svnlook log -r $version /usr/home/svn/repos/test`;
$message .= "
===========List of Changes========
";
$message .= `svnlog diff -r $version /usr/home/svn/repos/test`;
mail("address@example.com","SubVersion Commit $repos $version",$mensaje,"From: svn@example.com");
?>
[/code]

To get this to work with your current installation you have to change only the subversion installation step:

box# cd /usr/ports/devel/subversion
box# make deinstall
box# make -DWITH_MOD_DAV_SVN -DWITHOUT_BDB4 install clean

Ok, this is the end of this howto, any improvements are welcome. Regards!


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Pierre de France (not registered) on Thu, 2010-12-02 14:23.

Hi,

 short tutorials like this one are great.

I particularly appreciated the part about post-commit.

 Thanks,

 Pierre

Submitted by sveronese (not registered) on Mon, 2008-09-15 16:43.

$message .= `svnlog diff -r $version /usr/home/svn/repos/test`;
mail("address@example.com","SubVersion Commit $repos $version",$mensaje,"From: svn@example.com");

 The variable $mensaje IMHO should be replaced with $message.

 Bests,

Simone

Submitted by Anonymous (not registered) on Mon, 2008-12-08 21:54.

The commande "svnlog" doesn't exist. Use "svnlook diff".

To resume:

 $message .= `svnlook diff -r $version /usr/home/svn/repos/test`;

 

Bests regards,

gnomii

Submitted by softr8 (registered user) on Thu, 2007-03-15 15:15.

I forgot to mention that under /usr/local/share/subversion/hook-scripts directory there are some predefined scripts like commit-email.pl.

To use them only change their permissions with chmod +x file-name and in the repository/hooks/post-commit script edit the full path and make it executable (chmod +x post-commit)