<- Back to the HOWTO section

How to use Trac with ajp-wsgi and Apache

  • Audience: Those who want to use Trac within a separate process from apache
  • Requires: MacPorts >=1.7, Mac OS X 10.5


There are several ways to run Trac with Apache: mod_wsgi, mod_python, and ajp-wsgi (and probably others...). This discusses how to get it working with ajp-wsgi, which runs as a single separate process from Apache's httpd. ajp-wsgi uses the Apache JServ Protocol to communicate with Apache, hence needs some configuration done in httpd.conf.


Install the necessary ports with:

sudo port install apache2
sudo port install trac
sudo port install ajp-wsgi +python26

The +python26 variant was selected for ajp-wsgi to use the current Python version, and Trac prefers 2.6 as well so this keeps them using the same version. Note that by default ajp-wsgi will select +python26 if not otherwise specified.


Configuring ajp-wsgi

First, ajp-wsgi needs to be setup to run with a launchd item. Create a new launchd plist in /Library/LaunchDaemons called com.example.ajp-wsgi.plist (change com.example to suit your network) with sudo vi /Library/LaunchDaemons/com.example.ajp-wsgi.plist (or a different editor you can run as root). Place the following into this new file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">

Be sure to replace /usr/local/trac with the location of your actual Trac project location. This example uses TRAC_ENV_PARENT_DIR which allows for multiple Trac projects to be located as subdirectories under that path.

Also note the /projects part being passed to ajp-wsgi, which tells it that all the Trac projects will be accessed with a URL whose path starts with /projects.

Configuring Apache2

Edit /opt/local/etc/apache2/httpd.conf in a text editor, and in the section pertinent to your server and how you want Trac accessed, add

   ProxyPass /projects/ ajp://localhost:8990/projects
   <Proxy */projects/*>
      Require all granted

This tells Apache that requests to /projects/* to be proxied over to localhost's port 8990 (which is where ajp-wsgi is listening, as specified above). This excerpt can be placed in the main portion of httpd.conf or in a <VirtualHost> section, depending on your needs.

Configuring Trac

Setup Trac as specified in Creating a Project Environment. Since this example uses the multiple-projects-in-a-directory, be sure to use a subdirectory as the project environment; for example, with the /usr/local/trac location used above:

trac-admin /usr/local/trac/myproject initenv

Make sure everything in /usr/local/trac is owned by the user _www as that's how ajp-wsgi is running, which will need write access so Trac can update files.


Try loading (replacing the domain and myproject as appropriate) and you should see the Trac page.

<- Back to the HOWTO section

Last modified 6 years ago Last modified on Oct 22, 2017, 11:55:03 AM