Month: February 2009

Subversion – How to configure with Apache WebDAV or svnserve

Subversion – How to configure with Apache WebDAV or svnserve

1] What is Subversion?

Subversion is a beautiful free/open source tool (software) to manage changes made to your information. Subversion manages files and directories, and the changes made to them over time. This allows you to recover older versions of your data or examine the history of how your data changed. Subversion can operate across networks, which allows it to be used by people on different computers.

2] Different methods of accessing subversion (svn) repository ?

There are three different methods of accessing subversion repository…

a) Local filesystem or Network filesystem accessed by client directly
b) Apache HTTP using WebDAV module
c) svnserve tunneled over an SSH (svn + ssh)

For more informatio, please refer the article

3] Subversion architectue –

Subversion provides two backends to store the data in svn repository

a) FSFS – Fast and Secure File Systtem –

FSFS backend provides quite a bit more flexibility in terms of its supported deployment scenarios. More flexibility means you have to work a little harder to find ways to deploy it incorrectly. FSFS is the default backend

b) Berkeley DB File system –

Berkeley DB provides real transaction support—perhaps its most powerful feature. Another great feature of Berkeley DB is hot backups—the ability to backup the database environment without taking it “offline”. But Berkeley DB environments are not portable!!

root@arun:~# ls -l  /var/repos_base/myrepository/
total 28
drwxr-xr-x 2 arunsb www-data 4096 2008-12-27 15:30 conf
drwxr-xr-x 2 arunsb www-data 4096 2008-12-26 16:34 dav
drwxr-sr-x 5 arunsb www-data 4096 2008-12-27 15:27 db
-r–r–r– 1 arunsb www-data    2 2008-12-26 16:34 format
drwxr-xr-x 2 arunsb www-data 4096 2008-12-26 16:34 hooks
drwxr-xr-x 2 arunsb www-data 4096 2008-12-26 16:34 locks
-rw-r–r– 1 arunsb www-data  229 2008-12-26 16:34 README.txt

root@arun:~# cat /var/repos_base/myrepository/db/fs-type

4] How Install Subversion –

Ubuntu –

root@arun:~# apt-get install  subversion  subversion-tools
5] How to configure Subversion with Apache HTTP and WebDAV module –

Step (1) First of all we need to create the subversion repository….

root@arun:~# svnadmin create /var/repos_base/myrepository

* Make sure to set/change owership/permission of svn repository for Apache webserver user (www-data is apache user)

root@arun:/var/repos_base# chown arunsb:www-data -R /var/repos_base/
root@arun:~# chmod  775 -R /var/repos_base/
root@arun:~# ls -l /var/repos_base/
-rwxrwxr-x 1 arunsb www-data   63 2008-12-03 15:50 common_userdb
drwxrwxr-x 7 arunsb www-data 4096 2008-12-03 15:48 myrepository

Step (2) Authentication – common user DB for all repositories –

Let us create a file “/var/repos_base/common_userdb” which will contain users information in file and add few users…

root@arun:/var/repos_base# htpasswd  -c /var/repos_base/common_userdb   arunsb
New password:
Re-type new password:
Adding password for user arunsb

root@arun:/var/repos_base# htpasswd  /var/repos_base/common_userdb  ravi
New password:
Re-type new password:
Adding password for user ravi

root@arun:/var/repos_base# htpasswd  /var/repos_base/common_userdb  santhosh
New password:
Re-type new password:
Adding password for user santhosh

root@arun:/var/repos_base# cat /var/repos_base/common_userdb

Step (3) Now install Apache , WebDav module for apache –

Ubuntu –

root@arun:~# apt-get install apache2  apache2.2-common  libapache2-svn

you need to enable to WebDAV svn module for apache using following command on Ubuntu…

root@arun:~# a2enmod dav   dav_svn

* Make sure that Apache is running ….

Step (4) Configure svn repository with apache –

root@arun:~# cat /etc/apache2/mods-available/dav_svn.conf
# dav_svn.conf – Subversion/Apache configuration

<Location /myrepository>

DAV svn

#You need either SVNPath and SVNParentPath, but not both.
#use SVNParentPath if you have multiple repositories under one directory

SVNPath /var/repos_base/myrepository
#SVNParentPath /var/repos_base

# Access control is done at 3 levels –
#(1) Apache authentication
#(2) Apache <Limit> and <LimitExcept>
#(3) mod_authz_svn is a svn-specific authorization module

AuthType Basic
AuthName “|| Welcome to Subversion Repository || ”
AuthUserFile /var/repos_base/common_userdb

#To enable authorization via mod_authz_svn
AuthzSVNAccessFile  /var/repos_base/myrepository/conf/authz
Require valid-user

#Require valid-user


