Home

Debian/Ubuntu Tips & Tricks

Debuntu.org: .deb packages, Unix/Linux Tutorials and Articles.

sponsors


User login

Poll

Syndicate

Syndicate content


Tips


How To: subversion SVN with Apache2 and DAV

Subversion is an application used for version control, it is meant to become a replacement of CVS Concurrent Versions System. Subversion is also known as svn.

This how-to will show how to setup svn repositories accessible throught http by using apache2 and the DAV module.

This tutorial is splitted in 4 parts: install neccessary packages, create the repository structure, configure apache and create the first repository.

Neccessary packages:

First of all we need to install the required packages:

apt-get install subversion libapache2-svn

Repository structure:

The projects are going to be hosted on /var/svn/repository. We need to create to directories and give full permission to the apache user:

mkdir /var/svn
mkdir /var/svn/repository

Now that the directory exist, we need to give write access to the apache user:

chown www-data:www-data -R /var/svn/repository
chmod 770 -R /var/svn/repository

Configuring Apache:

Now, we need to modify apache svn module configuration file, edit /etc/apache2/mods-available/dav_svn.conf and make sure the following argument are properly setted up:

...
SVNParentPath /var/svn/repository
#SVNPath /var/svn/repository
.....
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/dav_svn.passwd
Require valid-user
...

In order to be able to track who modify the different files of the project, we need to create users. Create the first user (tester) and supply a password:

htpasswd2 -c /etc/apache2/dav_svn.passwd tester

