How To Install And Use SVN With Apache dav_svn On Ubuntu 14.04

Want to support HowtoForge? Become a subscriber!
 
Submitted by howtoforge (Contact Author) (Forums) on Sat, 2014-07-19 10:12. :: Linux | Ubuntu | Apache

How to Install and Use SVN with apache dav_svn on Ubuntu 14.04

1.1 SVN-An Overview

Subversion is a popular open source version control system that enables users to record the history of source files and documents, and manage files and directories over a period of time. It is akin to a tree of files being placed into a central repository on the lines of a regular file server, barring that each modification made to these files and directories is always remembered.

 

1.2 Step-by-Step Guide on the Installation and Use of SVN on Ubuntu 14.04

This tutorial explains the process of installing and using SVN on Ubuntu 14.04 as per steps outlined below.

 

1.2.1 Step 1: Ensuring Up-to-Date Installed Packages

At the outset, you must ensure that all the packages installed on your system are updated. The following command shall help you do that:

sudo apt-get update

 

1.2.2 Step 2: Downloading the Subversion, Subversion Tools and Libapache2 packages

To run a Subversion (SVN) server, you need all the requisite packages, and you need to key in the following command for the same:

sudo apt-get install subversion subversion-tools libapache2-svn

You are now geared up to for the next step.

 

1.2.3 Step 3: Creating Subversion (SVN) Directory

Here, you are required to create a directory where all the repositories may be housed. It is advisable to choose a directory that is easily accessible to your the managed backup service for obvious reasons. Please key in the following command to do the same:

sudo mkdir /home/svn

This brings you to the end of this step, and you may move on to the next one, as explained below.

 

1.2.4 Step 4: Creating a Test Repository

As part of this step, users need to first create a new folder to create the test project, and subsequently create a repository for the same. The following command shall help you do that:

sudo mkdir ~/test
sudo svnadmin create /home/svn/test -m 'initial project structure'

The aforementioned command shall create a new repository for you that would comprise the base file structure. You may now graduate to the next step.

 

1.2.5 Step 5: Adding Files into the Test Project

Once you have created the repository, please use the following command to add files into the test project:

cd ~/test
mkdir trunk tags branches

You are now ready to import these new directories into the test repository, using the following command:

sudo svn import ~/test file:///home/svn/test -m 'Initial project directories'

The above command lets you add and also commit the new directories into the repository, all in one go. Further, for Apache to access the SVN repositories, the directory thus created (/home/svn directory) must necessarily be owned by the same user and also group that Apache runs as. More often than not, in Ubuntu, it happens to be www-data. In order to change the directory owner, please use the following command:

sudo chown -R www-data:www-data /home/svn

The above command shall enable you to change the owner of the directory, and you may subsequently move on to the next step.

 

1.2.6 Step 6: Configuration of Apache

Using the following command, you would be able to enable the dav_svn Apache module:

sudo a2enmod dav_svn

After having enabled this, you would be required to modify the Apache configuration file (as follows):

sudo nano /etc/apache2/apache2.conf

Right at the bottom of the file, please add the following lines, before saving the file by hitting Ctrl+X.

  DAV svn
  SVNParentPath /home/svn
After having saved this, you must restart the Apache service so as to implement the changes, by using the following command:

sudo service apache2 restart

Moving on, you would now be in a position to browse through the test repository you created by opening the web browser in Firefox, and visiting the following link:

http://127.0.0.1/svn/test.

Here, you would be able to view all the three directories, though they would all be empty. You may now proceed to the next step.

 

1.2.7 Step 7: Securing the SVN Repositories

Before the users start committing the files to the test repository, they must ensure that only authorized users are able to view it. The current settings, however, would allow unauthorized viewing, and checking out of the repository and its contents, in addition to checkout and committing of files by just about anyone. To secure the repositories, you must supply a username and a password before you begin to view the repository/ perform any action on the same. To execute this, you must reopen apache2.conf, and replace the SVN Location information with the following:

  DAV svn
  SVNParentPath /home/svn
  AuthType Basic
  AuthName "My SVN Repositories"
  AuthUserFile /etc/svn-auth
  Require valid-user
Further, you must create a password file by using the following command:

htpasswd -cm /etc/svn-auth disney

Upon keying in the above command, you would be prompted to enter and confirm your password, and subsequently your details would be saved. Next, the Apache service must be restarted, and subsequently, the user would need to authenticate themselves before going about viewing the repositories.

 

1.2.8 Step 8: Checking Out the Repository and Committing Files

For checking out the files contained within the repository into a new directory (let us call it Test2) within the home directory, you first need to create the new directory before you may issue the checkout command (as explained below):

cd ~
mkdir test2
svn checkout http://127.0.0.1/svn/test/trunk test2

You may now start adding files into the directory. Once the files have been created, you must perform the SVN add command, and pass in individual filenames as further arguments (as given below):

svn add index.php
svn add *

Once all the required files have been added, these may be committed using svn commit -m 'commit message' , and further, the server may be updated using the SVN up command. This brings you to the end of the process!
Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.