How To Create a Subversion Repository and Trac Project

Subversion is the shit!

It allows you to seemless cover your own ass… It is also very useful for transfering, and updating code. Trac is also very cool, it has one of the best bug tracking sytems, a cool wiki, and a subversion browser. Here is a tutorial about how to setup these up on a fedora/redhat server… It’s pretty easy…

Subversion…

first off you need to install subversion if you haven’t already…

yum install subversion

next you need to find a good spot to place your repos in… I usually use /var/svn or /srv/svn, and sometimes I use /var/www/svn, it really doesn’t matter too much, the man thing is that you keep them organized and in a place where permissions will allow users to access it.

mkdir -p /srv/svn

Then create the repo

svnadmin create /srv/svn/REPO_NAME

I like to then checkout the repo and add the base directory structure…

svn co file:///srv/svn/REPO_NAME ~/REPO_NAME

cd ~/REPO_NAME

mkdir trunk tags branches

svn add *

svn ci -m “Base Directory Structure”

Subversion With Apache…

There are a lot of ways to connect to subversion servers… The Web, SSH, NFS, SMB, and many more… But the most common way and usually the simplest is HTTP…

yum install mod_dav_svn

When you did yum install mod_dav_svn it should add a file(/etc/httpd/conf.d/subversion.conf) that looks like thisthis configuration, run as root:

LoadModule dav_svn_module     modules/mod_dav_svn.so
LoadModule authz_svn_module   modules/mod_authz_svn.so

#
# Example configuration to enable HTTP access for a directory
# containing Subversion repositories, "/var/www/svn".  Each repository
# must be readable and writable by the 'apache' user.  Note that if
# SELinux is enabled, the repositories must be labelled with a context
# which httpd can write to; this will happen by default for
# directories created in /var/www.  Use "restorecon -R /var/www/svn"
# to label the repositories if upgrading from a previous release.
#

#
# To create a new repository "http://localhost/repos/stuff" using
# this configuration, run as root:
#
#   # cd /var/www/svn
#   # svnadmin create stuff
#   # chown -R apache.apache stuff
#

#<Location /repos>
#   DAV svn
#   SVNParentPath /var/www/svn
#
#   # Limit write permission to list of valid users.
#   <LimitExcept GET PROPFIND OPTIONS REPORT>
#      # Require SSL connection for password protection.
#      # SSLRequireSSL
#
#      AuthType Basic
#      AuthName "Authorization Realm"
#      AuthUserFile /path/to/passwdfile
#      Require valid-user
#   </LimitExcept>
#</Location>

You need to uncomment the lower half and enter in the paths you chose before…

if you used the /srv/svn paths like I did then it should look something like this…

LoadModule dav_svn_module     modules/mod_dav_svn.so
LoadModule authz_svn_module   modules/mod_authz_svn.so

#
# To create a new repository "http://localhost/repos/stuff" using
# this configuration, run as root:
#
#   # cd /var/www/svn
#   # svnadmin create stuff
#   # chown -R apache.apache stuff
#

<Location /repos>
   DAV svn
   SVNParentPath /srv/svn
   AuthUserFile /srv/svn/htpassword
   AuthName "REPO NAME Subversion"
   AuthType Basic
   Require valid-user
</Location>

You may notice I have a AuthUserFile listed at /var/www/authUsers, you can take out the lines about security if you want to grant everyone access…

Otherwise you need to create a htpassword file…

htpasswd -cb /srv/svn/htpassword secretUsernameA secretPasswordA

htpasswd -b /srv/svn/htpassword secretUsernameB secretPasswordB

htpasswd -b /srv/svn/htpassword secretUsernameC secretPasswordC

After that you need to restart apache so that it can load your new subversion.conf file…

service httpd restart

If everything worked right you should be able to view your repo at http://hostname/repos/REPO_NAME

You can also have others checkout a copy of your repo by doing something like this

svn co http://secretUsernameA@hostname/repos/REPO_NAME ~/REPO_NAME

Most people will just want the trunk thou…

svn co http://secretUsernameA@hostname/repos/REPO_NAME/trunk ~/REPO_NAME

Trac…

Ok, so now your rolling with a svn repo, but you still need a cool interface to show it off… That’s where Trac comes in…

yum install trac

You need to create a directory to store your trac project… I like to keep trac and subversion close… Here is how you create a trac project…

mkdir -p /srv/trac/

trac-admin /srv/trac/REPO_NAME initenv

You then will be asked to answer some questions to create the trac project, the only one you really need to edit is the project name and the svn path… for mine I used /srv/svn/REPO_NAME

After your done with that, you need to add a piece of code to your /etc/httpd/conf.d/subversion.conf file…

LoadModule dav_svn_module     modules/mod_dav_svn.so
LoadModule authz_svn_module   modules/mod_authz_svn.so

#
# To create a new repository "http://localhost/repos/stuff" using
# this configuration, run as root:
#
#   # cd /var/www/svn
#   # svnadmin create stuff
#   # chown -R apache.apache stuff
#

<Location /repos>
   DAV svn
   SVNParentPath /srv/svn
   AuthUserFile /srv/svn/htpassword
   AuthName "REPO NAME Subversion"
   AuthType Basic
   Require valid-user
</Location>

<Location /trac/REPO_NAME>
   SetHandler mod_python
   PythonInterpreter main_interpreter
   PythonHandler trac.web.modpython_frontend
   PythonOption TracEnv /srv/trac/REPO_NAME
   PythonOption TracUriRoot /trac/REPO_NAME
</Location>

<Location /trac/REPO_NAME/login>
  AuthType Basic
  AuthName "REPO NAME TRActrac"
  AuthUserFile /srv/svn/htpassword
</Location>

That’s it, all you need to do now is restart apache one more time and you should be able to visit http://hostname/trac/REPO_NAME and see trac.

service httpd restart

You can find a config file for your trac project in /srv/trac/REPO_NAME

Troubleshooting…

The most common problem is permissions, so chmod it!

Advertisements

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s