Installing and Configuring Trac on FreeBSD
Trac is a project management and software bug tracking tool. It uses a minimalist web interface based on wiki technology and lets you create cross-links between the database of reported bugs, the version control system, and wiki pages.
This also makes it possible to use Trac as a web interface for accessing the subversion version control system, as well as Mercurial, git, Bazaar, and others through plugins. Trac is written in the python programming language and is currently distributed under a modified BSD license.
http://ru.wikipedia.org/wiki/Trac
Features
- View all changes in svn and the trac project.
- Create subprojects; for a portal, for example, these might be “Develop a photo service,” “Forum development,” or “Rebuild the search module.” Each will have its own groups of tickets.
- View and compare project source code changes across svn revisions.
- Create, view, and close tickets.
- Manage users involved in development.
- A wiki engine that lets you create both reference material and documentation for the project as a whole.
There are also loads of plugins for Trac that make it easy to extend its functionality!
Installation
To deploy Trac, we will need:
- Apache 2.2 - though you can also deploy it on Apache 1.3 or Nginx, for example
- mod_python3 - this is for Apache 2; for 1.3, you just need “mod_python”
- Subversion - or another version control system, such as Mercurial, git, or Bazaar
- py-subversion - for working with Subversion from Python
- MySQL - you can also use SQLite or PgSQL. More details: http://trac.edgewall.org/wiki/DatabaseBackend
- And Trac itself, of course :)
Installing mod_python3 on Apache 2.2
# cd /usr/ports/www/mod_python3/
# make install clean
Go and check whether the mod_python.so module has been installed:
# cd /usr/local/libexec/apache22/
# ll | grep mod_python
If it is there, add the following to httpd.conf:
LoadModule python_module libexec/apache22/mod_python.so
More about mod_python: http://trac.edgewall.org/wiki/TracModPython
Installing Trac
Installing Trac is very simple:
# cd /usr/ports/www/trac
# make install clean
If you want to manage trac project settings and user permissions from the web panel, install the ”trac-webadmin” plugin.
# cd /usr/ports/www/trac-webadmin/
# make install clean
More about WebAdmin: http://trac.edgewall.org/wiki/WebAdmin
Using MySQL
If you want to use MySQL to store Trac data, you need to install the MySQL-python driver. If you do not need this, you can use SQLite and skip the MySQL-python installation I describe below.
To do this, install the MySQL-python driver.
# cd /tmp
# fetch http://downloads.sourceforge.net/sourceforge/mysql-python/MySQL-python-1.2.2.tar.gz
# tar -xvf MySQL-python-1.2.2.tar.gz
# cd MySQL-python-1.2.2
# python setup.py build
# python setup.py install
If you are using Apache, restart it so that mod_python can access it.
Now let’s create a database and a user for Trac:
CREATE DATABASE trac DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;
CREATE USER tracuser IDENTIFIED BY 'password';
GRANT ALL ON trac.* TO tracuser;
FLUSH PRIVILEGES;
Do not forget to replace the password in the query with one of your own.
Installing Subversion with Python Support
# cd /usr/ports/devel/subversion
# make WITH_PYTHON=true WITH_BERKELEYDB=db42 WITH_MOD_DAV_SVN= install
More about the flags: http://trac.edgewall.org/wiki/TracFaq
Installing py-subversion
# cd /usr/ports/devel/py-subversion
# make FORCE_PKG_REGISTER= install clean
More about the flag: http://trac.edgewall.org/wiki/TracSubversion
Configuring Apache
Let’s edit the Apache configuration and add a new virtual host:
<VirtualHost *:80>
DocumentRoot "/home/trac"
ServerName trac.example.com
<Location />
SetHandler mod_python
PythonInterpreter main_interpreter
PythonHandler trac.web.modpython_frontend
PythonOption TracEnv /home/trac/example.com
PythonOption TracUriRoot /
AuthType Basic
AuthName "Trac Server"
AuthUserFile /home/trac/example.com/.htpasswd
Require valid-user
</Location>
</VirtualHost>
I require authentication for Trac to keep outside users from accessing it. If you want Trac to be publicly accessible, you can move this part:
AuthType Basic
AuthName "Trac Server"
AuthUserFile /home/trac/example.com/.htpasswd
Require valid-user
Into a separate ; for example, the result would look like this:
<VirtualHost *:80>
DocumentRoot "/home/trac"
ServerName trac.example.com
<Location />
SetHandler mod_python
PythonInterpreter main_interpreter
PythonHandler trac.web.modpython_frontend
PythonOption TracEnv /home/trac/example.com
PythonOption TracUriRoot /
</Location>
<Location /login>
AuthType Basic
AuthName "Trac Server"
AuthUserFile /home/trac/example.com/.htpasswd
Require valid-user
</Location>
</VirtualHost>
I also use Subversion passwords for authentication. If you look at the article FreeBSD. Installing and Configuring Subversion, we used the path “/home/svn/svn-auth-file”, so that is what we will use as AuthUserFile:
...
AuthUserFile /home/svn/svn-auth-file
...
Configuring Trac
First, we need to create a trac project and configure it.
Creating a trac Project
# trac-admin /home/trac/example.com initenv
initenv — creation and use of interactive mode
More about trac-admin commands: http://trac.edgewall.org/wiki/TracAdmin
Next, specify the project name and the address for connecting to MySQL:
mysql://tracuser:password@localhost:3306/trac
The version control server type, “svn”, and the path to your project’s svn repository:
/home/svn/repos/example.com
More details: http://trac.edgewall.org/wiki/TracEnvironment
Configuring a trac Project
Edit the file “/home/trac/example.com/conf/trac.ini” and change the following directives:
default_charset = utf-8
base_url = http://trac.example.com
At the end of the file, add the following to enable the “webadmin” plugin:
[components]
webadmin.* = enabled
More details on all the directives: http://trac.edgewall.org/wiki/TracIni
If you visit “trac.example.com” and see:
Permission denied: '/home/trac/example.com/.egg-cache'then set write permissions for the trac project directory.
Granting Administrator Permissions to One of the Users
# trac-admin /home/trac/example.com permission add имя_пользователя TRAC_ADMIN
Synchronizing the trac Project with the svn Project
# trac-admin /home/trac/example.com resync
Automatic Notifications of svn Changes for trac Tickets
And finally, if you use svn hooks, as I described in the article Subversion. Automatically Updating a Project Using Hooks, add these lines to post-commit to notify trac tickets:
TRAC_ENV="/home/trac/example.com"
/usr/bin/python /usr/local/bin/trac-post-commit-hook -p "$TRAC_ENV" -r "$REV"
Summary
That’s it: Trac is installed and configured for comfortable use. In future articles, I will explain how to configure Mylyn so you can work with Trac and manage all your subprojects and tickets directly from your IDE!
If you have any questions, feel free to ask in the comments!
Comments are closed. Read the original discussion in Russian →
