How to set up a subversion server

October 17th, 2005

I finally decided to move my hobby projects from cvs to subversion. In the process of doing so, I documented the steps I took to get a subversion server up and running on my Fedora core 4 server at home. I suspect the instructions will work on any modern RedHat distribution.

Please note that this article describes how to set up a subversion server using svnserve running through xinetd. It allows either anonymous access or access once the system has authorized a user using CRAM-MD5. This article does not explain how to integrate Subversion into an existing Apache server, nor how to tunnel svn over ssh.

  1. Check to see if subversion is installed.

    $ rpm -q subversion
    

    If you see "package subversion not installed" you will need to install subversion before proceeding. Otherwise you should see something similar to "subversion-1.2.3-2.1".

  2. Login in as root.

  3. Create a user (and group) called svn.

    # groupadd svn
    # useradd -m -g svn -d /var/svn svn
    

    This will create a user called svn with a default group called svn and whose home directory is /var/svn.

  4. Login as the svn user. Since we haven't set a password for the svn user, just su to svn from root.

    # su - svn
    
  5. Create a directory to hold all your repositories.

    $ mkdir /var/svn/repositories
    
  6. Create a repository. In this example we will create a repository called "test".

    $ svnadmin create /var/svn/repositories/test
    
  7. Login in as root again.

  8. Check to see if xinetd is installed.

    # rpm -q xinetd
    

    If you see "package xinetd not installed" you will need to install the package before proceeding. Otherwise you should see something similar to "xinetd-2.3.13-6".

  9. Create tcp service for svn. Edit the /etc/services file and add the following line if it does not already exists:

    svn   3690/tcp   #Subversion
    svn   3690/udp   #Subversion
    

    This identifies the port the svn server will use. In most Linux/Unix installations, this is already defined.

  10. Assuming you want to be able to access subversion remotely from another machine, you will need to configure the firewall to allow access to the svn port. At the appropriate place in your /etc/sysconfig/iptables file insert the following:

    # Svn service
    -A RH-Firewall-1-INPUT -p tcp -s 192.168.69.0/24 --dport 3690 -i eth0 -j ACCEPT
    
  11. Restart the firewall so the changes become active.

    # /etc/rc.d/init.d/iptables restart
    
  12. Create a xinetd entry for the service. Create a file called svn in the /etc/xinetd.d directory. Put the following into the file:

    service svn
    {
            socket_type = stream
            protocol    = tcp
            wait        = no
            user        = svn
            server      = /usr/bin/svnserve
            server_args = -i -r /var/svn/repositories
            disable     = no
    }
    
  13. Restart xinetd so the changes become active.

    # /etc/rc.d/init.d/xinetd restart
    
  14. Trying listing the contents of the repository.

    # svn list svn://localhost/test
    

    There should be no errors and because our repository is currently empty nothing should be listed.

  15. Login again as the svn user.

    # su - svn
    
  16. Edit the file /var/svn/repositories/test/conf/svnserve.conf so that it contains the following:

    ### This file controls the configuration of the svnserve daemon, if you
    ### use it to allow access to this repository.  (If you only allow
    ### access through http: and/or file: URLs, then this file is
    ### irrelevant.)
    
    ### Visit http://subversion.tigris.org/ for more information.
    
    [general]
    ### These options control access to the repository for unauthenticated
    ### and authenticated users.  Valid values are "write", "read",
    ### and "none".  The sample settings below are the defaults.
    anon-access = read
    auth-access = write
    
    ### The password-db option controls the location of the password
    ### database file.  Unless you specify a path starting with a /,
    ### the file's location is relative to the conf directory.
    password-db = passwd
    
    ### This option specifies the authentication realm of the repository.
    ### If two repositories have the same authentication realm, they should
    ### have the same password database, and vice versa.  The default realm
    ### is repository's uuid.
    realm = My First Repository
    

    Make sure that there are no leading spaces on any lines in the file, otherwise subversion will have problems parsing it.

  17. Edit the file /var/svn/repositories/test/conf/passwd so that it contains the following:

    ### This file is an example password file for svnserve.
    ### Its format is similar to that of svnserve.conf. As shown in the
    ### example below it contains one section labelled [users].
    ### The name and password for each user follow, one account per line.
    
    [users]
    harry = harryssecret
    sally = sallyssecret
    

    Once again make sure that there are no leading spaces on any lines in the file.

  18. Set restrictive permissions on the password file.

    $ chmod 600 /var/svn/repositories/test/conf/passwd
    
  19. Try importing source code into the repository. Change to a directory containing the files you want to check in.

    $ svn -m "Imported sources" import svn://data/taylorit/test/trunk
    

    When prompted, enter one of the names and password specified in the passwd file above. If there were no error messages, then the file(s) should be imported into subversion.

  20. In an empty directory try checking out the files.

    $ svn co svn://data/taylorit/test/trunk
    

    If there were no errors, you should see the files you imported in your current directory. Congratulations you got a subversion server up and running!

Note that there are several ways of organizing projects in your repositories. The method above is based on the "one project per repository" method. For more information on repository layouts take a look at chapter 5 from the book Version Control with Subversion.

Current status

TaylorIT is fully booked until November 2010.

Quote worthy

To impose clarity upon complexity through deep and careful design-thinking is the critical achievement of the master programmer. David Gelernter