Changes between Version 1 and Version 2 of TracModPython


Ignore:
Timestamp:
Jun 19, 2006, 12:44:11 AM (18 years ago)
Author:
trac
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • TracModPython

    v1 v2  
    11= Trac and mod_python =
    22
    3 Trac 0.7.1 and later 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 tracd/mod_proxy.
     3Trac 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.
    44
    55== Simple configuration ==
    66
    7 Here's a typical Trac CGI/Apache setup:
     7If you just installed mod_python, you may have to add a line to load the module in the Apache configuration:
     8{{{
     9LoadModule python_module modules/mod_python.so
     10}}}
    811
     12A simple setup of Trac on mod_python looks like this:
    913{{{
    10 ScriptAlias /projects/myproject /path/to/python/share/trac/cgi-bin/trac.cgi
    1114<Location /projects/myproject>
    12    SetEnv TRAC_ENV /var/trac/myproject
     15   SetHandler mod_python
     16   PythonHandler trac.web.modpython_frontend
     17   PythonOption TracEnv /var/trac/myproject
     18   PythonOption TracUriRoot /projects/myproject
    1319</Location>
    1420}}}
    1521
    16 The equivalent mod_python setup is:
     22Note 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.
    1723
     24Configuring authentication works the same as for [wiki:TracCgi#AddingAuthentication CGI]:
    1825{{{
    19 <Location /projects/myproject>
    20    SetHandler mod_python
    21    PythonHandler trac.ModPythonHandler
    22    PythonOption TracUriRoot "/projects/myproject"
    23    PythonOption TracEnv /var/trac/myproject
     26<Location "/projects/myproject/login">
     27  AuthType Basic
     28  AuthName "myproject"
     29  AuthUserFile /var/trac/myproject/.htaccess
     30  Require valid-user
    2431</Location>
    2532}}}
    2633
    27 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, add the ''TracUriRoot'' option.
     34If 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:
     35{{{
     36<Location /projects/myproject>
     37  ...
     38  PythonPath "sys.path + ['/path/to/trac']"
     39  ...
     40</Location>
     41}}}
     42
    2843
    2944== Setting up multiple projects ==
    3045
    31 The Trac mod_python handler handler supports a configuration option similar to Subversion's {{{SvnParentPath}}}, called {{{TracEnvParentDir}}}:
    32 
     46The Trac mod_python handler handler supports a configuration option similar to Subversion's `SvnParentPath`, called `TracEnvParentDir`:
    3347{{{
    3448<Location /projects>
    3549  SetHandler mod_python
    36   PythonHandler trac.ModPythonHandler
     50  PythonHandler trac.web.modpython_frontend
     51  PythonOption TracEnvParentDir /var/trac
    3752  PythonOption TracUriRoot /projects
    38   PythonOption TracEnvParentDir "/var/trac"
    39 </LocationMatch>
     53</Location>
    4054}}}
    4155
    42 When you request the {{{/projects}}} URL, you will get a (currently very simple) listing of all subdirectories of the directory you set as {{{TracEnvParentDir}}}. Selecting any project in the list will bring you to the corresponding Trac instance. You should make sure that the configured directory only contains Trac environment directories that match the currently installed Trac version, because that is not checked prior the the generation of the project list.
     56When 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.
    4357
     58If you don't want to have the subdirectory listing as your projects home page you can use a
     59{{{
     60<LocationMatch "/.+/">
     61}}}
    4462
    45 === Adding authentication ===
     63This 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.
    4664
    47 Adding authentication is straightforward in both cases. For example:
    48 
     65You can also use the same authentication realm for all of the projects using a `<LocationMatch>` directive:
    4966{{{
    50 <LocationMatch /projects/[[:alnum:]]+/login>
     67<LocationMatch "/[^/]+/login">
    5168  AuthType Basic
    5269  AuthName "Trac"
    53   AuthUserFile /var/www/passwd
     70  AuthUserFile /var/trac/.htaccess
    5471  Require valid-user
    5572</LocationMatch>
    5673}}}
    5774
     75== Virtual Host Configuration ==
     76
     77Below is the sample configuration required to set up your trac as a virtual server (i.e. when you access it at the URLs like
     78!http://trac.mycompany.com):
     79
     80{{{
     81<VirtualHost * >
     82    DocumentRoot /var/trac/myproject
     83    ServerName trac.mycompany.com
     84    <Directory />
     85        SetHandler mod_python
     86        PythonHandler trac.web.modpython_frontend
     87        PythonOption TracEnv /var/trac/myproject
     88        PythonOption TracUriRoot /
     89    </Directory>
     90    <Location /login>
     91        AuthType Basic
     92        AuthName "MyCompany Trac Server"
     93        AuthUserFile /var/trac/myproject/.htusers
     94        Require valid-user
     95    </Location>
     96</VirtualHost>
     97}}}
     98
     99== Troubleshooting ==
     100
     101=== Form submission problems ===
     102
     103If 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.
     104
     105=== Using .htaccess ===
     106
     107Although 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.
     108
     109It 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. :)
     110
    58111=== Win32 Issues ===
    59112
    60 If you run trac with mod_python on Windows, attachments will not work.
     113If you run trac with mod_python (3.1.3 or 3.1.4) on Windows,
     114uploading attachments will '''not''' work.
     115This is a known problem which we can't solve cleanly at the Trac level.
    61116
    62 There is a (simple) workaround for this which is to apply the patch attached to
    63 ticket [http://projects.edgewall.com/trac/ticket/554 #554].
     117However, there is a workaround for this at the mod_python level,
     118which is to apply the following patch [http://projects.edgewall.com/trac/attachment/ticket/554/util_py.patch attachment:ticket:554:util_py.patch]
     119to the (Lib/site-packages)/modpython/util.py file.
    64120
     121If you don't have the `patch` command, that file can be replaced with the [http://svn.apache.org/viewcvs.cgi/httpd/mod_python/trunk/lib/python/mod_python/util.py?rev=103562&view=markup  fixed util.py] (fix which, although done prior to the 3.1.4 release, is ''not''
     122present in 3.1.4).
     123
     124=== OS X issues ===
     125
     126When 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].
    65127
    66128----
    67 See also TracGuide, TracInstall, TracMultipleProjects
     129See also TracGuide, TracInstall, TracCgi, TracFastCgi