| 1 | [wiki:howto <- Back to the HOWTO section] |
| 2 | |
| 3 | = How to use Trac with ajp-wsgi and Apache = |
| 4 | |
| 5 | * Audience: Those who want to use Trac within a separate process from apache |
| 6 | * Requires: MacPorts >=1.6, Mac OS X 10.5 |
| 7 | |
| 8 | == Introduction == |
| 9 | |
| 10 | 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. |
| 11 | |
| 12 | == Installation == |
| 13 | |
| 14 | Install the necessary ports with: |
| 15 | {{{ |
| 16 | sudo port install apache2 |
| 17 | sudo port install trac |
| 18 | sudo port install ajp-wsgi +python25 |
| 19 | }}} |
| 20 | The {{{+python25}}} variant was selected for ajp-wsgi to use the current Python version, and Trac prefers 2.5 as well so this keeps them using the same version. By default, ajp-wsgi would otherwise depend on python24. |
| 21 | |
| 22 | == Configuration == |
| 23 | |
| 24 | === Configuring ajp-wsgi === |
| 25 | |
| 26 | 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 |
| 27 | {{{ |
| 28 | <?xml version="1.0" encoding="UTF-8"?> |
| 29 | <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
| 30 | <plist version="1.0"> |
| 31 | <dict> |
| 32 | <key>EnvironmentVariables</key> |
| 33 | <dict> |
| 34 | <key>PYTHONHOME</key> |
| 35 | <string>/opt/local</string> |
| 36 | <key>PYTHON_EGG_CACHE</key> |
| 37 | <string>/usr/local/trac/.python-egg-cache</string> |
| 38 | <key>TRAC_ENV_PARENT_DIR</key> |
| 39 | <string>/usr/local/trac</string> |
| 40 | </dict> |
| 41 | <key>GroupName</key> |
| 42 | <string>_www</string> |
| 43 | <key>KeepAlive</key> |
| 44 | <true/> |
| 45 | <key>Label</key> |
| 46 | <string>com.example.ajp-wsgi</string> |
| 47 | <key>ProgramArguments</key> |
| 48 | <array> |
| 49 | <string>/opt/local/bin/ajp-wsgi</string> |
| 50 | <string>-p</string> |
| 51 | <string>8990</string> |
| 52 | <string>trac.web.main</string> |
| 53 | <string>dispatch_request</string> |
| 54 | <string>/projects</string> |
| 55 | </array> |
| 56 | <key>UserName</key> |
| 57 | <string>_www</string> |
| 58 | <key>WorkingDirectory</key> |
| 59 | <string>/usr/local/trac</string> |
| 60 | </dict> |
| 61 | </plist> |
| 62 | }}} |
| 63 | 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. |
| 64 | |
| 65 | 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}}}. |
| 66 | |
| 67 | === Configuring Apache2 === |
| 68 | Edit {{{/opt/local/apache2/conf/httpd.conf}}} in a text editor, and in the section pertinent to your server and how you want Trac accessed, add |
| 69 | {{{ |
| 70 | ProxyPass /projects/ ajp://localhost:8990/projects |
| 71 | <Proxy */projects/*> |
| 72 | Order Allow,Deny |
| 73 | Allow from all |
| 74 | </Proxy> |
| 75 | }}} |
| 76 | 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. |
| 77 | |
| 78 | === Configuring Trac === |
| 79 | 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: |
| 80 | {{{ |
| 81 | trac-admin /usr/local/trac/myproject initenv |
| 82 | }}} |
| 83 | 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. |
| 84 | |
| 85 | == Testing == |
| 86 | |
| 87 | Try loading {{{http://www.example.com/projects/myproject}}} (replacing the domain and myproject as appropriate) and you should see the Trac page. |
| 88 | |
| 89 | [wiki:howto <- Back to the HOWTO section] |