Edgewall Software

Recipe: Configuring Apache2 on CentOS-4.2 to serve Trac

This page duplicates information available on the TracModPython page, and discusses an obsolete platform. The page will eventually be deleted.

Getting Trac to work with Apache is not difficult, but there are a number of caveats. We will start with the DSO modules for Apache. mod_python is provided for by the default Apache2 configuration on CentOS-4.2. The configuration file is found at /etc/httpd/conf.d/python.conf and, as the settings in the default seem to serve, you can forget about modifying your conf/httpd.conf file for now.

Next, there is the issue of permissions on both the Trac environment and the Subversion repository. I came to the conclusion that it would be best to create separate users and groups forTtrac and Subversion called trac:trac and svn:svn respectively. I then set the ownerships on the Trac environment and subversion repositories to trac:trac and svn:svn. I next added the Apache user as a member to both the Trac and svn groups. This allows Apache to read the files in both these directory structures.

The final bit is to create a file called something like '/etc/httpd/conf.d/trac.conf' and place the httpd directives for Trac and Python in it. In my case I set up a virtual server called trac.mydomain.tld and put the following lines in a file called '/etc/httpd/conf.d/trac.mydomain.tld.conf':

<VirtualHost *>

DocumentRoot "/var/data/trac"
ServerName trac.mydomain.tld
<Directory "/var/data/trac">
allow from all
Options +Indexes
<Location />
   SetHandler mod_python
   PythonHandler trac.web.modpython_frontend
   PythonOption TracEnv /var/data/trac
   SetEnv PYTHON_EGG_CACHE /var/data/trac/cache
   PythonOption TracUriRoot /
 <Location "/">
   AuthType Digest
   AuthName "tld.mydomain"
   AuthDigestDomain /
   AuthDigestFile /var/data/trac/conf/trac.htdigest
#Should be set to this for the more recent mod_auth_digest:
#   AuthUserFile /var/data/trac/conf/trac.htdigest
   Require valid-user


Note that the Trac environment is located at '/var/data/trac' and that instead of htpasswd I use htdigest and lock down the entire Trac environment from anonymous access.

I had to create the egg.cache inside the Trac environment to avoid permission problems in the /var/www/htdocs directory. The 'TracUriRoot /' is required so that Trac can find its support files like stylesheets and plugins, '/' in this case equates to '/var/data/trac'.

The AuthName directive refers to the realm used when creating the htdigest file for user authentication. The AuthDigestDomain sets the uri covered by controlled access, '/' means the entire site is closed to public viewing. The user password file is created in '/var/data/trac/conf/trac.htdigest' with the htdigest program.

This setup does not yet employ cgi or fastcgi, so it will be slow.

Last modified 7 years ago Last modified on Jul 2, 2015, 1:32:03 AM
Note: See TracWiki for help on using the wiki.