Installing Trac and Git on Debian lenny
Posted on : 23-11-2009 | By : Arash Hemmat | In : Tutorials for myself
Tags: debian, git, howto, lenny, linux, server, trac, tutorial
6
I couldn’t find a good article so I decided to write one, this is a very quick howto for installing Trac with Git on Debian Lenny for myself!
First things first
First we should decide where to put our Trac files and Git repository, this is my fashion to put everything in /home directory so when i need a backup of my system all i have to do is to copy my /home directory.
Git repository files for the project test go here:
/home/repositories/test/
Trac files for project test go here:
/home/tracs/test
Installing Trac and Git
Thanks to apt magic installing Trac and Git is superb easy:
apt-get install trac-git
Initialize Git repository
We need to initialize out git repository first:
cd /home/repositories/test
git init
git commit
and it would be a good idea to add some files and folders before going to next step because trac-git plugin is not handling empty repositories very well.
Initializing Trac enviroment
trac-admin /home/tracs/test initenv
When asked for “Database connection string” just press Enter to use the default sqlite and when asked for “Repository type” type git and when asked for “Path to repository” enter the path like this “/home/repositories/test/.git” (Don’t forget to put the .git after the path)
Now we need to set the permissions:
find /home/tracs/test -type f -exec chmod 660 {} \;
find /home/tracs/test -type d -exec chmod 2770 {} \;
chown -R root.www-data /home/repositories
chown -R root.www-data /home/tracs
Adding Users to Trac
Let’s add an admin user to the Trac enviroment:
htpasswd -c /home/tracs/test/.htpasswd admin
You can add as many user as you want using this method.
Setting the Virtual Host
Now we will setup a virtual host like to be able to access trac from a sub domain like http://trac.example.com :
You’ll probably need to install and activate the apache python module if you don’t have it already:
apt-get install libapache2-mod-python
a2enmod python
Then we need to add the virtual host:
vim /etc/apache2/sites-available/trac.example.com
Now replace the example.com with your own domain name and paste the below lines into the newly created file:
<VirtualHost *:80>
ServerName trac.example.com
ServerAdmin webmaster@example.com# Note: This folder should exist, but will generally be empty
DocumentRoot /home/tracs/test/htdocs
<Directory /home/tracs/test/htdocs>
Order allow,deny
Allow from all
</Directory># Host the main Trac instance at /
<Location />
SetHandler mod_python
PythonHandler trac.web.modpython_frontend
PythonInterpreter main
PythonOption TracEnv /home/tracs/test
PythonOption TracUriRoot /
SetEnv PYTHON_EGG_CACHE /tmp
</Location># Host all others at /projects/$PROJECT
<Location /projects>
PythonOption TracEnv “”
PythonOption TracEnvParentDir /home/tracs/
</Location><Location /login>
AuthType Basic
AuthName “Test”
AuthUserFile /home/tracs/test/.htpasswd
Require valid-user
</Location></VirtualHost>
It is time to restart the apache:
/etc/init.d/apache2 restart
That’s it! Point your browser to http://trac.example.com and you’ll see Trac and Git running painless.
Troubleshooting
If you get an error message like below or something like that you will need to make some changes to the trac.ini file.
Warning: Can’t synchronize with the repository (GIT backend not available)
Let’s open trac.ini and take a look:
vim /home/tracs/example/conf/trac.ini
First find these lines:
[git]
cached_repository = false
git_bin = /usr/bin/git
persistent_cache = false
shortrev_len = 7
Now replace “git_bin = git” with “git_bin = /usr/bin/git”
This should solve the problem, if it is not then continue reading!
Ok, if you are still getting error about git these are the posibilities:
- Make sure you did put the “/.git” after your repository path while initializing the trac enviroment, if not find “repository_dir” in trac.ini and fix it.
- You may not set the permissions for your repository as described above, make sure www-data has permission to the repository
- You may be working with an empty repository, if so add some files and commit.
UPDATE 10-02-2010: If you still have problems you may read the comments you may find the solution there!

