Playing with SVN

Posted by DineshPremalal on Mon 20 Mar 2006 at 10:15

Today I started to set up a SVN repository for our final year project. I tried to setup a SVN server using Apache2 so that the SVN repository is available to the client through the WebDAV/DeltaV protocol. Read on for a trial-and-error introduction.

The Version Control with Subversion book (by Ben Collins-Sussman, Brian W. Fitzpatrick & C. Michael Pilato) was very useful to me when I struggled with SVN. The e-version of the book also available for free.

After installing subversion I found it inside the directory /usr/share/doc/subversion/book.

First I installed apache2 using apt-get

#apt-get install apache2

Then subversion:

#apt-get install subversion

In order to setup subversion with apache2, we need to use the mod_dav_svn module. Here I tried to use the pre-compiled version from the Debian repositories because otherwise the process get more complicated.

/**
 * If you really need to compile apache2 and subversion your self the following
 * link might help you. But I *didn't get dirty with it. :)
 * http://www.linuxjournal.com/article/7655
 */

Now I need to install mod_dav_svn module. I tried serveral searches using aptitude. Then I found out that libapache2-svn package provides mod_dav_svn plugin, so I installed it.

#apt-get install libapache2-svn

The most interesting part is, when we install pre-compiled package using apt-get or aptitude they edit configaration files accordingly.

When we install apache2 it installs configuration files in the /etc/apache2 directory. Modules are placed inside /usr/lib/apache2/modules.

In normal installation we found only httpd.conf for managing httpd server's configuration but in Debian we manipulate two configuration files namely "apache2.conf" and "httpd.conf".

As the book stated I edited httpd.conf as following:

LoadModule dav_module      /usr/lib/apache2/modules/mod_dav.so
LoadModule dav_svn_module /usr/lib/apache2/modules/mod_dav_svn.so

After restarted httpd server:

debian:/etc/apache2# /etc/init.d/apache2 restart
Forcing reload of web server: Apache2[Sun Mar 05 20:21:41 2006] [warn] module dav_module is already loaded, skipping
[Sun Mar 05 20:21:41 2006] [warn] module dav_svn_module is already loaded, skipping
[Sun Mar 05 20:21:42 2006] [warn] module dav_module is already loaded, skipping
[Sun Mar 05 20:21:42 2006] [warn] module dav_svn_module is already loaded, skipping

It seems that module already loaded then, so I commented out that newly added two lines (little devation from the book).

debian:/etc/apache2# /etc/init.d/apache2 restart
Forcing reload of web server: Apache2.

Since my intention was to have more repositories in the svn, I added following lines to the apache2.conf:

<Location /svn>
  DAV svn
  # any "/svn/foo" URL will map to a repository /home/dinesh/svn/foo
  SVNParentPath /home/dinesh/svn (absolute path to repository)
</Location>

Then I created repository using 'svnadmin':

$svnadmin create file:///home/dinesh/svn/repos

Then created directory in that repository:

$svn mkdir file:///home/dinesh/svn/repos/guththila

First I tried to acces repository using the http:// protocol but it didn't work :

dinesh@debian:~/tmp$ svn checkout http://127.0.0.1/svn/repos/guththila project
svn: PROPFIND request failed on '/svn/repos/guththila'
svn:
Could not open the requested SVN filesystem

Then tried to use the repository using web http://127.0.0.1/svn/repos/guththila:

<d:error>
<c:error>
<m:human-readable errcode="160029">
 Could not open the requested SVN filesystem
</m:human-readable>
</c:error>
</d:error>

The Apache error log (in /var/log/apache/error.log) said:

[error] [client 127.0.0.1] (20014)Error string not specified yet:
  Berkeley DB error while opening 'nodes' table for filesystem
   /home/dinesh/svn/repos/db:
   Permission denied

It seems that there was a problem in permissions. I set permissions of the svn repository to the 777

#chmod -R 777 svn

Then I was able to acces the repository through the web browser using the URL http://127.0.0.1/svn/repos/.

At one point I came across a database error. The Apache error log said:

[error] [client 127.0.0.1] (20014)Error string not specified yet: 
  Berkeley DB error while opening environment for filesystem 
  /home/dinesh/svn/repos/db:
  DB_RUNRECOVERY: Fatal error, run database recovery

After seaching on the web found a similar problem it said to goto the repository db folder and run db_recovery.

$ cd ~/svn/repos/db
dinesh@debian:~/svn/repos/db$ db4.2_recover

This recovered the database.

Now everything works fine but when I tried to commit into the repository:

$svn commit -m "test"
svn: Commit failed (details follow):
svn: MKACTIVITY of '/svn/repos/!svn/act/3033bdb6-400e-0410-9aed-b2743e91598e': 500 Internal Server Error (http://localhost)

This happened because of I didn't have authentication method for my svn repository.

# htpasswd -cm /etc/svn-passwd dinesh
New password:
Re-type new password:
Adding password for user dinesh

# htpasswd /etc/svn-passwd -m thilina
New password:
Re-type new password:
Adding password for user thilina

I added the following lines to the apache2.conf:

<Location /svn>
  DAV svn
  SVNParentPath /usr/local/svn
  AuthType Basic
  AuthName "Subversion repository"
  AuthUserFile /etc/svn-passwd
</Location>

With this method the password is transmitted as plain text over the network.

Now I'm able to acces and commit SVN repository over the network!

I still need to configure the SVN repository to use SSL. I'll post the steps that I followed to configure SVN with SSL also.

If you interested please look at my weblog for original article

This article can be found online at the Debian Administration website at the following bookmarkable URL:

This article is copyright 2006 DineshPremalal - please ask for permission to republish or translate.