Edgewall Software

Version 9 (modified by anonymous, 17 years ago) ( diff )

Installing Trac on Ubuntu for Multiple Projects using Mod_Python

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: wajig install puts Trac's main files in the directory: /usr/share/trac

  1. install
      % wajig 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:

wajig 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 one one site; it doesnt say one way or another if you could do this with multiple virtual hosts on the same server, but i dont 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 mkdir /tmp/YourProjectNameHere
% sudo mkdir /tmp/YourProjectNameHere/branches
% sudo mkdir /tmp/YourProjectNameHere/tags
% sudo mkdir /tmp/YourProjectNameHere/trunk
% sudo svnadmin create /var/lib/svn/YourProjectNameHere
% sudo svn import /tmp/YourProjectNameHere file:///var/lib/svn/YourProjectNameHere -m "initial import"
% sudo rm -rf /tmp/YourProjectNameHere 

the tmp files are necessary so that the svn import command has something to import (even if it's empty). if you dont do all this the initenv command will fail, complaining that whatever SVN directory you give it "isnt an SVN directory".

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

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

where <user> is whoever is creating the project. note: the -R is important, as www-data needs to access the database files while 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.) }}}

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>
Note: See TracWiki for help on using the wiki.