Categories
Apps & OS's Coding Technology

How to setup an SVN server on Ubuntu 10.04 Server

Hi all,

Another feature that I needed for my project over at zpanel.co.uk was an SVN server so that other members of my team can download the source code, make changes and upload it back to the master server.

So this quick tutorial will show you the basics of how to setup an SVN server with public read access but authenticated write access.

Ok so first of all you’ll need Ubuntu Server 10.04 installed on your server…

Now we’ll install SVN, Apache and the SVN library for Apache…

apt-get install apache2 subversion libapache2-svn

and now we’ll create our repository like so..

svnadmin create /svn

In the above example I have called the repository ‘svn’ but obviously you can substitute ‘/svn’ for ‘/{yourprojectname}’ if you’d like.

Now what we’ll do is edit the configuration file for subversion…

nano /etc/apache2/mods-enabled/dav_svn.conf

The Location element in the configuration file dictates the root directory where subversion will be acessible from, for instance: http://www.server.com/svn

<Location /svn>

The DAV line needs to be uncommented to enable the dav module

# Uncomment this to enable the repository,
DAV svn

The SVNPath line should be set to the same place your created the repository with the svnadmin command.

# Set this to the path to your repository
SVNPath /svn

The next section will let you turn on authentication. This is just basic authentication, so don’t consider it extremely secure. The password file will be located where the AuthUserFile setting sets it to…  probably best to leave it at the default.

# Uncomment the following 3 lines to enable Basic Authentication
AuthType Basic
AuthName “Subversion Repository”
AuthUserFile /etc/apache2/dav_svn.passwd

To create a user on the repository use, the following command:

sudo htpasswd -cm /etc/apache2/dav_svn.passwd <username>

Note that you should only use the -c option the FIRST time that you create a user. After that you will only want to use the -m option, which specifies MD5 encryption of the password, but doesn’t recreate the file.

Example:

sudo htpasswd -cm /etc/apache2/dav_svn.passwd ballen
New password:
Re-type new password:
Adding password for user ballen

Restart apache by running the following command:

/etc/init.d/apache2 restart

Now if you go in your browser to http://www.server.com/svn, you should see that the repository is enabled for anonymous read access, but commit access will require a username.

If you want to force all users to authenticate even for read access, add the following line right below the AuthUserFile line from above. Restart apache after changing this line.

Require valid-user

Now if you refresh your browser, you’ll be prompted for your credentials:

So that is now it, you now have a working Linux Subversion server!

You can also create additonal respositories with different access rights by simply duplicating and renaming this file /etc/apache2/mods-enabled/dav_svn.conf. – Just use your head, you’ll figure it out!

Remember if you make changes to SVN you MUST restart apache for the changes to become active!

Happy coding!