| 1 | = Trac and mod_python = |
| 2 | |
| 3 | Trac supports [http://www.modpython.org/ mod_python], which speeds up Trac's response times considerably and permits use of many Apache features not possible with [wiki:TracStandalone tracd]/mod_proxy. |
| 4 | |
| 5 | Be sure to grab mod_python 3.1.3 and later for ''SetHandler'' ''mod_python'' directive to work. Also, older versions may generate an internal error (see [http://projects.edgewall.com/trac/ticket/1090 #1090]) |
| 6 | |
| 7 | == Simple configuration == |
| 8 | |
| 9 | If you just installed mod_python, you may have to add a line to load the module in the Apache configuration: |
| 10 | {{{ |
| 11 | LoadModule python_module modules/mod_python.so |
| 12 | }}} |
| 13 | |
| 14 | A simple setup of Trac on mod_python looks like this: |
| 15 | {{{ |
| 16 | <Location /projects/myproject> |
| 17 | SetHandler mod_python |
| 18 | PythonHandler trac.ModPythonHandler |
| 19 | PythonOption TracEnv /var/trac/myproject |
| 20 | PythonOption TracUriRoot /projects/myproject |
| 21 | </Location> |
| 22 | }}} |
| 23 | |
| 24 | Note that the option `TracUriRoot` may or may not be necessary in your setup. Try without first, and if the URLs produced by Trac look wrong or if Trac does not seem to recognize the URLs correctly, add the `TracUriRoot` option. |
| 25 | |
| 26 | Configuring authentication works the same as for [wiki:TracCgi#AddingAuthentication CGI]: |
| 27 | {{{ |
| 28 | <Location "/projects/myproject/login"> |
| 29 | AuthType Basic |
| 30 | AuthName "myproject" |
| 31 | AuthUserFile /var/trac/myproject/.htaccess |
| 32 | Require valid-user |
| 33 | </Location> |
| 34 | }}} |
| 35 | |
| 36 | If the Trac installation isn't installed in your Python path, you'll have to tell Apache where to find the Trac mod_python handler using the `PythonPath` directive: |
| 37 | {{{ |
| 38 | <Location /projects/myproject> |
| 39 | ... |
| 40 | PythonPath "sys.path + ['/path/to/trac']" |
| 41 | ... |
| 42 | </Location> |
| 43 | }}} |
| 44 | |
| 45 | == Setting up multiple projects == |
| 46 | |
| 47 | The Trac mod_python handler handler supports a configuration option similar to Subversion's `SvnParentPath`, called `TracEnvParentDir`: |
| 48 | {{{ |
| 49 | <Location /projects> |
| 50 | SetHandler mod_python |
| 51 | PythonHandler trac.ModPythonHandler |
| 52 | PythonOption TracEnvParentDir /var/trac |
| 53 | PythonOption TracUriRoot /projects |
| 54 | </Location> |
| 55 | }}} |
| 56 | |
| 57 | When you request the `/projects` URL, you will get a listing of all subdirectories of the directory you set as `TracEnvParentDir`. Selecting any project in the list will bring you to the corresponding Trac environment. |
| 58 | |
| 59 | If you don't want to have the subdirectory listing as your projects home page you can use a |
| 60 | {{{ |
| 61 | <LocationMatch "/.+/"> |
| 62 | }}} |
| 63 | |
| 64 | This will instruct Apache to use mod_python for all locations different from root while having the possibility of placing a custom home page for root in your !DocumentRoot folder. |
| 65 | |
| 66 | You can also use the same authentication realm for all of the projects using a `<LocationMatch>` directive: |
| 67 | {{{ |
| 68 | <LocationMatch "/[^/]+/login"> |
| 69 | AuthType Basic |
| 70 | AuthName "Trac" |
| 71 | AuthUserFile /var/trac/.htaccess |
| 72 | Require valid-user |
| 73 | </LocationMatch> |
| 74 | }}} |
| 75 | |
| 76 | == Troubleshooting == |
| 77 | |
| 78 | === Form submission problems === |
| 79 | |
| 80 | If you're experiencing problems submitting some of the forms in Trac (a common problem is that you get redirected to the start page after submission), check whether your {{{DocumentRoot}}} contains a folder or file with the same path that you mapped the mod_python handler to. For some reason, mod_python gets confused when it is mapped to a location that also matches a static resource. |
| 81 | |
| 82 | === Using .htaccess === |
| 83 | |
| 84 | Although it may seem trivial to rewrite the above configuration as a directory in your document root with a `.htaccess` file, this does not work. Apache will append a "/" to any Trac URLs, which interferes with its correct operation. |
| 85 | |
| 86 | It may be possible to work around this with mod_rewrite, but I failed to get this working. In all, it is more hassle than it is worth. Stick to the provided instructions. :) |
| 87 | |
| 88 | === Win32 Issues === |
| 89 | |
| 90 | If you run trac with mod_python on Windows, attachments will not work. |
| 91 | |
| 92 | There is a (simple) workaround for this which is to apply the patch attached to |
| 93 | ticket [http://projects.edgewall.com/trac/ticket/554 #554]. |
| 94 | |
| 95 | === OS X issues === |
| 96 | |
| 97 | When using mod_python on OS X you will not be able to restart Apache using `apachectl restart`. This is apparently fixed in mod_python 3.2, but there's also a patch available for earlier versions [http://www.dscpl.com.au/projects/vampire/patches.html here]. |
| 98 | |
| 99 | ---- |
| 100 | See also TracGuide, TracInstall, TracCgi, TracFastCgi |