Installing Trac on a Ubuntu server

Despite I’ve worked before with Trac (a well-known bug tracking system), this is the first time I’ve been in the need for installing it. This post covers in a few steps what I’ve done. Maybe in your particular case it would be helpful, maybe not. So, these are the steps…

1. Install Trac

To install trac, all the detailed information is available here:

http://trac.edgewall.org/wiki/TracInstall

First of all, I needed to install the ‘easy_install tool’. I had already Python installed, because it runs over this language (http://python.org/).

To get ‘easy_install’, ‘setuptools’ package for Python must be installed. Can be downloaded from here http://pypi.python.org/pypi/setuptools#downloads and is auto-executable. Just run

1
sudo sh setuptools-0.6c9-py2.4.egg

To install then Trac:

1
sudo easy_install Trac

Note that you would need root permissions. And it was easy!

2. Create a Project

Trac runs with several database engines. In my case I’ve chosen SQLite for simplicity. This engine must be installed before configuring Trac. To install SQLite:

1
sudo apt-get install sqlite

And we’ll need also SQLite packages for Python. Well, perhaps this is the only mandatory step about SQLite, but I’m writing down what I did and I had no chance to check again without the main SQLite engine.

1
sudo apt-get install python-sqlite

Now we are ready to create a project, let’s create the folder first:

1
2
sudo mkdir /var/lib/trac
sudo chown www-data:www-data /var/lib/trac

And now the project can be initialized

1
sudo trac-admin /var/lib/trac/myproject initenv

We need to provide the project name, and as the default database engine is SQLite and we are not going to use a svn repository right now, the other questions at the installation time can be avoided.

Don’t forget to assign the project to user www-data recursively with

1
sudo chown www-data:www-data -R /var/lib/trac/myproject

At this point we can start testing the server with the standalone daemon:

1
sudo tracd --port 8000 /var/lib/trac/myproject

More info: http://trac.edgewall.org/wiki/TracInstall

3. Configuring Apache

We need to embed Python in Apache by installing mod_python.

1
sudo apt-get install libapache2-mod-python

And now we are about to configure Apache to use this module. We can use Publisher Handler to run .py scripts, or Python Server Pages to run .psp html files with python embedded code.

In our case I’m installing the Publisher Handler.

Let’s edit the Apache configuration for this virtual host, on file /etc/apache2/sites-available/default

And in the directory definition, add the bold lines.

?View Code APACHE
1
2
3
4
5
6
7
8
9
<Directory /var/www/>;
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
    AddHandler mod_python .py
    PythonHandler mod_python.publisher
    PythonDebug On
</Directory>

Then, restart Apache

1
sudo /etc/init.d/apache2 restart

More info:

http://www.howtoforge.com/embedding-python-in-apache2-with-mod_python-debian-etch

With the virtual host configured to run Python scripts, we need to add a location (virtual path) in our Apache server. To do so, edit apache configuration file, in my case on:

/etc/apache2/apache2.conf

And add the following location definition:

?View Code APACHE
1
2
3
4
5
6
7
<Location /projects/myproject>
   SetHandler mod_python
   PythonInterpreter main_interpreter
   PythonHandler trac.web.modpython_frontend
   PythonOption TracEnv /var/lib/trac/myproject
   PythonOption TracUriRoot /projects/myproject
</Location>

Where /projects/myproject will become your virtual url on the http server for trac system. This configuration sets up a unique project but other options can be chosen:

?View Code APACHE
1
2
3
4
5
6
# For a single project
PythonOption TracEnv /var/lib/trac/myproject
# For multiple projects
PythonOption TracEnvParentDir /var/lib/trac
# For the index of multiple projects
PythonOption TracEnvIndexTemplate /srv/www/htdocs/trac/project_list_template.html

More info: http://trac.edgewall.org/wiki/TracModPython

4. Adding permissions

Is preferable to have server authentication to avoid not allowed visitors. For this purpose, we should update Apache configuration file to stablish that Trac virtual location will require an authenticated user. To do so, we add these lines:

?View Code APACHE
1
2
3
4
AuthType Basic
AuthName "My Project"
AuthUserFile /var/lib/trac/.htpasswd
Require valid-user

We only need else to create the user and password definition:

1
htpasswd -nb user password

And add the resulting line to the passwords file mentioned above.We also need to set users in trac and assign them permissions. At least one of them should be administrator, and having different logins they are allowed to manage their own content.First of all, we need to create a new group which will have administrator permissions. In my case, I’ll call it ‘admin’

1
2
3
4
5
6
sudo trac-admin /var/lib/trac/climaps/ permission add admin MILESTONE_ADMIN
sudo trac-admin /var/lib/trac/climaps/ permission add admin PERMISSION_ADMIN
sudo trac-admin /var/lib/trac/climaps/ permission add admin ROADMAP_ADMIN
sudo trac-admin /var/lib/trac/climaps/ permission add admin TRAC_ADMIN
sudo trac-admin /var/lib/trac/climaps/ permission add admin TICKET_ADMIN
sudo trac-admin /var/lib/trac/climaps/ permission add admin REPORT_ADMIN

As I’ve activated server authentication, user name is caught from Apache, so that all I only need to do is to add the already created users in .htpasswd file to the trac group admin.

1
sudo trac-admin /var/lib/trac/climaps/ permission add jorge admin

After that, other users and permissions can be managed from the web interface.

More info: http://trac.edgewall.org/wiki/TracPermissions

Leave a Reply

Your email address will not be published. Required fields are marked *