Overview

Installing trac on a server with Apache and mod_python

Requirements

Tested with the below ,

Apache 2.2
Mysql 5.0

Objective

Installing trac and apache module mod_python for a project system on a domain subdirectory

Configuration

Step 1

Make sure that you have the required version of python , flew, setuptools and mysql-python installed.
This installation was done on a DirectAdmin server and it had python version as Python 2.4.3, so had to install a secondary python of version 2.5 on a different location

To install python 2.5

root@serv:~# cd /usr/local/src
root@serv:~# mkdir -p /usr/local/TRAC/PYTHON/
root@serv:~# wget http://www.python.org/ftp/python/2.5/Python-2.5.tgz
root@serv:~# tar -zxvf Python-2.5.tgz
root@serv:~# cd Python-2.5
root@serv:~# ./configure –enable-shared –prefix=/usr/local/TRAC/PYTHON/
root@serv:~# make
root@serv:~# make install

To install flex 2.5

root@serv:~# cd /usr/local/src
root@serv:~# wget http://sourceforge.net/projects/flex/files/flex/flex-2.5.35/flex-2.5.35.tar.gz/download?use_mirror=biznetnetworks
root@serv:~# tar -zxvf flex-2.5.35.tar.gz
root@serv:~# cd flex-2.5.35
root@serv:~# ./configure
root@serv:~# make
root@serv:~# make install

To install setup tools

root@serv:~# cd /usr/local/src
root@serv:~# wget http://peak.telecommunity.com/dist/ez_setup.py
root@serv:~# /usr/local/TRAC/PYTHON/bin/python ez_setup.py

To install mysql-python

root@serv:~# cd /usr/local/src
root@serv:~# wget http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz/download?use_mirror=biznetnetworks
root@serv:~# tar -zxvf MySQL-python-1.2.3.tar.gz
root@serv:~# cd MySQL-python-1.2.3
root@serv:~# /usr/local/TRAC/PYTHON/bin/python ./setup.py install

Step 2

Linking the libraries
As you have installed the python to a custom location you have to link the libraries so as properly compile the mod_python

root@serv:~# echo “/usr/local/TRAC/PYTHON/lib/” > /etc/ld.so.conf.d/python2.5.conf
root@serv:~# ldconfig -v

Step 3

Installing trac

root@serv:~# cd /usr/local/src
root@serv:~# wget http://ftp.edgewall.com/pub/trac/Trac-0.12.1.tar.gz
root@serv:~# tar -zxvf Trac-0.12.1.tar.gz
root@serv:~# cd Trac-0.12.1/
root@serv:~# /usr/local/TRAC/PYTHON/bin/python setup.py install

Step 4

Installing mod_python and loading the module
Please note to give the apxs and python binary path correctly according to the installed location.

root@serv:~# wget http://www.ecoficial.com/apachemirror//httpd/modpython/mod_python-3.3.1.tgz
root@serv:~# tar -zxvf mod_python-3.3.1.tgz
root@serv:~# cd mod_python-3.3.1/
root@serv:~# ./configure –with-apxs=/usr/sbin/apxs –with-python=/usr/local/TRAC/PYTHON/bin/python
root@serv:~# make
root@serv:~# make install

Please make sure that the module is loaded on the proper file which is included in apache conf or you can load the module directly in the main conf file ( httpd.conf )

root@serv:~# echo “LoadModule python_module /usr/lib/apache/mod_python.so” > /etc/httpd/conf/extra/httpd-python.conf

Step 5

Creating a project
Create a mysql db/db_user and grant all privileges to the database with a password

root@serv:~# /usr/local/TRAC/PYTHON/bin/trac-admin /var/project initenv desired_projectname mysql://db_user:db_pass@localhost:3306/db_name

Step 6

Setting up a Login
Limit the access with a login

root@serv:~# htpasswd -c /var/project/ .htpasswd admin

Step 7

Setup the VirtualHost
Open your Apache VirtualHost file and add the below lines into it

<Location /project>

RewriteEngine Off  ### to override any redirect rules on .htaccess of parent directory
SetHandler mod_python
PythonInterpreter main_interpreter
PythonHandler trac.web.modpython_frontend
PythonOption TracEnv /var/project
PythonOption TracUriRoot /project
AuthType Basic
AuthName “Trac”
AuthUserFile /var/project/.htpasswd
Require valid-user

</Location>

You will be able to access the project trac now using

http://your_domain.com/project