Edgewall Software

Installing Trac on Ubuntu for Multiple Projects using Mod_Python

For a full tutorial to get SVN + Trac 0.11 running on Ubuntu with multiple projects view this link.

See wiki:0.11/TracOnUbuntu for an install of 0.11 on Ubuntu-8.04.

This page is geared towards an installation of Trac that will run off the Apache web server using mod_python, and support multiple projects. The distro is Ubuntu. I'm totally new to Trac, so feel free to correct any errors.

The install page on the Trac site (see TracInstall) is confusing. it doesn't explain well how Trac relates to the server. It gives manual install information, but on Ubuntu, which we use, you use apt-get instead. The next thing it recommends is to set up a project environment, but you probably don't actually want to this yet since you want to set up the interaction of Trac with the server first. This is done largely by following instructions on the TracModPython page.

There is another site for setting up Trac on Ubuntu, TracOnUbuntu, but the focus there is on the CGI method, plus for whatever reason, I found the instructions a little inapplicable for my system. for example, I had no dav_svn module in my /etc/apache2/mods-available directory, and that sent me on a wild goose chase for quite a while, only to realize I didn't need it (at least, so far!)

note: apt-get install puts Trac's main files in the directory: /usr/share/trac

  1. install
% apt-get install trac 

install all necessary dependencies as well.

it's worth opening the TracModPython page to follow along side these instructions.

  1. you do NOT need to add the line:

LoadModule python_module modules/mod_python.so to your apache2.conf file. But make sure you did:

% apt-get install libapache2-mod-python2.4

to install mod_python.

  1. you should create a directory where all your Trac projects will live. Issue (from TracOnUbuntu):
% sudo mkdir /var/lib/trac
% sudo chown www-data:www-data /var/lib/trac
  1. now add the following to the <VirtualHost> directive of whatever site you want to use Trac on:
<Location /projects> #set up Trac handling      
     SetHandler mod_python    
     PythonHandler trac.web.modpython_frontend    
     PythonOption TracEnvParentDir /var/lib/trac    
     PythonOption TracUriRoot /projects    
</Location>      

(this is the instructions given for if you want to host multiple projects on one site; it doesn't say one way or another if you could do this with multiple virtual hosts on the same server, but I don't see why not).

You can change /projects to be anything you want, as long as you are consistent throughout the other things you do which depend on what you call this location.

  1. you need to do some pre-configuration to set up an actual subversion project BEFORE the
    %sudo trac-admin <projectpath/project> initenv 
    

command will work.

assuming for now you just want to create an empty base project in subversion without any actual code, do the following:

create a 'home' subversion repository at /var/lib/svn (this isnt necessary, just useful), and create a skeleton config for a project like so (cf: TracOnUbuntu):

% sudo mkdir /var/lib/svn
% sudo mkdir /var/lib/svn/YourProjectNameHere
% sudo svnadmin create /var/lib/svn/YourProjectNameHere

then issue:

% sudo chown -R www-data /var/lib/svn/YourProjectNameHere
% sudo chown -R www-data /usr/share/trac
% sudo apache2 -k restart
  1. try creating a project now (as root/admin):
% sudo trac-admin /var/lib/trac/test_project initenv

You will be prompted to enter some information about your project: Project Name (enter the name of your project), Database connection string (press enter to accept the default), Repository type (press enter to accept the default), Path to repository (enter the path to the subversion repository, for example /var/lib/svn/YourProjectNameHere), and Templates directory (press enter to accept the default).

When done, you need to change the ownership of /var/lib/trac/test_project to

% sudo chown -R www-data:www-data /var/lib/trac/test_project

Note: the -R is important, as www-data needs to access the database files that sit a couple of directories down from the top project directory.

{{{ btw, i spent a LONG time trying to figure out why i was missing the dav_svn module (mod_dav_svn.so wasnt in /usr/lib/apache2/modules/), since the instructions on the "Trac on Ubuntu" site implied i needed it, but then i decided to just see what happened if i created a project environment and it succeeded. so… go figure. (From Alex: dav_svn is used to export Subversion repositories over HTTP.) }}}

Edit: You can get the dav_svn module by installing the libapache2-svn package (sudo apt-get libapache2-svn).

if everything has gone right, your site will be working now! go to http://www.yoursite.com/projects, and you should see a listing of your one lone project. click on it and arrive at your project's main page.

  1. authentication:

you dont NEED authentication, but it's a good idea. again, i found the main documentation lacked a couple of important details.

setting up the accounts is pretty much by the book:

% htpasswd -c /web/yoursite.org/.htpasswd admin
enter new password: 

for additional users (ie when you are not creating file for first time):

% htpasswd /web/yoursite.org/.htpasswd <someotheruser>
enter new password: 

meanwhile, in the apache config file, you need to have a Directory directive that specifies:

<Directory /absolute/path/yoursite.org/>
      AllowOverride AuthConfig
</Directory>

and then within the <VirtualHost>, you require:

<VirtualHost ... >

...other site directives...

    <Location /projects> #set up Trac handling

      ... other Trac directives from above...

     #authentication scheme
       AuthType Basic
       AuthName "Trac Projects"
       AuthUserFile /path/.htpasswd
       Require valid-user
   </Location>
</VirtualHost>

this accomplishes password protection for the entire projects location (access to the entire trac system and all it's projects).

*example complete directives section in your apache config file (ie apache2.conf, httpd.conf, etc.) for yoursite.org:

<VirtualHost aaa.bbb.ccc.ddd>

ServerName www.yoursite.org
ServerAdmin your@email.com
DocumentRoot /web/yoursite.org/www
etc...

  <Location /projects> #set up Trac handling

     SetHandler mod_python
     PythonHandler trac.web.modpython_frontend
     PythonOption TracEnvParentDir /var/lib/trac
     PythonOption TracUriRoot /projects

   #authentication scheme
     AuthType Basic
     AuthName "Descriptive Title Here"
     AuthUserFile /web/yoursite.org/.htpasswd
     Require valid-user

</Location>
</VirtualHost>

<Directory /web/yoursite.org/>
      AllowOverride AuthConfig
</Directory>
Last modified 7 years ago Last modified on Aug 7, 2009, 6:33:46 PM