Installing a Subversion server on Debian

This guide describes how to setup a SVN server on Debian. It is designed to be a good a starting point to make the first steps easier. The provided scripts are tested on Debian Squeeze and has to be executed with root privileges, so if the current user is not root, type this before doing anything:

su root

First, install the required packages:

apt-get install apache2 subversion libapache2-svn

Create a directory for the future Subversion repositories:

mkdir /var/repo
mkdir /var/repo/svn

Create a script file the automates the creation of a repository. It initializes a repository and grants the appropriate rights.

svnadmin create $1
chmod 770 ./$1 -R

chown www-data.root ./$1 -R

Script to achieve this:

cd /var/repo/svn
echo "svnadmin create $1" > create.sh
echo "chmod 770 ./\$1 -R" >> create.sh
echo "chown www-data.root ./\$1 -R" >> create.sh
chmod +x create.sh

The Subversion server is hosted by Apache, so create the corresponding site configuration file: /etc/apache2/sites-available/svn

This sample configuration makes the server to show all repositories located in the previously created directory.

<VirtualHost *:80>
 ErrorLog /var/log/apache2/svn-error.log
 CustomLog /var/log/apache2/svn-access.log custom

 <Location />

  DAV svn
  SVNParentPath /var/repo/svn/
  SVNListParentPath on
  SVNAutoVersioning on
 
 </Location>
</VirtualHost>

Script that creates this configuration file: cd /etc/apache2/sites-available

echo "<VirtualHost *:80>" > svn
echo " ErrorLog /var/log/apache2/svn-error.log" >> svn
echo " CustomLog /var/log/apache2/svn-access.log custom" >> svn
echo " >> svn 
echo " <Location />" >> svn
echo "  DAV svn" >> svn
echo "  SVNParentPath /var/repo/svn/" >> svn
echo "  SVNListParentPath on" >> svn
echo "  SVNAutoVersioning on" >> svn
echo " </Location>" >> svn
echo "</VirtualHost>" >> svn

The configuration is complete, now the site and Apache has to be enabled and reloaded, respectively.

a2dissite default
a2ensite svn

/etc/init.d/apache2 reload

It’s done. Now, we can use this to create a new repository:

/var/repo/svn/create.sh repository_name

To access the repositories, simply use this url: http://ipaddress_of_server/

Keep in mind that the provided script only serves as a starting point. For example, it is highly recommended to complete the site configuration file with the ServerName directive and provide authentication and authorization mechanism.

The complete script can be downloaded from here.

Advertisements