Recently, I needed to set up a Subversion (SVN) server on a Ubuntu Linux server. This post is going to outline the steps taken, and the commands used, to install and configure the service.
Note: As I was using Ubuntu, I was using the 'apt-get' command to download and install the software packages. If you're using a different distribution of Linux, then this command may be different. I'm also assuming that Apache is already installed.
These are all of the packages that are needed to run a Subversion server.
## Create subversion directory
Now, I need to create the directory where my repositories are going to sit. I've chosen this directory as I know that it's one that is accessible to my managed backup service.
This both adds and commits these new directories into the repository.
In order for Apache to access the SVN repositories, the `/home/svn` directory needs to be owned by the same user and group that Apache runs as. In Ubuntu, this is usually www-data. To change the owner of a directory, use the chown command.
I can now browse through my test repository by opening Firefox, and navigating to `http://127.0.0.1/svn/test`. Here, I can now see my three directories, although they are currently all empty.
<imgclass="imagecache-blog imagecache image-caption caption"title="Viewing the test repository in Firefox"src="http://oliverdavies.co.uk/sites/default/files/imagecache/blog/images/blog/how-install-and-configure-subversion-svn-server-ubuntu/viewing-test-repository-firefox.png"alt="Image: Screenshot of the test SVN repository in Firefox">
## Securing my SVN repositories
Before I start committing any files to the test repository, I want to ensure that only authorised users can view it - currently anyone can view the repository and it's contents, as well as being able to checkout and commit files. To do this, I'm going to require the user to enter a username and a password before viewing or performing any actions with the repository.
Re-open apache2.conf, and replace the SVN Location information with this:
I'm prompted to enter and confirm my password, and then my details are saved. The Apache service will need to be restarted again, and then the user will need to authenticate themselves before viewing the repositories.
<imgclass="imagecache-blog imagecache image-caption caption"title="Being prompted for authorisation"src="http://oliverdavies.co.uk/sites/default/files/imagecache/blog/images/blog/how-install-and-configure-subversion-svn-server-ubuntu/being-prompted-authorisation_0.png"alt="Image: Screenshot of the authorisation prompt when opening the repository">
## Checking out the repository and commiting files
For example, now want to checkout the files within my repository into a new directory called 'test2' within my home directory. Firstly, I need to create the new directory, and then I can issue the checkout command.
I'm passing the command two arguments - the first is the URL of the repository's trunk directory, and the second is the directory where the files are to be placed. As no files have been commited yet into the trunk, it appears to be empty - but if you perform an ls -la command, you'll see that there is a hidden .svn directory.
Now you can start adding files into the directory. Once you've created your files, perform a svn add command, passing in individual filenames as further arguments.
With all the required files added, they can be committed using `svn commit -m 'commit message'` command, and the server can be updated using the svn up command.