On running a Subversion server

June 2007


Subversion is the Version Control System of choice for most people in the environment I work in (Computing Science students and systems administrators). A good source of documentation is the Red Bean Book. Subversion is easily installed by apt-get install subversion.

Procedure 45.  Creating a SVN repository

  1. Create the repository on the server: svnadmin create /var/lib/svn/grid

  2. Import the layout of the repository: svn import template/ file:///var/lib/svn/grid -m "initial import"

Procedure 46.  Creating a Subversion server using Apache(version 2)

  1. Create a separate system group 'svn': addgroup --system --group svn

  2. Change ownership of created repositories: chgrp -R svn:svn /var/lib/svn/

  3. Add the apache user to the 'svn' group [22] : adduser www-data svn

  4. Add some more users to the 'svn' group: adduser username svn [23]

  5. Install mod_dav by apt-get install libapache2-svn.

  6. Edit /etc/apache2/mods-available/svn.conf to contain

      <Location /svn>
      DAV svn
      
      # any "/svn/foo" URL will map to a repository /usr/local/svn/foo
      SVNParentPath /var/lib/svn
      
      AuthType Basic
      AuthName "Subversion repository on myhost.com"
      AuthUserFile /etc/subversion/passwd
      
      <LimitExcept GET PROPFIND OPTIONS REPORT>
      Require valid-user
      </LimitExcept>
      
      Order deny,allow
      Deny from all
      # Localhost
      Allow from 127.0.0.1
      Allow from 192.168.5.0/24
      
      </Location>
    	

    1. Enable the configuration: cd /etc/apache2/mods-enabled && ln -s ../mods-available/svn.conf ./.

    2. And reload the Apache configuration: /etc/init.d/apache reload

  7. Create a new passwd file for Apache and put a username/passwd in it. htpasswd -cs /etc/subversion/passwd username

Procedure 47.  Using the Apache SVN server

  1. Check out [24] an (empty) working copy with cd / && svn co http://myserver.com/svn/repository/project/trunk/ ./

  2. Add files to subversion control using svn add /etc

  3. Commit it like this: svn commit -m"Adding /etc"

Procedure 48.  Enabling ssh access to the Subversion repository

  • Nothing needs to be done. Just link /svn to /var/lib/svn for convenience and use it saying svn co svn+ssh://myhost.com/svn/repository/project/trunk ./



[22] We are assuming here that Apache is already installed

[23] I think membership of this group is only important if it is required by Apache asking for it in a 'require' statement. When a user logs in via the web server, all writing of the repositories is done by the web server. But is it nice anyway in case a user wants to do file-based access instead of via the web server.

[24] I tried to use the svn import command to do the initial fill of the project, but it failed giving a 405 (resource not allowed) error on the PROPFIND request in the Apache logs. The checkout and commit works fine so I won't spend time on it.