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 http://www.indiangnu.org/2006/different-methods-of-accessing-subversion-svn-repository/

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:~#

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

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
root@arun:~#

* 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:~#
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
root@arun:~#

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
arunsb:dXxZU5vmHxFoc
ravi:gGEX.dsWcwqzc
santhosh:Jlzed1almY.SY
root@arun:/var/repos_base#

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
root@arun:~#

* 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

#<LimitExcept GET PROPFIND OPTIONS REPORT>
#Require valid-user
#</LimitExcept>

</Location>

## Add entry for other svn repositories

root@arun:~#

* 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 http://www.indiangnu.org/2006/different-methods-of-accessing-subversion-svn-repository/

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
#!/bin/bash

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

SVN_DAEMON=”/usr/bin/svnserve”
PID_FILE=”/var/run/svn-server.pid”
LOG_FILE=”/var/log/svnserve.log”
SVN_PORT=3690
SVN_ROOT=”/var/repos_base”
case “$1” in

start)
if [ -f  $PID_FILE ];then
check=$(cat $PID_FILE)
echo “Subversion service (svnserve) already running [pid = $check]”
else
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.”
fi
;;

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

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

*)
echo “Usage: $0  {start|stop|status}”
exit 1
esac
exit 0
#DONE
root@arun:~#

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

[general]
### 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

root@arun:~#

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 (”)

[groups]
svn_admin = arunsb , ravi

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

[myrepository:/]
@svn_admin= rw

[myrepository:/branches]
@svn_admin = rw
santhosh = r

[myrepository:/trunk]
@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.

[users]

arunsb = 1234
ravi   = 1234
santhosh = 12345
root@arun:~#

Step (4) Start svnserve with following command –

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

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

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

** 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

root@arun:~#

Troubleshooting –

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

* 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://192.168.0.1/myrepository/trunk/   /home/arunsb/working_svn
Authentication realm: <svn://192.168.0.1:3690> ” || Welcome to Subversion Repository ||”
Password for ‘arunsb’:
Checked out revision 2.
arunsb@arun:~$

Thank you,

Arun Bagul

Similar Posts:

Be Sociable, Share!

2 Replies to “Subversion – How to configure with Apache WebDAV or svnserve”

  1. Thank you, Arun! Adding anon-access = none to svnserve.conf solved the issue I was having (svn: Not authorized to open root of edit operation)

Leave a Reply

Your email address will not be published. Required fields are marked *