Changes between Version 1 and Version 2 of TracModPython


Ignore:
Timestamp:
Apr 13, 2011, 9:04:35 PM (15 years ago)
Author:
trac
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • TracModPython

    v1 v2  
    11= 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.
     2[[TracGuideToc]]
     3
     4Trac supports [http://www.modpython.org/ mod_python], which speeds up Trac's response times considerably, especially compared to [TracCgi CGI], and permits use of many Apache features not possible with [wiki:TracStandalone tracd]/mod_proxy.
     5
     6These instructions are for Apache 2; if you are still using Apache 1.3, you may have some luck with [trac:wiki:TracModPython2.7 TracModPython2.7].
     7
     8== A Word of Warning ==
     9
     10As of 16^th^ June 2010, the mod_python project is officially dead.  If you are considering using mod_python for a new installation, '''please don't'''!  There are known issues which will not be fixed and there are now better alternatives.  Check out the main TracInstall pages for your target version for more information.
    411
    512== Simple configuration ==
     
    1017}}}
    1118
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
    1245A simple setup of Trac on mod_python looks like this:
    1346{{{
     47
    1448<Location /projects/myproject>
    1549   SetHandler mod_python
     50
    1651   PythonHandler trac.web.modpython_frontend
    1752   PythonOption TracEnv /var/trac/myproject
    1853   PythonOption TracUriRoot /projects/myproject
    19 </Location>
    20 }}}
    21 
    22 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.
    23 
    24 Configuring authentication works the same as for [wiki:TracCgi#AddingAuthentication CGI]:
    25 {{{
    26 <Location "/projects/myproject/login">
     54   Order allow,deny
     55   Allow from all
     56</Location>
     57}}}
     58
     59The option '''`TracUriRoot`''' may or may not be necessary in your setup. Try your configuration without it; if the URLs produced by Trac look wrong, if Trac does not seem to recognize URLs correctly, or you get an odd "No handler matched request to..." error, add the '''`TracUriRoot`''' option.  You will notice that the `Location` and '''`TracUriRoot`''' have the same path.
     60
     61The options available are
     62{{{
     63    # For a single project
     64    PythonOption TracEnv /var/trac/myproject
     65    # For multiple projects
     66    PythonOption TracEnvParentDir /var/trac/myprojects
     67    # For the index of multiple projects
     68    PythonOption TracEnvIndexTemplate /srv/www/htdocs/trac/project_list_template.html
     69    # A space delimitted list, with a "," between key and value pairs.
     70    PythonOption TracTemplateVars key1,val1 key2,val2
     71    # Useful to get the date in the wanted order
     72    PythonOption TracLocale en_GB.UTF8
     73    # See description above       
     74    PythonOption TracUriRoot /projects/myproject
     75}}}
     76
     77=== Python Egg Cache ===
     78
     79Compressed python eggs like Genshi are normally extracted into a directory named `.python-eggs` in the users home directory. Since apache's home usually is not writable an alternate egg cache directory can be specified like this:
     80{{{
     81PythonOption PYTHON_EGG_CACHE /var/trac/myprojects/egg-cache
     82}}}
     83
     84or you can uncompress the Genshi egg to resolve problems extracting from it.
     85=== Configuring Authentication ===
     86
     87Creating password files and configuring authentication works similar to the process for [wiki:TracCgi#AddingAuthentication CGI]:
     88{{{
     89#!xml
     90<Location /projects/myproject/login>
    2791  AuthType Basic
    2892  AuthName "myproject"
    29   AuthUserFile /var/trac/myproject/.htaccess
     93  AuthUserFile /var/trac/myproject/.ht
    3094  Require valid-user
    3195</Location>
    3296}}}
    3397
     98
     99
     100
     101
     102
     103
     104
     105
     106
     107
     108
     109
     110
     111
     112
     113
     114
     115
     116
     117
     118
     119
     120
     121
     122
     123
     124
     125
     126
     127
     128
     129
     130
     131
     132
     133
     134
     135
     136
     137
     138
     139
     140
     141
     142
     143
     144
     145
     146
     147
     148
     149
     150
     151
     152
     153
     154
     155
     156
     157
     158
     159
     160
     161
     162
     163
     164
     165
     166
     167
     168
     169
     170
     171
     172
     173
     174
     175
    34176If 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:
    35177{{{
     178
    36179<Location /projects/myproject>
    37180  ...
     
    41184}}}
    42185
     186
    43187
    44188== Setting up multiple projects ==
    45189
    46 The Trac mod_python handler handler supports a configuration option similar to Subversion's `SvnParentPath`, called `TracEnvParentDir`:
    47 {{{
     190The Trac mod_python handler supports a configuration option similar to Subversion's `SvnParentPath`, called `TracEnvParentDir`:
     191{{{
     192#!xml
    48193<Location /projects>
    49194  SetHandler mod_python
     195
    50196  PythonHandler trac.web.modpython_frontend
    51197  PythonOption TracEnvParentDir /var/trac
     
    54200}}}
    55201
    56 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.
     202When 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.
    57203
    58204If you don't want to have the subdirectory listing as your projects home page you can use a
    59205{{{
     206
    60207<LocationMatch "/.+/">
    61208}}}
     
    65212You can also use the same authentication realm for all of the projects using a `<LocationMatch>` directive:
    66213{{{
    67 <LocationMatch "/[^/]+/login">
     214#!xml
     215<LocationMatch "/projects/[^/]+/login">
    68216  AuthType Basic
    69217  AuthName "Trac"
    70   AuthUserFile /var/trac/.htaccess
     218  AuthUserFile /var/trac/.ht
    71219  Require valid-user
    72220</LocationMatch>
     
    79227
    80228{{{
     229
    81230<VirtualHost * >
    82     DocumentRoot /var/trac/myproject
     231    DocumentRoot /var//myproject
    83232    ServerName trac.mycompany.com
    84     <Directory />
     233    < />
    85234        SetHandler mod_python
     235
    86236        PythonHandler trac.web.modpython_frontend
    87237        PythonOption TracEnv /var/trac/myproject
    88238        PythonOption TracUriRoot /
    89     </Directory>
     239    </>
    90240    <Location /login>
    91241        AuthType Basic
    92242        AuthName "MyCompany Trac Server"
    93         AuthUserFile /var/trac/myproject/.htusers
     243        AuthUserFile /var/trac/myproject/.ht
    94244        Require valid-user
    95245    </Location>
     
    97247}}}
    98248
     249
     250
     251
     252
     253
     254
     255
     256
     257
    99258== Troubleshooting ==
    100259
     260
     261
     262
     263
     264
     265
     266
     267
     268
     269
     270
     271
     272
     273
     274
     275
     276
     277
     278
     279
     280
    101281=== Form submission problems ===
    102282
    103283If 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.
    104284
     285
     286
     287
     288
     289
     290
     291
     292
     293
     294
     295
     296
     297
     298
    105299=== Using .htaccess ===
    106300
     
    109303It 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. :)
    110304
     305
     306
     307
     308
     309
     310
     311
     312
     313
     314
     315
     316
     317
     318
     319
     320
     321
     322
     323
     324
     325
     326
     327
     328
     329
     330
     331
    111332=== Win32 Issues ===
    112 
    113 If you run trac with mod_python (3.1.3 or 3.1.4) on Windows,
    114 uploading attachments will '''not''' work.
    115 This is a known problem which we can't solve cleanly at the Trac level.
    116 
    117 However, there is a workaround for this at the mod_python level,
    118 which is to apply the following patch [http://projects.edgewall.com/trac/attachment/ticket/554/util_py.patch attachment:ticket:554:util_py.patch]
    119 to the (Lib/site-packages)/modpython/util.py file.
    120 
    121 If 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''
    122 present in 3.1.4).
     333If you run trac with mod_python < 3.2 on Windows, uploading attachments will '''not''' work. This problem is resolved in mod_python 3.1.4 or later, so please upgrade mod_python to fix this.
     334
    123335
    124336=== OS X issues ===
     
    126338When 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].
    127339
     340
     341
     342
     343
     344
     345
     346
     347
     348
     349
     350
     351
     352
     353
     354
     355
     356
     357
     358
     359
     360
     361
     362
     363
     364
     365
     366
     367
     368
     369
     370
     371
     372
     373
     374
     375
     376
     377
     378
     379
     380
     381
     382
     383
     384
     385
     386
     387
     388
     389
     390
     391
     392
     393
     394
     395
     396
     397
     398
     399
     400
     401
     402
     403
     404
     405
     406
     407
     408
     409
    128410----
    129 See also TracGuide, TracInstall, TracCgi, TracFastCgi
     411See also