Creating a first repository:
Get apache user access (so files and directories are created with proper rights:

su www-data

and create your first repository (example):

svnadmin create /var/svn/repository/example

import your project:

svn import /path/to/projectexample file:///var/svn/repository/example/examplev1 -m"initial import"

Now, get back to root user (Ctrl-D) and restart apache:

/etc/init.d/apache2 restart

Your project is now avalaible to the different user you will add in /etc/apache2/dav_svn.passwd .
User tester can now access the project at http://svnhostaddress/example and checkout a first copy to his computer, modify files and commit back his changes to the server.

Reference: SVN online Book.

Debian Tip

This is a very succinct tutorial that got me unstuck when trying to set up WebDAV. There are a few things I would add from my experience with installing this on Debian Sid (Unstable) using Apache 2.2. First of all, Debian's default configuration is to use virtual hosts. You can't edit the /etc/apache2/mods-available/dav_svn.conf file and enable DAV there if you are using virtual hosts. Instead, I just imported the text from that file into my site's config file (in this case, the virtual host config file in /etc/apache2/sites-available/ was named "default"). Actually, I imported the text twice: once for the NamedVirtualHost *:80 section and once for the NamedVirtualHost *:443 section so that it would work both for http and https sessions. Then I configured the file there to point to the proper places. Of course, this assumes that you have correctly installed and configured SSL.

Another thing that had me stuck for a while is that if you use the SVNParentPath directive, you can't pull up the svn directory in your browser by going to the svn root (i.e., http://localhost/svn assuming that your svn path declared in the virtual host config file points to /svn). Whenever I tried that, I got an http error that said I'm not authorized to be in that directory. You must instead use the sub-repository URL, as in, for example, http://localhost/svn/my_repository. That solved my problem.

Here's what my "default" config file looks like:

NameVirtualHost *:443
NameVirtualHost *:80

	ServerAdmin webmaster@localhost
	
	DocumentRoot /var/www/
	
		Options FollowSymLinks
		AllowOverride None
	
#	
#		Options Indexes FollowSymLinks MultiViews
#		AllowOverride None
#		Order allow,deny
#		allow from all
#		# This directive allows us to have apache2's default start page
#               # in /apache2-default/, but still have / go to the right place
#                RedirectMatch ^/$ /apache2-default/
#	

	ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
	
		AllowOverride None
		Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
		Order allow,deny
		Allow from all
	

	ErrorLog /var/log/apache2/error.log

	# Possible values include: debug, info, notice, warn, error, crit,
	# alert, emerg.
	LogLevel warn

	CustomLog /var/log/apache2/access.log combined
	ServerSignature On

    Alias /doc/ "/usr/share/doc/"
    
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    

### Start read-in of /etc/apache2/mods-available/dav_svn.conf
# dav_svn.conf - Example Subversion/Apache configuration
#
# For details and further options see the Apache user manual and
# the Subversion book.
#
# NOTE: for a setup with multiple vhosts, you will want to do this
# configuration in /etc/apache2/sites-available/*, not here.

#  ... 
# URL controls how the repository appears to the outside world.
# In this example clients access the repository as http://hostname/svn/
# Note, a literal /svn should NOT exist in your document root.


  # Uncomment this to enable the repository
DAV svn

  # Set this to the path to your repository
#SVNPath /var/svn
  # Alternatively, use SVNParentPath if you have multiple repositories under
  # under a single directory (/var/lib/svn/repo1, /var/lib/svn/repo2, ...).
  # You need either SVNPath and SVNParentPath, but not both.
SVNParentPath /var/svn

  # Access control is done at 3 levels: (1) Apache authentication, via
  # any of several methods.  A "Basic Auth" section is commented out
  # below.  (2) Apache  and , also commented out
  # below.  (3) mod_authz_svn is a svn-specific authorization module
  # which offers fine-grained read/write access control for paths
  # within a repository.  (The first two layers are coarse-grained; you
  # can only enable/disable access to an entire repository.)  Note that
  # mod_authz_svn is noticeably slower than the other two layers, so if
  # you don't need the fine-grained control, don't configure it.

  # Basic Authentication is repository-wide.  It is not secure unless
  # you are using https.  See the 'htpasswd' command to create and
  # manage the password file - and the documentation for the
  # 'auth_basic' and 'authn_file' modules, which you will need for this
  # (enable them with 'a2enmod').
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/dav_svn.passwd
Require valid-user
  # To enable authorization via mod_authz_svn
  #AuthzSVNAccessFile /etc/apache2/dav_svn.authz

  # The following three lines allow anonymous read, but make
  # committers authenticate themselves.  It requires the 'authz_user'
  # module (enable it with 'a2enmod').
  #
    #Require valid-user
  # 



### End read-in of /etc/apache2/mods-available/dav_svn.conf






	ServerAdmin webmaster@localhost
	
	DocumentRoot /var/www/
	
		Options FollowSymLinks
		AllowOverride None
	
#	
#		Options Indexes FollowSymLinks MultiViews
#		AllowOverride None
#		Order allow,deny
#		allow from all
#		# This directive allows us to have apache2's default start page
#               # in /apache2-default/, but still have / go to the right place
#                RedirectMatch ^/$ /apache2-default/
#	

	ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
	
		AllowOverride None
		Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
		Order allow,deny
		Allow from all
	

	ErrorLog /var/log/apache2/error.log

	# Possible values include: debug, info, notice, warn, error, crit,
	# alert, emerg.
	LogLevel warn

	CustomLog /var/log/apache2/access.log combined
	ServerSignature On

	SSLEngine on
	SSLCertificateFile /etc/apache2/apache.pem	

    Alias /doc/ "/usr/share/doc/"
    
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    

### Start read-in of /etc/apache2/mods-available/dav_svn.conf
# dav_svn.conf - Example Subversion/Apache configuration
#
# For details and further options see the Apache user manual and
# the Subversion book.
#
# NOTE: for a setup with multiple vhosts, you will want to do this
# configuration in /etc/apache2/sites-available/*, not here.

#  ... 
# URL controls how the repository appears to the outside world.
# In this example clients access the repository as http://hostname/svn/
# Note, a literal /svn should NOT exist in your document root.


  # Uncomment this to enable the repository
DAV svn

  # Set this to the path to your repository
#SVNPath /var/svn
  # Alternatively, use SVNParentPath if you have multiple repositories under
  # under a single directory (/var/lib/svn/repo1, /var/lib/svn/repo2, ...).
  # You need either SVNPath and SVNParentPath, but not both.
SVNParentPath /var/svn

  # Access control is done at 3 levels: (1) Apache authentication, via
  # any of several methods.  A "Basic Auth" section is commented out
  # below.  (2) Apache  and , also commented out
  # below.  (3) mod_authz_svn is a svn-specific authorization module
  # which offers fine-grained read/write access control for paths
  # within a repository.  (The first two layers are coarse-grained; you
  # can only enable/disable access to an entire repository.)  Note that
  # mod_authz_svn is noticeably slower than the other two layers, so if
  # you don't need the fine-grained control, don't configure it.

  # Basic Authentication is repository-wide.  It is not secure unless
  # you are using https.  See the 'htpasswd' command to create and
  # manage the password file - and the documentation for the
  # 'auth_basic' and 'authn_file' modules, which you will need for this
  # (enable them with 'a2enmod').
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /usr/local/svn-root/dav_svn.passwd
Require valid-user
  # To enable authorization via mod_authz_svn
  #AuthzSVNAccessFile /etc/apache2/dav_svn.authz

  # The following three lines allow anonymous read, but make
  # committers authenticate themselves.  It requires the 'authz_user'
  # module (enable it with 'a2enmod').
  #
    #Require valid-user
  # 



### End read-in of /etc/apache2/mods-available/dav_svn.conf




Small Addition

Thanks for the how-to. It was pretty quick and easy to use.

An interesting addition to the installation how-to can be found at:
http://blog.andrewbeacock.com/2005/08/configuring-subversion-svn-on-linux.html

It's a small addition to the /etc/apache2/sites-[available|enabled] folders. The addition seemed to allow the mapping of the "/svn" virtual directory pop up for web-browsing.

If anyone is interested a

If anyone is interested a howto explaining how to install apache 2.2.4, svn 1.4.2 and serf 0.1.0 is available here wiki.talk360.com