Wednesday, February 17, 2010

Install Subversion on CentOS 5 with Apache

SkyHi @ Wednesday, February 17, 2010

Setup Subversion and Trac on CentOS 5

Recently I set up a virtual server to use as a development machine. It runs on CentOS 5 and hosts several Subversion repositories with associated Trac projects.
There are many guides and plenty of help on the net to help you setup such a system. However, when I tried to do it I came across a few problems and I hope this post may help at least a few people trying to do the same as me. I am not going to rewrite the great tutorials out there, I will just point you to them and note what things I did differently.
This ‘guide’ should get you from a fresh install of CentOS 5 linux to one or more working Subversion (SVN) repositories and associated Trac wiki’s. Apache/WebDAV is used as the network layer. I have only tested this on a fresh install of CentOS 5.

The Environment

I am aiming for the following:
  • CentOS 5, SVN installed. Apache2 as the network layer using mod_dav_svn.
  • Trac running on Apache with mod_python
  • SVN repositories located at: /srv/svn (e.g. /srv/svn/my-project), accessible via http://server/svn/my-project
  • Trac projects located at: /srv/trac (e.g /srv/trac/my-project) accessible via http://server/trac/my-project

How I did it

Not all the steps are vital (probably) but this is how I got it working. Feel free to skip any non-relevant steps (i.e. there is probably no need for a fresh install). Replace any occurence of with the name of your first project.
1. Fresh install of CentOS. I followed most of the Perfect Setup Guide, except the mail and ISPConfig stuff. The important part is setting up the Apache2 web server.
2. Make sure SVN and mod_dav_svn are installed. As root:
yum install subversion mod_dav_svn
vim /etc/httpd/conf/httpd.conf
If the following two lines are not present, add them:
LoadModule dav_svn_module modules/
LoadModule authz_svn_module modules/
3. Install Trac: Follow Nick’s guide with the alternative Clearsilver installation below. Skip the Apache Configuration part.
Follow all of parts 1 and 2. Instead of part 3 do:
rpm -i clearsilver-0.10.4-1.el5.rf.i386.rpm
rpm -i python-clearsilver-0.10.4-1.el5.rf.i386.rpm
Continue with parts 4.1 and 4.2 of Nick’s guide. Remember, leave out Apache configuration section.
4. Create your first SVN Repository:
svnadmin create --fs-type fsfs /srv/svn/
5. Initialise a Trac project for your new repository:
trac-admin /srv/trac/ initenv
For the trac-admin command use the defaults if not sure, giving a descriptive name for the project. The `Path to repository` is: /srv/svn/.
6. Set the correct file permissions for apache
chown -R apache.apache /srv/svn/
chown -R apache.apache /srv/trac/
7. Tell apache where to find the new repository. Here we create an additional Apache configuration file specifically for the SVN repositories.
vim /etc/httpd/conf.d/subversion.conf
Add the following directive:
 DAV svn
 SVNPath /srv/svn/
 AuthType Basic
 AuthName " Repository"
 AuthzSVNAccessFile /srv/svn/svn-acl-conf
 AuthUserFile /srv/svn/.htpasswd
 Require valid-user
8. Add a repository user:
touch /srv/svn/.htpasswd
htpasswd -m /srv/svn/.htpasswd 
9. Create the Access Control List for the SVN Repository
vim /srv/svn/svn-acl-conf
Add the following directives:
 =  rw
Where represents the username of the repository user you created earlier.
10. Tell apache where to find the new Trac project. Here we create an additional Apache configuration file specifically for the Trac projects.
vim /etc/httpd/conf.d/trac.conf
Add the following directives:
 SetHandler mod_python
 PythonHandler trac.web.modpython_frontend
 PythonOption TracEnv /srv/trac/
 PythonOption TracUriRoot /trac/

 AuthType Basic
 AuthName "trac"
 AuthUserFile /srv/trac/.htpasswd
 Require valid-user
11. Add a Trac user:
touch /srv/trac/.htpasswd
htpasswd -m /srv/trac/.htpasswd 
12. Give admin permissions to the Trac user you just created:
trac-admin /srv/trac/ permission add  TRAC_ADMIN
Where represents the username of the Trac user you just created.
13. Restart Apache:
service httpd restart
You should now have SVN and Trac installed. You will have an SVN repository setup (http://server/svn/) and the Trac wiki (http://server/trac/) associated with the repository.
Please let me know if this helped you. If you come across any problems I will be happy to try and help.

Official guide:
Here is a good place to start: