Ubuntu SVN Setup
- May 14th,
If you’re looking over the perfect subversion setup in ubuntu you’re at the right place. I’m a long time subversion and ubuntu user and I’ll try to share some info on how I keep my source code safe. This article will cover how you can setup your own webdav enabled, multi repository subversion server.
Setting up Subversion with WebDav Access
Starting with the easy part, installing all the needed packages.
apt-get install apache2 libapache2-svn subversion
We’re also going to need a directory structure where to store our repositories and config files:
mkdir -p /var/lib/svn/conf/policies mkdir -p /var/lib/svn/repository
Let’s create our first config file /var/lib/svn/conf/default_policy.conf. We’re going to use this file to act as a default webdav config for every repository.
<Location /> Dav svn SVNParentPath /var/lib/svn/repository AuthType Basic AuthName "Razvan's Subversion Repository" AuthUserFile /var/lib/svn/conf/passwords Require user rgavril </Location>
Of course you should set the Require user and AuthName to match your needs.
Create a default svn user. Since I used rgavril in the above config file, I’ll continue my example with that username but you can use whatever you want.
htpasswd -c /var/lib/svn/conf/passwords rgavril
Now we need to deceide on how to access the subversion repositories. I’m into using the http://svn.domain.com/project naming scheme so I’ll show you how to do that. Create a file named svn.domain.com in /etc/apache2/sites-available with the fallowing content:
<VirtualHost *:80> ServerName svn.domain.com UseCanonicalName Off ServerAdmin "firstname.lastname@example.org" CustomLog /var/log/apache2/svn.domain.com_access_log combined ErrorLog /var/log/apache2/svn.domain.com_error_log Include /var/lib/svn/conf/default_policy.conf Include /var/lib/svn/conf/policies/* </VirtualHost>
Let’s enable enable the svn_dav module and the newly created virtual host in apache and restart it:
a2ensite svn.domain.com a2enmod dav_svn invoke-rc.d apache2 restart
Creating and Managing Repositories
Ok so let’s start creating our first repository in svn, it’s actually very simple:
mkdir /var/lib/svn/repository/project001 svnadmin create /var/lib/svn/repository/project001 chown -R www-data.www-data /var/lib/svn/repository/project001
After running the above commands you should be able to use access your newly created repository using this url: http://svn.domain.com/project001
Let’s assume you’re working with bob on this project and you want to give him access to the repository don’t allow him to access the other projects. What you want to do is to create a password for bob:
htpasswd /var/lib/svn/conf/passwords bob
And now create a special policy for this project by creating a file named /var/lib/svn/conf/policy/project001.conf :
<Location /> AuthName "Razvan and Bob's Repository" Require user rgavril bob </Location>
For setting more complex user rights I recommend using the AuthzSVNAccessFile directive, but this should get you going for now.