Simple SVN Server

I’ve recently started to teach a friend of mine, with an aspiration to embark on a career in software development, how to program. One of the aspects of software development that people often don’t get exposure to when learning how to program is version control systems. This omission means that a lot of the time when a person begins their career as a software developer their first exposure to version control systems is during their first job (if they’re not unlucky enough to work somewhere that doesn’t use version control!).

I thought it would be useful for my friend to get to grips with SVN from the get go as it’s relatively simple to learn compared to Git. I had a look for some free options that would provide multiple users for a single repository but it seemed that most of the basic SVN hosting packages only offered a single user repository. Seeing as I had a spare Raspberry Pi kicking about I thought why not set it up as an SVN server and host the server next to the Raspberry Pi that hosts this site putting it under the same domain.

For the initial set up of Raspbian you might want to follow the steps from my tutorial setting up raspbian with a web server in mind as this allows Raspbian to run from a USB stick which is more reliable than running from an SD card.

Following the set-up of Raspbian I carried out the steps below.

Subversion Installation

Install the Subverion package via the APT package handling utility.

sudo apt-get install subversion

Create a repository directory

Run the command below, the ‘-p’ flag creates nested directories if they don’t already exist. This directory will be the place all of your repositories will go, we are only going to be creating a single repository during this tutorial.

mkdir -p /home/pi/repos

Create a new empty repository

Create a new empty repository in the new ‘repos’ directory. The previous step was required as svnadmin doesn’t create intermediate repositories.

sudo svnadmin create /home/pi/repos/test

Create a project directory

mkdir -p /home/pi/projects/test

Import the project

sudo svn import /home/pi/projects/test/ file://localhost/home/pi/repos/test

This completes the set up of SVN – it’s so simple that there is no reason to not use a version control system!  Now we need to provide remote web access so that the SVN repository can be accessed remotely.

Install Apache components

To enable web access requires the installation of the Apache web server and Apache Subversion server module.

sudo apt-get install apache2 libapache2-svn

Restrict access control

As the repository can be publicly accessed we want to restrict access so that a username and password are required to check out the repository and to commit changes to the repository.

Open the apache svn module configuration file.

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

Append the following to the bottom of the file then save and close.

<Location /svn>
DAV svn
SVNParentPath /home/pi/repos
AuthType Basic
AuthName "Subversion Repo"
AuthUserFile /etc/apache2/dav_svn.passwd
<LimitExcept GET="" PROPFIND="" OPTIONS="" REPORT="">
Require valid-user

Restart Apache

Restarting Apache is required so that the new configuration settings take effect.

sudo /etc/init.d/apache2 restart

Update permissions

Give the SVN server permission to modify the repository directory.

sudo chown -R www-data:www-data /home/pi/repos

Create users

I needed to create two users, one for me and one for my friend.

Create the first user, you will be asked to provide a password.

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

Notice that after creating the first user you should omit the ‘-c’ flag this is used to create the passwdfile and will overwrite the file if you use it again.

Create the second user, again you will be asked to provide a password.

sudo htpasswd /etc/apache2/dav_svn.passwd tom

The SVN server should now be accessible via a suitable SVN client. My favourite client for Windows is TortoiseSVN.

If you want to be able to access the server externally follow step 4 onwards in my tutorial Setting up WordPress on a Raspberry Pi.

I’ve been successfully running SVN on my raspberry PI for over a month with no down time. This has allowed my friend to get to grips with C# (and version control!) by building his very own version of the classic game pong!