Subversion Server

How to install and configure Subversion for use in professional development environments. This subversion will run as a module in Apache2 and will use it's own database of users. Installation and configuration of Subversion clients on Windows are also discussed.

Install Subversion Server

Set the USE flags properly and emerge subversion. The output below shows the USE flags on the example server and some of the dependencies. Swig is the Simplified Wrapper and Interface Generator and neon is a DAV client.

root@carbon # emerge -pv subversion

These are the packages that I would merge, in order:

Calculating dependencies ...done!
[ebuild  N    ] dev-lang/swig-1.3.21  -X -guile -java +perl +php -python -ruby -tcltk 1,975 kB
[ebuild  N    ] app-shells/bash-completion-config-0.8-r2  106 kB
[ebuild  N    ] net-misc/neon-0.24.7  -expat +ssl +zlib 589 kB
[ebuild  N    ] dev-util/subversion-1.2.3  +apache2 +bash-completion -berkdb -emacs -java +nls -nowebdav +perl -python +zlib 7,068 kB

Configure Subversion

To run Subversion server one must first create the repository then configure the server type. Subversion can run with its own daemon (svnserve) with or without xinetd, via ssh or over http in Apache2. The example server is setup to use Apache2 and pointers are provided for use with https.

To create the repository use the svnadmin command or use the built in ebuild piece. The ebuild will create the repository as /var/svn and set the owner properly.

root@carbon # ebuild /var/db/pkg/dev-util/subversion-1.2.3/subversion-1.2.3.ebuild config

Configure Apache2

To get Apache2 to host the Subversion stuffs it must be told to load the proper modules. Update the Apache2 start command to enable DAV and SVN. Ensure that the auth_module is loaded in apache2.conf, the SVN module needs it. Specific configuration parameters are located in /etc/apache2/conf/modules.d/47_mod_dav_svn.conf.

root@carbon # grep APACHE2_OPTS /etc/conf.d/apache2
APACHE2_OPTS="-D DAV -D SVN"

root@carbon # grep auth_module /etc/apache2/conf/apache2.conf
LoadModule auth_module                   modules/mod_auth.so

Create the user database for access to the repository. It seems possible to plug this into a different auth database by editing apache2 and 47_mod_dav_svn.conf accordingly. The example server simply uses an htpasswd file in the default location which is set in 47_mod_dav_svn.conf

# First User
root@carbon # htpasswd2 -b -c -m /var/svn/conf/svnusers user1 pass1
# Subsequent Users
root@carbon # htpasswd2 -b -m /var/svn/conf/svnusers userN passN

The the repository is now available on the server at path /svn/repos. This location name is set in 47_mod_dav_svn.conf and can be altered, specifically a dedicated source server could be placed at the root by setting <Location />.

Create Readonly Repo

# Readonly SVN
<Location /svn>
    DAV svn
    SVNPath /opt/example.com/project-alpha/repo.copy/
    # AuthType Basic
    # AuthName "Edoceo"
    # AuthUserFile /opt/example.com/project-alpha/htpasswd
    # Require valid-user
    #  GET PROPFIND OPTIONS CHECKOUT REPORT MKACTIVITY PROPPATCH PUT MKCOL MOVE COPY DELETE LOCK UNLOCK MERGE
    <Limit GET PROPFIND OPTIONS CHECKOUT REPORT>
        Allow from any
    </Limit>
    <Limit MKACTIVITY PROPPATCH PUT MKCOL MOVE COPY DELETE LOCK UNLOCK MERGE>
        Deny from all
    </Limit>
</Location>

Restrict Access to ".svn" Directory

Now is also a good time to configure Apache to block access to the Subversion working-copy directories. If for example you were to svn export to a webroot we don't want outsiders viewing our code.

We generally place this near the top of the Apache configuration to ensure it applies server-wide

<DirectoryMatch .*\.svn/.*>
    Deny From All
</DirectoryMatch>

Subversion Repo Permissions

Subversion over Apache DAV can also take advantage of the AuthzSVNAccessFile configuration which points to a ACL definition file. The file is similar to the common .ini format.

Configure Apache as follows

SVNPath /var/svn/repos
AuthUserFile /var/svn/conf/htpasswd
AuthzSVNAccessFile /var/svn/conf/svnaccess

Here is an example ini file

[groups]
dev = code@edoceo.com
adm = root@edoceo.com

[/]
@dev = r
@adm = rw

[/one/project]
* =
@dev = rw
@adm = r

[/other/trunk]
* = r
@dev = r
@adm = rw

Subversion Windows Client

There are many Subversion clients available for many systems. The Subversion project directly provides a CLI that will run on Windows, TortiseSVN is a Windows shell extension that looks pretty and has lots of features. Get it from their respective home pages (link below) and go crazy.

See Also

ChangeLog