SVN Environment Setup


SVN Installation

Subversion is popular open-source Version Control tool. As it’s open-source it is available for free over a internet. It comes by default with most of the GNU/Linux distributions, so it might be already installed on your system. To check whether it is installed or not use following command.

[jerry@CentOS ~]$ svn --version

If Subversion client is not installed, then command will report error, otherwise it will display version of the installed software.

[jerry@CentOS ~]$ svn --version
-bash: svn: command not found

If you are using RPM based GNU/Linux then use yum command for installation. After successful installation execute svn --version command.

[jerry@CentOS ~]$ su -
[root@CentOS ~]# yum install subversion

[jerry@CentOS ~]$ svn --version
svn, version 1.6.11 (r934486)
compiled Jun 23 2012, 00:44:03

And if you are using Debian based GNU/Linux then use apt command for installation.

[jerry@Ubuntu]$ sudo apt-get update
[sudo] password for jerry:

[jerry@Ubuntu]$ sudo apt-get install subversion

[jerry@Ubuntu]$ svn --version
svn, version 1.7.5 (r1336830)
compiled Jun 21 2013, 22:11:49

Apache Setup

We have seen how to install Subversion client on GNU/Linux. Let us see how to create new repository and allow access to users.

On server we have to install Apache httpd module and svnadmin tool.

[jerry@CentOS ~]$ su -
[root@CentOS ~]# yum install mod_dav_svn subversion

The mod_dav_svn package allows access to a repository using HTTP, via the Apache httpd server and subversion package installs svnadmin tool.

Subversion reads it's configuration from /etc/httpd/conf.d/subversion.conf file. After adding configuration subversion.conf file will look like this.

LoadModule dav_svn_module     modules/
LoadModule authz_svn_module   modules/

<Location /svn>
   DAV svn
   SVNParentPath /var/www/svn
   AuthType Basic
   AuthName "Authorization Realm"
   AuthUserFile /etc/svn-users
   Require valid-user

Let us create Subversion users and grant them access to the repository. htpasswd command is used to create and update the plain-text files which are used to store usernames and passwords for basic authentication of HTTP users. '-c' options creates password file, if password file already exists, it is overwritten. That is why use '-c' option only first time. '-m' option enables MD5 encryption for passwords.

User Setup

Let us create user tom.

[root@CentOS ~]# htpasswd -cm /etc/svn-users tom
New password: 
Re-type new password: 
Adding password for user tom

Let us create user jerry

[root@CentOS ~]# htpasswd -m /etc/svn-users jerry
New password: 
Re-type new password: 
Adding password for user jerry
[root@CentOS ~]# 

Create Subversion parent directory to store all work (see /etc/httpd/conf.d/subversion.conf).

[root@CentOS ~]# mkdir /var/www/svn
[root@CentOS ~]# cd /var/www/svn/

Repository Setup

Create project repository named project_repo. svnadmin command will create new repository and few other directories inside that to store metadata.

[root@CentOS svn]# svnadmin create project_repo

[root@CentOS svn]# ls -l project_repo
total 24
drwxr-xr-x. 2 root root 4096 Aug  4 22:30 conf
drwxr-sr-x. 6 root root 4096 Aug  4 22:30 db
-r--r--r--. 1 root root    2 Aug  4 22:30 format
drwxr-xr-x. 2 root root 4096 Aug  4 22:30 hooks
drwxr-xr-x. 2 root root 4096 Aug  4 22:30 locks
-rw-r--r--. 1 root root  229 Aug  4 22:30 README.txt

Let us change user and group ownership of the repository.

[root@CentOS svn]# chown -R apache.apache project_repo/

Check whether SELinux is enabled or not using SELinux status tool.

[root@CentOS svn]# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /selinux
Current mode:                   enforcing
Mode from config file:          enforcing
Policy version:                 24
Policy from config file:        targeted

For our server SELinux is enabled, so we have to change SELinux security context.

[root@CentOS svn]# chcon -R -t httpd_sys_content_t /var/www/svn/project_repo/

To allow commits over HTTP execute following command.

[root@CentOS svn]# chcon -R -t httpd_sys_rw_content_t /var/www/svn/project_repo/

Restart the Apache server and we are done with configuration of Apache server.

[root@CentOS svn]# service httpd restart
Stopping httpd:                                            [FAILED]
Starting httpd: httpd: apr_sockaddr_info_get() failed for CentOS
httpd: Could not reliably determine the server's fully qualified domain name, using for ServerName
                                                           [  OK  ]
[root@CentOS svn]# service httpd status
httpd (pid  1372) is running...
[root@CentOS svn]#

We have configured Apache server successfully, now configure repository. To provide repository access to only authenticated users and to use default authorization file; append following lines to project_repo/conf/svnserve.conf file.

anon-access = none
authz-db = authz

By conventionally every Subversion project have trunk, tags and branches directories directly under the project's root directory.

The trunk is a directory where all the main development happens and is usually checked out by developers to work on the project.

The tags directory is used to store named snapshots of the project. When creating a production release, the team will tag the code that goes into the release.

The branches directory is used when you want to pursue different lines of development.

Let us create trunk, tags and branches directory structure under project repository.

[root@CentOS svn]# mkdir /tmp/svn-template
[root@CentOS svn]# mkdir /tmp/svn-template/trunk
[root@CentOS svn]# mkdir /tmp/svn-template/branches
[root@CentOS svn]# mkdir /tmp/svn-template/tags

Now import directories from /tmp/svn-template to the repository.

[root@CentOS svn]# svn import -m 'Create trunk, branches, tags directory structure' /tmp/svn-template/ 
Adding         /tmp/svn-template/trunk
Adding         /tmp/svn-template/branches
Adding         /tmp/svn-template/tags
Committed revision 1.
[root@CentOS svn]#

Done!!! . We have created repository successfully and allowed access to Tom and Jerry. From now they can perform all supported operation to the repository.