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

Grundlefleck picture Grundlefleck · Sep 13, 2008 · Viewed 213.3k times · Source

I have a laptop running Ubuntu that I would like to act as a Subversion server. Both for myself to commit to locally, and for others remotely. What are the steps required to get this working? Please include steps to:

  • Get and configure Apache, and necessary modules (I know there are other ways to create a SVN server, but I would like it Apache-specific)
  • Configure a secure way of accessing the server (SSH/HTTPS)
  • Configure a set of authorised users (as in, they must authorised to commit, but are free to browse)
  • Validate the setup with an initial commit (a "Hello world" of sorts)

These steps can involve any mixture of command line or GUI application instructions. If you can, please note where instructions are specific to a particular distribution or version, and where a users' choice of a particular tool can be used instead (say, nano instead of vi).

Answer

Grundlefleck picture Grundlefleck · Sep 13, 2008

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.