Version 3 (modified by Schamschula (Marius Schamschula), 7 years ago) (diff) |
---|
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
Introduction
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.
Installation
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.
Configuration
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" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>EnvironmentVariables</key> <dict> <key>PYTHONHOME</key> <string>/opt/local/Library/Frameworks/Python.framework/Versions/2.6</string> <key>PYTHON_EGG_CACHE</key> <string>/usr/local/trac/.python-egg-cache</string> <key>TRAC_ENV_PARENT_DIR</key> <string>/usr/local/trac</string> </dict> <key>GroupName</key> <string>_www</string> <key>KeepAlive</key> <true/> <key>Label</key> <string>com.example.ajp-wsgi</string> <key>ProgramArguments</key> <array> <string>/opt/local/bin/ajp-wsgi</string> <string>-p</string> <string>8990</string> <string>trac.web.main</string> <string>dispatch_request</string> <string>/projects</string> </array> <key>UserName</key> <string>_www</string> <key>WorkingDirectory</key> <string>/usr/local/trac</string> </dict> </plist>
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 </Proxy>
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.
Testing
Try loading http://www.example.com/projects/myproject
(replacing the domain and myproject as appropriate) and you should see the Trac page.