install trac 1.1.2-dev on ubuntu 12.04

I tried to make a good tutorial to figure out, how to install trac 1.1.2-dev on ubuntu 12.04. This was mainly done as a walkthrough for me, and I hope that you ‘ll find nice too.

I asume that you have a fresh install of ubuntu 12.04, so you firstly have to do:

sudo apt-get update
sudo apt-get upgrade.

Out of our scope I am just saying that, I allways want to take the role of root, even on an ubuntu linux system so the first thing I do is:

sudo passwd root

after setting a password for a root user, you are able to do:


and then you are logged in a root session.

One more thing that helps me a lot is to set bash_autocompletion for root user. This is tricky and easy in Ubuntu. You have to edit the the .bashrc file in your home directory. For the root user is:


so lets do it:

vi /root/.bashrc

and then just comment out the 3 last lines in this file and more accurately these 3 lines:

if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
 . /etc/bash_completion

now we are ready to proceed to the installation guide.

install trac 1.1.2-dev on ubuntu 12.04

lets apt-get install all packages needed:

apt-get -y install python-setuptools python-genshi python-genshi-doc mysql-client-5.5 mysql-server-5.5 python-mysqldb python-babel python-docutils enscript subversion git apache2 libapache2-mod-python mercurial python-dev python-pygments

I hope that I haven’t forget a package 😛

Database preparation

At the time of installing mysql-server-5.5 you will be asked to set a root password for the database server. Choose one to enter. After the successful installation of mysql server and all the other package, lets prepare our database server for the trac installation.

use the mysql client you just installed:

mysql -u root -p

enter the root password you have chosen

In this section I have to say that for each trac project you will need a database, so lets the database a relative name. I named mine trac_myproject. So enter on mysql console the following commands:

CREATE DATABASE trac_myproject DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
GRANT ALL ON trac_myproject.* TO tracuser@localhost IDENTIFIED BY 'tracpass';
flush privileges;

tracuser and tracpass in the above example are just example names.

Now write down the db connection string, that you will need when you will create your first trac project.


As an advice I ‘ll say that you shouldn’t use the char @ as member of the password beacuse trac will fail to make the connection to the database.

Once we are ready with the database lets get our hands dirty with trac!

Trac latest dev and TracMercurial plugin installation

we have to get the sources for the trac and TracMercurial:

I got the clones of these repositories to my root directory:

cd /root

clone repositories

svn co
hg clone

install trac

get into the directory trunk

cd trunk
python install

install TracMercurial

get into mercurial-plugin directory

cd ../mercurial-plugin
python bdist_egg

After this procedure a python egg file has been created for the plugin, which we will copy into our project’s folder later. After this procedure we can use trac commands to create environment to create projects and more.

Create our trac environment directory

We can now create our trac environment diractory. You can initialize anywhere you want. My opinion is to create a directory under /usr/share/ directory named trac. Under this directory you can deploy your trac projects. Keep in mind that this directory will be exposed to web access.

mkdir /usr/share/trac
trac-admin /usr/share/trac/myproject initenv

now you will  be asked for a name of the project and the db connection string for this project ( mysql://tracuser:tracpass@localhost:3306/trac_myproject )

chown -R www-data:www-data /usr/share/trac/myproject

with the trac-admin command we created and initialized a project environemnet. Now you can create and initialize as much projects as you want under /usr/share/trac directory

We changed the group and owner of the project directory to apache user (www-data) to the project because we will now setup apache with mod_python module to serve the trac projects.

Apache Configuration

Usually main apache configuration file is /etc/apache2/apache2.conf, and we will edit it a litle to use python module for apache.

vi /etc/apache2/apache2.conf

Add the following lines at the end of the file:

<Location "/trac">
SetHandler mod_python
PythonInterpreter main_interpreter
PythonHandler trac.web.modpython_frontend
PythonOption TracEnvParentDir /usr/share/trac
PythonOption TracUriRoot /trac

You should now check if module mod_python is enabled. Check if a file python.load exists under /etc/apache2/mods-enabled/ directory. If it does not exist create it your self:

vi /etc/apache2/mods-enabled/python.load

and add this line to the file:

LoadModule python_module /usr/lib/apache2/modules/


Basic Authentication

If you want basic authentication via apache then add to the /etc/apache2/apache2.conf file the following lines:

vi /etc/apache2/apache2.conf

add the following

<LocationMatch "/trac/[^/]+/login">
 AuthType Basic
 AuthName "Trac"
 AuthUserFile /etc/trac/trac.htpasswd
 Require valid-user

save and exit

mkdir /etc/trac
htpasswd -c /etc/trac/trac.htpasswd admin

enter a password for the admin user

Now restart apache:

service apache2 restart

You can now visit the http://your-ip/trac/ or if you want to visit it locally

I installed trac to a remote server so I visit my projects by using it’s ip. Keep in mind that you should check for firewall settings to allow access to port 80.

Configure the project to use TracMercurial

now we should copy the python egg file we created when installing the TracMercurial plugin into project’s plugin directory.

cp /root/mercurial-plugin/dist/TracMercurial- /usr/share/trac/myproject/plugins/.

the name of the egg may vary depending of the dev version.

now lets make a profile for the mercurial, because it will be needed at next steps.

vi /root/.hgrc

and add the following lines by your needs.

username = Administrator <admin@trac>

Ofcourse this is a test environment, and we will create the repository inside the trac project directory. In an mercurial server environment you can include the actual repository directories.

mkdir -p /usr/share/trac/myproject/hg/
cd /usr/share/trac/myproject/hg/

now lets init a hg project

hg init (project-directory)
cd (project-directory)
(add some files)
hg add
hg commit -m 'Initial commit'

Our last configuration step is to configure project see the repository

vi /usr/share/trac/myproject/conf/trac.ini

check if these lines exist and if not, add them

node_format = short
show_rev = yes
tracext.hg.* = enabled

then under [trac] tag edit the corresponding to match:

repository_dir = /usr/share/trac/myproject/hg/(project-directory)
repository_type = hg

now you should do one more time:

chown -R www-data:www-data /usr/share/trac/myproject
service apache2 restart

I hope that all work fine!!!


How to install mercurial on centos

You can setup mercurial on a server just to keep your teams repository. It’s pretty easy to install it to your CentOS machine

Mercurial is a free, distributed source control management tool. It efficiently handles projects of any size and offers an easy and intuitive interface. You can setup mercurial on a server just to keep your teams repository. It’s pretty easy to install it to your CentOS machine , or vm. You can just run the command:

yum install mercurial


and that’s all. I think that it’s easy to install it to other Linux distributions too. Now all you have to do is to add a group for the developers and a user for each of them to have access to the repositories.

If your team of developers use windows as their primary operating system Mercurial is the right choice for a scm. Mercurial just works on Windows. The definitive Mercurial book (written by Bryan O’Sullivan – a fellow Irishman) is concise, and exhaustive. Better yet, if you want that warm fuzzy feeling a GUI gives you, then look no further than TortoiseHg – a top quality tool. It’s good to learn Mercurial mainly on the command line. I wanted to understand how Mercurial worked, and how it is different from SVN.