Ubuntu Server 7.04 Fiesty: How to Setup a Subversion Repository on Apache 2.0 using libapache2-svn

A few months ago I spent many hours pulling out my hair in a long attempt to get a Subversion repository accessible through Apache 2.0. The main benefit was the ability to browse through your repository using a web browser and the ability to integrate with the Trac Project Management tool.

The first step is to setup apache2, subversion, and libapache2-svn on your server. Login and type:

sudo apt-get install subversion apache2 libapache2-svn

Next restart the server. Type:

sudo /etc/init.d/apache2 restart

Since we will be using authenticating against specific users in the repository, we also need an SSL certificate for encryption. Type:

sudo a2enmod ssl
sudo apache2-ssl-certificate

 
After creating your SSL certificate, we need to enable port 443 on your server. To do this, edit your ‘/etc/apache2/ports.conf’ file and the line ‘Listen 443’. Your file should look like this:

Listen 80
Listen 443

Next you need to create a virtual host file for your server. If you would like more information on Apache 2.0 and virtual hosts, consult this article. Type:

sudo touch /etc/apache2/sites-available/svn.alexkuo.info

Now you will need to edit your new virtual host file and make it similar to the following.

NameVirtualHost *:443
<VirtualHost *:443>
ServerAdmin me@alexkuo.info
ServerName svn.alexkuo.info


<Location "/">
DAV svn
SVNPath /var/svn/akuo
AuthType Basic
AuthName "ALex Kuo's Repository"
AuthUserFile /etc/apache2/dav_svn.passwd
<Limit GET PROPFIND OPTIONS REPORT>
Require valid-user
</Limit>
</Location>

CustomLog /var/log/apache2/svn.alexkuo.info.custom.log combined
ErrorLog /var/log/apache2/error.svn.alexkuo.info.log

SSLEngine on
SSLCertificateFile /etc/apache2/ssl/apache.pem
SSLProtocol all
SSLCipherSuite HIGH:MEDIUM
</VirtualHost>

In the first and lines, ‘NameVirtualHost *:443’ and ‘<VirtualHost *:443>’, tells the server to listen for all names on port 443, which is the SSL port that we specified previously. The ‘ServerName’ variable specifies the domain that this configuration applies to, in this case svn.alexkuo.info. The Location tags can be used to specify different references to repositories. In this example, their is only one – ‘http://svn.alexkuo.info/’.

In the location tag, ‘SVNPATH’ specifies the local path to the repository and the ‘AuthType’ variable specifies authentication type. The setting ‘Basic’ will just prompt for a username/password. The AuthUserFile is the authentication file that will be used to authenticate against when a user atttemps to access the repository. The settings in the <Limit> specify the permissions given to a valid-user.

Next, let’s setup a user for our repository. Type:

sudo htpasswd -c /etc/apache2/dav_svn.passwd svnuser

Now we should setup a repository at the location specified by the variable ‘SVNPath’ in our virtualhosts file. We also need to set the owner to ‘www-data’ and give that group read/write permissions to these directories. To do this type:

sudo svnadmin create /var/svn/akuo
sudo chown -R www-data:www-data /var/svn/akuo
sudo chmod -R g+ws /var/svn/akuo

The last thing we need to do is enable the site and restart Apache. Type:

sudo a2ensite svn.alexkuo.info
sudo /etc/init.d/apache2 restart

You should now be able to access your Subversion repository through the ‘http’ protocol.

Reference Links

Leave a Reply