Sunday, September 20, 2015

Installing Subversion with Apache on Debian


This tutorial is written for Apache 2.2.22 and Subversion 1.6.17. This document will not be updated.

Install packages

As a first step we need to install all required packages.

sudo apt-get update
sudo apt-get install apache2
sudo apt-get install subversion
sudo apt-get install libapache2-svn

Include Apache modules

Here we activate some required apache modules

sudo a2enmod dav
sudo a2enmod dav_svn
sudo a2enmod ssl

Create directory structure

Next we create the directory structure.

  • public: Root directory of the virtual host container
  • repo: Directory that contains all subversion repositories
  • auth: Directory that contains all htpasswd files
  • ssl: Directory that contains the ssl cert and key
sudo mkdir /var/www/
sudo mkdir /var/www/
sudo mkdir /var/www/
sudo mkdir /var/www/
sudo mkdir /var/www/

Create repository

Next we create a first repository

sudo svnadmin create /var/www/

Create group

Then we create the necessary groups

sudo groupadd subversion
sudo addgroup you subversion

Create credentials for login

As we authenticate with http basic method we create a password file

sudo htpasswd -c /var/www/ you

Create SSL certificate

When requesting a new certificate, it is possible to specify with -days how long the certificate will remain valid. In the example below it's 365 days. This will create both, the self-signed SSL certificate and the server key that protects it.

sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /var/www/ -out /var/www/
After that a prompt appears that will ask us some questions.

You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
Country Name (2 letter code) [AU]:US
State or Province Name (full name) [Some-State]:New York
Locality Name (eg, city) []:NYC
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Your Inc
Organizational Unit Name (eg, section) []:Dept of something
Common Name (e.g. server FQDN or YOUR name) []                  
Email Address []

Create the virtualhost

Next we create a virtualhost entry: /etc/apache2/sites-available/

<VirtualHost *:443>
  ErrorLog /var/log/apache2/
  CustomLog /var/log/apache2/ combined
  DocumentRoot /var/www/
  <Directory "/var/www/">
    Order allow,deny
    Allow from all

  SSLEngine on
  SSLCertificateFile /var/www/
  SSLCertificateKeyFile /var/www/

  # Test project
  <Location /svn/test-project>
    DAV svn
    SVNPath /var/www/
    AuthType Basic
    AuthName "Test-Project Server Repo"
    AuthUserFile /var/www/
    Require valid-user

Activate the virtualhost directive

Apache looks for files in /etc/apache2/sites-enabled. So you need to create a symlink.

cd /etc/apache2/sites-enabled/
sudo ln -s ../sites-available/ .

Set the right permissions

It is important that you set the right permissions so that apache can write data in to the svn repository and can also read the htpasswd file.

sudo chown -R www-data:subversion /var/www/

Reload Apache

service apache2 restart

Test Url

You should now be able to connect to

No comments:

Post a Comment