## Add entry for other svn repositories


* Once done restart the Apache server and try to access svn repository as …

root@arun:~# svn list http://server_name_or_IP/your_repository_name_mentioned_in_dav_svn.conf_file

please refer the article for more operation

6] How to configure Subversion with svnserve tunneled over an SSH (svn + ssh) –

Step (1) Make sure that subversion is installed and repository is created…

Start up script for svnserve is as shown below (ubuntu), please update this file with proper setting…

root@arun:~# cat /etc/init.d/svnserve

# startup script for svn server!
## svnserve  –daemon  –listen-port   3690  –pid-file /var/run/svn.server

case “$1” in

if [ -f  $PID_FILE ];then
check=$(cat $PID_FILE)
echo “Subversion service (svnserve) already running [pid = $check]”
echo “Starting the Subversion service (svnserve)..”
$SVN_DAEMON  –daemon –root $SVN_ROOT  –listen-port $SVN_PORT –pid-file $PID_FILE  > $LOG_FILE 2>&1
echo “log file is $LOG_FILE”
echo “…”
echo “Done.”

echo “killing Subversion service (svnserve)…”
if [ -f  $PID_FILE ];then
#killall svnserve
kill -9 $(cat $PID_FILE)
echo “…”
echo “Done.”
echo “NOT running…”

if [ -f  $PID_FILE ];then
echo “Subversion service (svnserve) -”
pid_of_svnserve=$(cat $PID_FILE)
echo -e “Running & pid is $pid_of_svnserve”
echo “Subversion service (svnserve) NOT running…”

echo “Usage: $0  {start|stop|status}”
exit 1
exit 0

Step (2) svnserve  configuration –

root@arun:~# cat /var/repos_base/myrepository/conf/svnserve.conf
### This file controls the configuration of the svnserve daemon, if you

### Authenticated users.  Valid values are “write”, “read”,
### and “none”.  The sample settings below are the defaults.
### The password-db option controls the location of the password file
### The authz-db option controls the location of the authorization
### rules for path-based access control.

realm = || Welcome to Subversion Repository ||
anon-access = none
auth-access = write
authz-db = authz
password-db = passwd


Step (3) Authentication for svnserve –

root@arun:~# cat /var/repos_base/myrepository/conf/authz
# single user, to a group of users defined in a special [groups]
# section, or to anyone using the ‘*’ wildcard.  Each definition can
# grant read (‘r’) access, read-write (‘rw’) access, or no access (”)

svn_admin = arunsb , ravi

# remember here svn name which you mentioned in “dav_svn.conf” file

@svn_admin= rw

@svn_admin = rw
santhosh = r

@svn_admin= rw
santhosh = rw

root@arun:~# cat /var/repos_base/myrepository/conf/passwd
### Below it contains one section labelled [users].
### The name and password for each user follow, one account per line.


arunsb = 1234
ravi   = 1234
santhosh = 12345

Step (4) Start svnserve with following command –

root@arun:~# /etc/init.d/svnserve
Usage: /etc/init.d/svnserve  {start|stop|status}
root@arun:~# /etc/init.d/svnserve  start
Starting the Subversion service (svnserve)..
log file is /var/log/svnserve.log

root@arun:~# /etc/init.d/svnserve  status
Subversion service (svnserve) –
Running & pid is 11346

root@arun:~# netstat -nlp |  grep svnserve
tcp        0      0  *               LISTEN      11346/svnserve

** HELP ?

root@arun:~# svnserve  –help
usage: svnserve [options]

Valid options:
-d [–daemon]            : daemon mode
–listen-port arg        : listen port (for daemon mode)
–listen-host arg        : listen hostname or IP address (for daemon mode)
–foreground             : run in foreground (useful for debugging)
-h [–help]              : display this help
–version                : show program version information
-i [–inetd]             : inetd mode
-r [–root] arg          : root of directory to serve
-R [–read-only]         : force read only, overriding repository config file
-t [–tunnel]            : tunnel mode
–tunnel-user arg        : tunnel username (default is current uid’s name)
-T [–threads]           : use threads instead of fork
-X [–listen-once]       : listen once (useful for debugging)
–pid-file arg           : write server process ID to file arg


Troubleshooting –

arunsb@arun:~$ svn co svn://  /tmp/12345
svn: Not authorized to open root of edit operation

* please add “anon-access = none” to ‘svnserve.conf’ conf file of your repository…

root@arun:~# vi /var/repos_base/myrepository/conf/svnserve.conf

arunsb@arun:~$ svn co svn://   /home/arunsb/working_svn
Authentication realm: <svn://> ” || Welcome to Subversion Repository ||”
Password for ‘arunsb’:
Checked out revision 2.

Thank you,

Arun Bagul