Since version control is something which every programmer should be using, and since I like Subversion (SVN), I thought it would be great to add a tutorial about installing a web based SVN interface. Trac allows you to browse your SVN repositories from any web browser.

This tutorial assumes you have already installed Apache2 and Subversion. Apache2 is simple to install, just use apt-get. Subversion is more complex to configure. Check out a tutorial I made about installing SVN. The directories don’t match this Trac tutorial, but the basic concept is the same.

The following Trac tutorial uses puts the SVN repository in a different place than my tutorial because I was following the standard SVN location. SVN repository locations are up to the user. You can put a repository anywhere (as long as you have sufficient privileges).

My Subversion tutorial SVN location: /usr/local/svn/project
Trac tutorial SVN location: /var/svn/project

I found a tutorial on the Trac website which focuses on a Debian install of Trac. But I ran into a problem, the Apache2 web server would fail to restart when I tried to follow the steps in the tutorial. All you have to do is make sure “libapache2-svn” is installed on your system prior to configuring Trac. If you don’t have libapache2-svn, get it with apt.

apt-get install libapache2-svn

Once you have done this prep-work, you should be able to follow the instructions below without encountering any error messages like “Invalid command ‘DAV’…” or “Cannot load /usr/lib/apache2/modules/mod_dav_svn.so into server…”

Much of the following is from Installing and Running Trac on Debian, with some important changes by me.

Install Trac
apt-get install trac

I decided to keep my Subversion project at /var/svn/project. Here are the commands I entered to get SVN up and running:
mkdir /var/svn
mkdir /var/svn/project
mkdir /tmp/project
mkdir /tmp/project/branches
mkdir /tmp/project/tags
mkdir /tmp/project/trunk

svnadmin create /var/svn/project
svn import /tmp/project file:///var/svn/project -m "initial import"
rm -rf /tmp/project

I added the following to /etc/apache2/sites-available/default
#SVN dir
<Location /svn>
DAV svn
SVNParentPath /var/svn
</Location>

Fix permissions and restart apache2
chown www-data /var/svn/project
chown -R www-data /var/svn/project/*
apache2 -k restart

If you get an error message from Apache2, read the following, otherwise skip:

I had some problems with the WebDAV module not loading. To enable this, you need to create some sym links inside /etc/apache2/mods-enabled. I typed this to get it to work:
ln -s /etc/apache2/mods-available/dav.load /etc/apache2/mods-enabled/dav.load
ln -s /etc/apache2/mods-available/dav_fs.load /etc/apache2/mods-enabled/dav_fs.load
apache2 -k restart

Ubuntu even comes with tools to manage these symlinks. Instead of the above you can also type this, which will have the same effect:
a2enmod dav
a2enmod dav_fs
/etc/init.d/apache2 force-reload

If you are having problems restarting and the error is something like “Unknown DAV provider: svn” try installing the libapache2-svn module by typing
apt-get install libapache2-svn
apache2 -k restart

I was able to test by going to http://servername.foo.com/svn/project where I could see the empty directories as imported. I did not move on to the next step until this worked right!

Configure Trac
mkdir /var/trac
trac-admin /var/trac/project initenv

The “trac-admin” command above prompted me to enter the project name, the path to the Trac environment, and the path to the Trac templates directory; then it printed out a bunch of stuff.

Adjust permissions
chown -R www-data /var/trac/project

Next, I edited /etc/apache2/sites-available/default and added this at the end:
Alias /trac "/usr/share/trac/htdocs"
ScriptAlias /proj /usr/share/trac/cgi-bin/trac.cgi
<Location "/proj">
SetEnv TRAC_ENV "/var/trac/project"
</Location>

Add basic user authentication for Trac
<Location "/proj/login">
AuthType Basic
AuthName "project"
AuthUserFile /var/www/trac.htpasswd
Require valid-user
</Location>

Now to add a couple of users
cd /var/www
htpasswd -c trac.htpasswd user1
htpasswd trac.htpasswd user2
chown www-data trac.htpasswd

Restart Apache2
apache2 -k restart

Customize your Trac install by editing /var/trac/project/conf/trac.ini
You can change the header logo, email notification, logging, and many other features

For further information about Trac, check out the TracGuide which is installed by default. You will find information about backup, using the Wiki, and many other useful topics.