[wiki:howto <- 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 == Introduction == There are several ways to run Trac with Apache: [http://trac.edgewall.org/wiki/TracModWSGI mod_wsgi], [http://trac.edgewall.org/wiki/TracModPython mod_python], and [http://www.saddi.com/software/ajp-wsgi/ 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 [http://tomcat.apache.org/connectors-doc/ajp/ajpv13a.html 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 {{{ EnvironmentVariables PYTHONHOME /opt/local/Library/Frameworks/Python.framework/Versions/2.6 PYTHON_EGG_CACHE /usr/local/trac/.python-egg-cache TRAC_ENV_PARENT_DIR /usr/local/trac GroupName _www KeepAlive Label com.example.ajp-wsgi ProgramArguments /opt/local/bin/ajp-wsgi -p 8990 trac.web.main dispatch_request /projects UserName _www WorkingDirectory /usr/local/trac }}} 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 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 section, depending on your needs. === Configuring Trac === Setup Trac as specified in [http://trac.edgewall.org/wiki/TracInstall#CreatingaProjectEnvironment 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. [wiki:howto <- Back to the HOWTO section]