Exposing Subversion through Apache

This tutorial will guide you through exposing Subversion with the Apache HTTP Server on Ubuntu so that it can be accessed on a network. We will make use of the WebDAV protocol.

Before we start, you might want to check out:
Installing Subversion on Ubuntu
Installing Apache on Ubuntu

The first step is optional, but can assist you in identifying any errors that may happen through the process. Type the following at the terminal:

tail -f /var/log/apache2/error.log

This will display the Apache error log and will update and display the errors as they happen.

To enable Subversion to be used on the Apache server, you need to install the apache2-svn library which will also install the WebDAV protocol:

sudo apt-get install libapache2-svn

You will also need to add the Apache web user to the Subversion group:

sudo adduser www-data svn

In the previous command, ‘www-data’ is the Apache web user and ’svn’ is the group which has access to Subversion on the system.

Next we need to update the WebDAV protocol configuration. Enter the following at the terminal:

sudo gedit /etc/apache2/mods-available/dav_svn.conf

Uncomment the following lines:

<Location /svn>

DAV svn

SVNPath /var/lib/svn

AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/dav_svn.passwd

Require valid-user

Now you need to edit the file to reflect the settings on your system. ‘SVNPath’ is the location of the Subversion home directory. In my case this should be changed to:

/home/svn

‘AuthUserFile’ should be changed to the location of your Subversion password file. We will create this file in the next step. In this case it will be:

/etc/subversion/passwd

Restart the server by entering the following at the terminal:

sudo /etc/init.d/apache2 restart

Next we will create the Subversion authentication file. This file contains user authentication details. If you have just installed Subversion, the password file will not yet exist and needs to be created using the ‘-c’ switch. Adding any users after that should be done without the ‘-c’ switch to avoid overwriting the password file. Enter the following at the terminal and enter your username in the ‘[username]’ field:

sudo htpasswd -c /etc/subversion/passwd [username]

You will be prompted for your password.

To add more users at a later stage, you can run the following command:

sudo htpasswd /etc/subversion/passwd [second_user_name]

To test that everything has been set up correctly, you can enter the following at the terminal:

svn info http://localhost/svn

This should display some information about your Subversion repository. You can now find the repository at the following location (enter this address in your browser to test):

http://localhost/svn/

Installing Apache on Ubuntu

This tutorial will take you through installing the Apache HTTP Server on Ubuntu.

Enter the following at the terminal:

sudo apt-get install apache2

This will install Apache to ‘/etc/apache2′ on your filesystem. The server will be automatically started each time you start Ubuntu. Alternatively, you can start, stop, and restart the server by running the following commands respectively:

sudo /etc/init.d/apache2 start
sudo /etc/init.d/apache2 stop
sudo /etc/init.d/apache2 restart

The document root will be installed to ‘/var/www’. This is the root directory of the context path where your files can be accessed from on the server.

To test that it is working enter the following at the terminal:

sudo gedit /var/www/index.html

Enter the following and save it.

<html>
    <head></head>
    <body>
        Yeaa. It works!
    </body>
</html>

You can now open the browser and enter the following address:

http://localhost/

This should display the page you have just created.