Edgewall Software

Trac on Ubuntu

Note from stratos: I tried a quite complicated route following TracOnUbuntu and TracModPython, facing installation errors in both pages so I am re-writting the instructions as they worked with me on a clean server install of Ubuntu 5.10 "BreezyBadger".

My intention was to have a TRAC installation on a virtual apache server that can handle multiple TRAC projects running as effecient as possible (mod-python).

These instructions are heavily based on the above mentioned pages and combine only what works...

Installation

1. Install Software Packages

To install Trac on your system, install the trac, libapache2-svn, python-subversion and libapache2-mod-python packages:

sudo apt-get install trac libapache2-svn python-subversion
sudo apt-get install libapache2-mod-python

2. Create the Trac Environments Directory

You'll need a directory for Trac's environments to live that should be writable by the default Apache user:

sudo mkdir /var/trac
sudo chown www-data:www-data /var/trac

3. Setup Apache2

Next, create a new Apache-2 virtualhost by saving the following as /etc/apache2/sites-available/trac :

#You need the following to load python
LoadModule python_module modules/mod_python.so
<VirtualHost * >
    DocumentRoot /var/trac
    # ***REMEMBER TO SET THE CORRECT DOMAIN NAME - or just use localhost ***
    ServerName trac.yourdomain.com

    <Location />
        SetHandler mod_python
        PythonHandler trac.web.modpython_frontend
        PythonOption TracEnvParentDir /var/trac
        PythonOption TracUriRoot /
    </Location>

    <LocationMatch "/[^/]+/login">
        AuthType Basic
        AuthName "Trac"
        AuthUserFile /var/svn/.htaccess
        Require valid-user
    </LocationMatch>

   Alias /trac /usr/share/trac/htdocs
    <LocationMatch /trac/>
        SetHandler None
    </LocationMatch>

    # Subversion
    <Location /svn>
        DAV svn
        # any /svn/foo URL will map to a repository /var/svn/foo
        # I've only got it working using SVNPath!!
        SVNParentPath /var/svn
        AuthType Basic
        AuthName "Subversion repository"
        AuthUserFile /var/svn/.htaccess
        Require valid-user
    </Location>

    ErrorLog /home/www/trac.yourdomain.com/logs/error.log

</VirtualHost>
   

Create an .htaccess file for authentication purposes

sudo mkdir /var/svn
sudo htpasswd -cm /var/svn/.htaccess userName

Create the directory structure for your error log file (I usually put mine on /home/www). Of course you can create your own directory wherever you prefer...

sudo mkdir -p /home/www/trac.yourdomain.com/logs

Enable your new virtual server, disable the default then restart Apache

sudo a2ensite trac
sudo a2dissite default
sudo /etc/init.d/apache2 restart

4. Creating Environments

I installed my Subversion repository at /var/svn/YourProjectNameHere. So I did a quick starting config of subversion with the following commands:

sudo mkdir /var/svn/YourProjectNameHere
sudo mkdir /tmp/YourProjectNameHere
sudo mkdir /tmp/YourProjectNameHere/branches
sudo mkdir /tmp/YourProjectNameHere/tags
sudo mkdir /tmp/YourProjectNameHere/trunk
sudo svnadmin create /var/svn/YourProjectNameHere
sudo svn import /tmp/YourProjectNameHere file:///var/svn/YourProjectNameHere -m "initial import"
sudo rm -rf /tmp/YourProjectNameHere

Some permissions changes and an apache restart are now needed:

sudo chown -R www-data /var/svn/YourProjectNameHere
sudo chown -R www-data /usr/share/trac
sudo apache2 -k restart

Test by web-browsing to http://servername/svn/YourProjectNameHere

If you see a simple web page which says Revision 1: / and lists branches, tags, and trunk, your Subversion install is up and running!

Now let's finish the Trac install (but don't go on to Trac install until you have the above working properly).

I put my trac environment at /var/trac/YourProjectNameHere. Of course you could use any other path or name - something a little more descriptive of your project would probably be a good idea. First I ran these commands:

sudo trac-admin /var/trac/YourProjectNameHere initenv

The "trac-admin" command shown above prompted me to enter:

  • the project name (YourProjectNameHere)
  • use the default database connection string (sqlite:db/trac.db)
  • the path to svn repository (/var/svn/YourProjectNameHere)
  • use the default Trac templates directory (/usr/share/trac/templates)

... then it prints out a bunch of stuff. If there are no errors change permissions on the project directory

sudo chown -R www-data /var/trac/YourProjectNameHere

You should now be able to surf to your Trac site at http://trac.yourdomain.com

From there, you should be shown a list of your Available Projects and if you click on YourProjectNameHere you will be taken to your TRAC installation for that project.

Comments & Suggestions