How to set up a Subversion (SVN) server on GNU/Linux - Ubuntu [closed]

Steps I've taken to make my laptop a Subversion server. Credit must go to AlephZarro for his directions here. I now have a working SVN server (which has currently only been tested locally).

Specific setup: Kubuntu 8.04 Hardy Heron

Requirements to follow this guide:

  • apt-get package manager program
  • text editor (I use kate)
  • sudo access rights

1: Install Apache HTTP server and required modules:

sudo apt-get install libapache2-svn apache2

The following extra packages will be installed:

apache2-mpm-worker apache2-utils apache2.2-common

2: Enable SSL

sudo a2enmod ssl
sudo kate /etc/apache2/ports.conf

Add or check that the following is in the file:

<IfModule mod_ssl.c>
    Listen 443
</IfModule>

3: Generate an SSL certificate:

sudo apt-get install ssl-cert
sudo mkdir /etc/apache2/ssl
sudo /usr/sbin/make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/apache2/ssl/apache.pem

4: Create virtual host

sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/svnserver
sudo kate /etc/apache2/sites-available/svnserver

Change (in ports.conf):

"NameVirtualHost *" to "NameVirtualHost *:443"

and (in svnserver)

<VirtualHost *> to <VirtualHost *:443>

Add, under ServerAdmin (also in file svnserver):

SSLEngine on
SSLCertificateFile /etc/apache2/ssl/apache.pem
SSLProtocol all
SSLCipherSuite HIGH:MEDIUM

5: Enable the site:

sudo a2ensite svnserver
sudo /etc/init.d/apache2 restart

To overcome warnings:

sudo kate /etc/apache2/apache2.conf

Add:

"ServerName $your_server_name"

6: Adding repository(ies): The following setup assumes we want to host multiple repositories. Run this for creating the first repository:

sudo mkdir /var/svn

REPOS=myFirstRepo
sudo svnadmin create /var/svn/$REPOS
sudo chown -R www-data:www-data /var/svn/$REPOS
sudo chmod -R g+ws /var/svn/$REPOS

6.a. For more repositories: do step 6 again (changing the value of REPOS), skipping the step mkdir /var/svn

7: Add an authenticated user

sudo htpasswd -c -m /etc/apache2/dav_svn.passwd $user_name

8: Enable and configure WebDAV and SVN:

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

Add or uncomment:

<Location /svn>
DAV svn

# for multiple repositories - see comments in file
SVNParentPath /var/svn

AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/dav_svn.passwd
Require valid-user
SSLRequireSSL
</Location>

9: Restart apache server:

sudo /etc/init.d/apache2 restart

10: Validation:

Fired up a browser:

http://localhost/svn/$REPOS
https://localhost/svn/$REPOS

Both required a username and password. I think uncommenting:

<LimitExcept GET PROPFIND OPTIONS REPORT>

</LimitExcept>

in /etc/apache2/mods-available/dav_svn.conf, would allow anonymous browsing.

The browser shows "Revision 0: /"

Commit something:

svn import --username $user_name anyfile.txt https://localhost/svn/$REPOS/anyfile.txt -m “Testing”

Accept the certificate and enter password. Check out what you've just committed:

svn co --username $user_name https://localhost/svn/$REPOS

Following these steps (assuming I haven't made any error copy/pasting), I had a working SVN repository on my laptop.


Afterwards, I needed to execute (within the context of the example quoted above)

$ sudo chmod g+w /var/svn/$REPOS/db/rep-cache.db

$ sudo chown www-data:www-data /var/svn/$REPOS/db/rep-cache.db

Otherwise I kept receiving a 409 error when committing local modifications (though the commitments were server side effective, I needed to follow up with local updates)


If you get 403 forbidden when you hit the webserver it may be because you used a hostname that is not what you specified in your config file (ie localhost or 127.0.0.1). Try hitting https://whateveryousetasyourhostname instead...