It has been way too long since the last post, so here is something you might find useful.
A couple of months back we noticed that our commercially hosted svn and trac repositories were becoming quite unresponsive and slow, which held up development albeit only slightly. Time is money as they say, so we decided to cancel our commercial hosting and go for a local svn set up on our development server (just an old networked dell laptop, not very high specs at all). Our dev server is just a freebsd 7.1 install on an old dell laptop, which already had Apache, MySQL and PHP installed (FAMP server). For this guide you will need to have at least Apache installed (plus a few other port installs which I will detail below), but if you’re going to install Apache you might as well go all the way and have MySQL and PHP, see here and here posts on this. This guide is mainly for FreeBSD, although steps should be similar for Ubuntu, although your installs are very different, where appropriate I’ll put the ubuntu alternative installation steps.
Assuming you have already set up your FAMP server, next steps are as follows:
Use the make options as defined below. At the time of writing I am installing subversion 1.6.6
cd /usr/ports/devel/subversion make install clean
This might take a while depending on how many dependencies need to be installed.
Leave the options as they are or copy from below. At time of writing I am installing trac 0.11.5
cd /usr/ports/www/trac make install clean
Install mod_python for apache
From /usr/ports/www/mod_python3. Trac runs on python, the trac website neds to be handled by python so we need to install this apache module for the trac website(s) to work
cd /usr/ports/www/mod_python3 make install clean
Apache needs to be set up to enable the new mod_python module, so edit the httpd.conf file located in /usr/local/etc/apache22/httpd.conf add the following to the end of the LoadModule section if it is not there already.
LoadModule python_module libexec/apache22/mod_python.so
Install Git (optional)
There is a trac plugin to work with git repositiories if you prefer that to svn. I will not go into git now, see my next post for integrating trac with a git repository.
cd /usr/ports/devel/git make install clean
You do not need perforce or cvs support unless you want it. I have never used either, only subversion. You will not be able to install the GUI Tools without install the X11 windowing system. If you have already got X11 installed, then I would recommend installing the GUI tools as they can help with visualising the current branch on the development tree, but if not then do not bother as X11 takes AGES to install and will bloat your system with hundreds of dependencies.
Install the trac git plugin (optional)
You can install the trac git plugin if you want to work with git repositories rather than svn.
cd /usr/ports/www/trac-gitplugin make install clean
Ubuntu install steps for the all of the above are below(they are a lot simpler and quicker! Ubuntu uses pre-compiled files binary files and automatically sets up apache with the relevant modules loaded):
sudo apt-get install subversion sudo apt-get install libapache2-mod-python sudo apt-get install libapache2-svn sudo apt-get install trac sudo apt-get install git-core sudo apt-get install trac-git
Now that we have all the programs we need lets go on to set up an svn repository.
Create an SVN repository
First we need to decide where we are going to have our svn repository, where ever you decide to keep it, you will need to make sure it is readable (and writable if you want to make checkins) by the apache user. For this example I am storing all my svn repositories under one location, /usr/local/svn. Make sure you are root and run the following:
cd /usr/local mkdir svn cd svn mkdir repositories cd respositories mkdir Test svnadmin create Test cd /usr/local/svn htpasswd -c .passwd [Username] [Enter password, and again] chown -R www /usr/local/svn
Ok, the steps above we created a location where we are going to store our svn repositories, we created one respository called Test, then we created an apache basic authentication access file which the svn server will use to authenticate the users. Finally we changed the owner of the entire svn directory over to the apache web user. Ubuntu users can perform the same steps, feel free to choose a different location than /usr/local, this is common practice in a freebsd system.
Setup Apache to serve our SVN repository
Now we need to tell apache which directory contains our svn repository. As root create the following file by running:
Then edit that file and save the following in it:
AuthName "Subversion access"
Now if you restart your apache webserver (apachectl restart) and navigate to http://[server address]/svn/Test you should be asked for your username and password. Once you have logged in you should see your empty repository!
Create a trac repository
Now we will create a trac repository, I will follow the same logic as for the svn repositories and keep all the trac repositories under /usr/local/trac. As root again run:
cd /usr/local mkdir trac cd trac mkdir Test trac-admin Test initenv
trac-admin is an interactive program and you will be asked a series of questions to set up the trac repository. You will have to enter or accept the default value (by pressing return) at the following prompts:
Project Name [My Project]> Test Database connection string [sqlite:db/trac.db]> Repository type [svn]> Path to repository [/path/to/repos]> /usr/local/svn/repositories/Test
When you have finished change the owner of the trac folder to the apache web user:
chown -R www /usr/local/trac
The steps are again the same for Ubuntu users.
Setup apache to serve our trac repository
Apache needs to serve the trac repository using the mod_python module we installed earlier. To set this up, create the configuration file by running the following as root:
Save the following text in the new file:
<Location /trac/MyRepoName> SetHandler mod_python PythonHandler trac.web.modpython_frontend PythonOption TracEnv /usr/local/trac/Test PythonOption TracUriRoot /trac/Test AuthType Basic AuthName "trac access" AuthUserFile /usr/local/svn/.passwd Require valid-user </Location>
Now if you restart apache again by running apachectl restart and navigate to http://[server address]/trac/Test you should be asked to authenticate and see your trac site!
Testing the SVN repository
To test the repository we will checkout a working copy, in your users home directory, try the following:
mkdir svnworkingcopy cd svnworkingcopy svn checkout http://[server address]/svn/Test . --username [username] [Enter password] svn mkdir trunk branches tags svn commit -m "Checking in svn directory structure"
Now if you go back to the trac site and click the Timeline button you should see the first commit with the message. Click on Browse source to see the directory structure we just created. You now have everything you need to work with your trac and svn repository and to start adding and committing your project code.
Look out for the next post which will detail a few more steps to get more out of your trac server setup including:
- Using a git repository instead by using the trac git plugin
- A few extras steps that will help integrating your trac repository with the Eclipse Mylyn trac connector
- A svn post-commit hook to automatically add comments or close your trac tickets, simply by referring to a ticket number in your svn commit messages