Linux: Apache based SVN on Ubuntu

Subversion is an open source version control system. Using Subversion, you can record the history of source files and documents. It manages files and directories over time. A tree of files is placed into a central repository. The repository is much like an ordinary file server, except that it remembers every change ever made to files and directories.

For the installation of Subversion I used a Stack Appliance from TurnKey. We will use Apache 2.0 as a central authentication checkpoint. Subversion is already in the main repository, so to install Subversion you can simply install the subversion package.

apt-get upgrade
apt-get update
apt-get install subversion

Via a custom module, httpd makes Subversion repositories available to clients via the WebDAV/DeltaV protocol (Web-based Distributed Authoring and Versioning), which is an extension to HTTP 1.1. This protocol takes the HTTP protocol and adds writing (specifically, versioned writing) capabilities. The result is a standardized, robust system that is conveniently packaged as part of the Apache 2.0 software, is supported by numerous operating systems and third-party products, and doesn’t require network administrators to open up yet another custom port.

To network your repository over HTTP, you basically need four components, available in two packages. You’ll need Apache httpd 2.0, the mod_dav DAV module that comes with it, Subversion, and the mod_dav_svn filesystem provider module distributed with Subversion. Once you have all of those components, the process of networking your repository is as simple as:

  • Getting httpd 2.0 up and running with the mod_dav module
  • Installing the mod_dav_svn plugin to mod_dav, which uses Subversion’s libraries to access the repository
  • Configuring your httpd.conf file to export (or expose) the repository

 

apt-get install libapache2-svn

We need to tell Apache where we keep our Subversion repository. The purpose of the Location directive is to instruct Apache to do something special when handling requests that are directed at a given URL or one of its children. In the case of Subversion, you want Apache to simply hand off support for URLs that point at versioned resources to the DAV layer. You can instruct Apache to delegate the handling of all URLs whose path portions begin with /svn/ to a DAV provider whose repository is located at /absolute/path/to/repository. To browse all projects on this repository by going to the root url (http://www.serveraddress.com/svn) use the following in dav_svn.conf (/etc/apache2/mods-available/dav_svn.conf):

 DAV svn
 SVNParentPath /var/svn
 SVNListParentPath On
 AuthType Basic
 AuthName "Subversion Repository"
 AuthUserFile /etc/subversion/passwd
 Require valid-user

Once you add the above lines, you must restart apache2 web server.

sudo /etc/init.d/apache2 restart

Next, we must create /etc/subversion/passwd file. This file contains user authentication details.

sudo htpasswd -c /etc/subversion/passwd user_name

Now we can create our svn root:

mkdir /var/svn
cd /var/svn

Now, we need to set some access permissions on those directories. We only want to allow certain users of your system to access the repositories, so we add a new group for those users. Add yourself and www-data (the Apache user) as users to this group and change the group ownership of /var/svn to the new group using the chgrp command. The members of the svn group also need write access to the svn directory, so use chmod to add the permissions for the group:

sudo addgroup svn
sudo adduser  svn
sudo adduser www-data svn
sudo chown www-data:svn /var/svn
sudo chmod g+rws /var/svn

Subversion stores all versioned data in a central repository. To begin, create a new repository, set the umask so that group members have r/w access to newly created subdirectories:

umask 002
svnadmin create /var/svn/project1

Leave a Reply