Tutorials and How-tos/Install Subversion with Apache

From BubbaWiki
Jump to navigation Jump to search

How to install Subversion (SVN) with Apache on your Bubba server

Using Apache instead of svnserve give you some benefits like being able to see your repo in your browser.

Basic set-up

Most people have their Bubba server connected on a private network and don't need much security protocols, so I'll start with an easy set up.

Log in to your Bubba server using SSH (On Windows use PuTTY and on Mac & Linux open a terminal and use ssh). Gain root access (Linux talk for admin rights) with default password excito.

$ su

Change directory to /

$ cd /

First we need to install the actual SVN software from the repository.
We will use the default repository and install the version available there (in my case 1.5.1).

$ apt-get install subversion

Next we need to install the package to bind SVN and Apache together.

$ apt-get install libapache2-svn 

Now it's time to create a directory to use for SVN. I usually use /srv/svn/ but in Debian it seams to be more common to use /var/svn/ so lets use that.

$ mkdir /var/svn

As this directory is created by root Apache can not use it, so lets hand over the ownership of our newly created directory to the Apache user "www-data".

$ chown -R www-data:www-data /var/svn

Now that our files and directories are in place we can start configure our Apache expansion module. A template file is already installed and you can view it with

$ cat /etc/apache2/mods-available/dav_svn.conf

All lines starting with a # is a comment and will be ignored.

Let's edit the file using the editor nano (or your favourite editor).

$ nano /etc/apache2/mods-available/dav_svn.conf 

I will list the complete template file with my changes. I change the path to /var/svn.

Notice also that I add the line "SVNListParentPath on" to be able to browse all repos not just in the repos.

# dav_svn.conf - Example Subversion/Apache configuration
# For details and further options see the Apache user manual and
# the Subversion book.
# NOTE: for a setup with multiple vhosts, you will want to do this
# configuration in /etc/apache2/sites-available/*, not here.

# <Location URL> ... </Location>
# URL controls how the repository appears to the outside world.
# In this example clients access the repository as http://hostname/svn/
# Note, a literal /svn should NOT exist in your document root.
<Location /svn>

# Uncomment this to enable the repository
DAV svn

# Set this to the path to your repository
#SVNPath /var/lib/svn
# Alternatively, use SVNParentPath if you have multiple repositories under
# under a single directory (/var/lib/svn/repo1, /var/lib/svn/repo2, ...).
# You need either SVNPath and SVNParentPath, but not both.
SVNParentPath /var/svn
SVNListParentPath on
# Access control is done at 3 levels: (1) Apache authentication, via
# any of several methods. A "Basic Auth" section is commented out
# below. (2) Apache <Limit> and <LimitExcept>, also commented out
# below. (3) mod_authz_svn is a svn-specific authorization module
# which offers fine-grained read/write access control for paths
# within a repository. (The first two layers are coarse-grained; you
# can only enable/disable access to an entire repository.) Note that
# mod_authz_svn is noticeably slower than the other two layers, so if
# you don't need the fine-grained control, don't configure it.

# Basic Authentication is repository-wide. It is not secure unless
# you are using https. See the 'htpasswd' command to create and
# manage the password file - and the documentation for the
# 'auth_basic' and 'authn_file' modules, which you will need for this
# (enable them with 'a2enmod').
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/dav_svn.passwd

# To enable authorization via mod_authz_svn
#AuthzSVNAccessFile /etc/apache2/dav_svn.authz

# The following three lines allow anonymous read, but make
# committers authenticate themselves. It requires the 'authz_user'
# module (enable it with 'a2enmod').
Require valid-user


To get Apache to read in our new configuration file we will restart the complete Apache service.

$ /etc/init.d/apache2 restart

Apache does not care about what users we have on our Bubba server (at least not with this authorization method) so we will create a new list of users that will be used. For the first user and only for the first user use this command.

$ htpasswd -cm /etc/apache2/dav_svn.passwd user

For all the remaining users do no use the -c option as that creates a new file and erases all old users.

$ htpasswd -m /etc/apache2/dav_svn.passwd user2

Create a Repository

Now it's time to create our first repository that we can use. As we are logged in as root we'll change ownership of the repository before we can use it.

$ svnadmin create /var/svn/test
$ chown -R www-data:www-data /var/svn/test 

Testing the Repository

Point your browser to http://bubba/svn/test/ If it works it will ask you for your username and password and then display revision 0 of test.

If http://bubba/ don't work try replacing it with the actual ip-address instead.

Try also http://bubba/svn/ to see all your repositories. If you can view the test repository but not the list of repositories you have forgot the "SVNListParentPath on" line.

If all this works it's time to try it with your favorite SVN-client. On your computer start a shell and type

$ svn co http://bubba/svn/test/

Remove a Repository

To remove a repository log in as root and go to the directory they are stored, list all repositories. 

$ cd /var/svn

$ ls -al

Remove it with.

$ rm test -R

Setting Up SSL

If accessing the server via Internet or an open wireless network, it might be wise to set up some sequrity. Setting up SSL is easy because the Bubba team at Excito have already done most of the work.

All you have to do is to add SSLRequireSSL to /etc/apache2/mods-available/dav_svn.conf See my example configuration file.

# dav_svn.conf
<Location /svn>

DAV svn

SVNParentPath /var/svn
SVNListParentPath on

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

Require valid-user 


After restarting Apache you will no longer be able to access SVN via http:// but only with https://

First time you log in you must approve the self signed certificate.