Changes between Version 1 and Version 2 of TracFastCgi


Ignore:
Timestamp:
2006-09-10T02:41:18+02:00 (8 years ago)
Author:
trac
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • TracFastCgi

    v1 v2  
    44 
    55== Simple Apache configuration == 
     6 
     7There are two FastCGI modules commonly available for Apache: `mod_fastcgi` and 
     8`mod_fcgid`.  The `FastCgiIpcDir` and `FastCgiConfig` directives discussed 
     9below are `mod_fastcgi` directives; the `DefaultInitEnv` is a `mod_fgcid` 
     10directive. 
     11 
     12For `mod_fastcgi`, add the following to an appropriate Apache configuration 
     13file: 
    614{{{ 
    715# Enable fastcgi for .fcgi files 
     
    1422LoadModule fastcgi_module /usr/lib/apache2/modules/mod_fastcgi.so 
    1523}}} 
    16  
    17 You can either setup the `TRAC_ENV` as an overall default: 
     24Setting `FastCgiIpcDir` is optional if the default is suitable. 
     25 
     26Configure `ScriptAlias` or similar options as described in TracCgi, but 
     27calling `trac.fcgi` instead of `trac.cgi`. 
     28 
     29You can set up the `TRAC_ENV` as an overall default: 
    1830{{{ 
    1931FastCgiConfig -initial-env TRAC_ENV=/path/to/env/trac 
     
    2537}}} 
    2638 
    27 Configure `ScriptAlias` or similar options as described in TracCgi, but calling `trac.fcgi` instead of `trac.cgi`. 
     39But neither of these will work for `mod_fcgid`.  A similar but partial 
     40solution for `mod_fcgid` is: 
     41{{{ 
     42DefaultInitEnv TRAC_ENV /path/to/env/trac/ 
     43}}} 
     44But this cannot be used in `Directory` or `Location` context, which makes it 
     45difficult to support multiple projects. 
     46 
     47A better method which works for both of these modules (and for  [http://www.lighttpd.net/ lighttpd] and CGI as well), because it involves 
     48no server configuration settings for environment variables, is to set one 
     49of the variables in `trac.fcgi`, e.g.: 
     50{{{ 
     51import os 
     52os.environ['TRAC_ENV'] = "/path/to/projectenv" 
     53}}} 
     54or 
     55{{{ 
     56import os 
     57os.environ['TRAC_ENV_PARENT_DIR'] = "/path/to/project/parent/dir" 
     58}}} 
     59 
     60Using this method, different projects can be supported by using different 
     61`.fcgi` scripts with different `ScriptAliases`, copying and appropriately 
     62renaming `trac.fcgi` and adding the above code to create each such script. 
    2863 
    2964== Simple Lighttpd Configuration == 
     
    4883}}} 
    4984 
    50 Note that you will need to add a new entry to `fastcgi.server` for each separate Trac instance that you wish to run. Alternatively, you may use the `TRAC_ENV_PARENT_DIR` variable instead of `TRAC_ENV` as described  above. 
     85Note that you will need to add a new entry to `fastcgi.server` for each separate Trac instance that you wish to run. Alternatively, you may use the `TRAC_ENV_PARENT_DIR` variable instead of `TRAC_ENV` as described above, 
     86and you may set one of the two in `trac.fcgi` instead of in `lighttpd.conf` 
     87using `bin-environment` (as in the section above on Apache configuration). 
     88 
     89For using two projects with lighttpd add the following to your `lighttpd.conf`: 
     90{{{ 
     91fastcgi.server = ("/first" => 
     92                   ("first" => 
     93                    ("socket" => "/tmp/trac-fastcgi-first.sock", 
     94                     "bin-path" => "/path/to/cgi-bin/trac.fcgi", 
     95                     "check-local" => "disable", 
     96                     "bin-environment" => 
     97                       ("TRAC_ENV" => "/path/to/projenv-first") 
     98                    ) 
     99                  ), 
     100                  "/second" => 
     101                    ("second" => 
     102                    ("socket" => "/tmp/trac-fastcgi-second.sock", 
     103                     "bin-path" => "/path/to/cgi-bin/trac.fcgi", 
     104                     "check-local" => "disable", 
     105                     "bin-environment" => 
     106                       ("TRAC_ENV" => "/path/to/projenv-second") 
     107                    ) 
     108                  ) 
     109                ) 
     110}}} 
     111Note that field values are different.  If you prefer setting the environment 
     112variables in the `.fcgi` scripts, then copy/rename `trac.fcgi`, e.g., to 
     113`first.fcgi` and `second.fcgi`, and reference them in the above settings. 
     114Note that the above will result in different processes in any event, even 
     115if both are running from the same `trac.fcgi` script. 
     116{{{ 
     117#!html 
     118<p style="background: #fdc; border: 2px solid #d00; font-style: italic; padding: 0 .5em; margin: 1em 0;"> 
     119<strong>Note from c00i90wn:</strong> It's very important the order on which server.modules are loaded, if mod_auth is not loaded <strong>BEFORE</strong> mod_fastcgi, then the server will fail to authenticate the user. 
     120</p> 
     121}}} 
     122For authentication you should enable mod_auth in lighttpd.conf 'server.modules', select auth.backend and auth rules: 
     123{{{ 
     124server.modules              = ( 
     125... 
     126  "mod_auth", 
     127... 
     128) 
     129 
     130auth.backend               = "htpasswd" 
     131 
     132# Separated password files for each project 
     133# See "Conditional Configuration" in 
     134# http://trac.lighttpd.net/trac/file/branches/lighttpd-merge-1.4.x/doc/configuration.txt 
     135 
     136$HTTP["url"] =~ "^/first/" { 
     137  auth.backend.htpasswd.userfile = "/path/to/projenv-first/htpasswd.htaccess" 
     138} 
     139$HTTP["url"] =~ "^/second/" { 
     140  auth.backend.htpasswd.userfile = "/path/to/projenv-second/htpasswd.htaccess" 
     141} 
     142 
     143# Enable auth on trac URLs, see 
     144# http://trac.lighttpd.net/trac/file/branches/lighttpd-merge-1.4.x/doc/authentication.txt 
     145 
     146auth.require = ("/first/login" => 
     147                ("method"  => "basic", 
     148                 "realm"   => "First project", 
     149                 "require" => "valid-user" 
     150                ), 
     151                "/second/login" => 
     152                ("method"  => "basic", 
     153                 "realm"   => "Second project", 
     154                 "require" => "valid-user" 
     155                ) 
     156               ) 
     157 
     158 
     159}}} 
     160Note that lighttpd (I use version 1.4.3) stopped if password file doesn't exist. 
     161 
     162Note that lighttpd doesn't support 'valid-user' in versions prior to 1.3.16. 
     163 
     164Conditional configuration is also useful for mapping static resources, i.e. serving out images and CSS directly instead of through FastCGI: 
     165{{{ 
     166# Aliasing functionality is needed 
     167server.modules += ("mod_alias") 
     168 
     169# Setup an alias for the static resources 
     170alias.url = ("/trac/chrome/common" => "/usr/share/trac/htdocs") 
     171 
     172# Use negative lookahead, matching all requests that ask for any resource under /trac, EXCEPT in 
     173# /trac/chrome/common, and use FastCGI for those 
     174$HTTP["url"] =~ "^/trac(?!/chrome/common)" { 
     175# If you have previous fastcgi.server declarations for applications other than Trac, use += here 
     176# instead of = so you won't overwrite them 
     177fastcgi.server = ("/trac" => 
     178                   ("trac" => 
     179                     ("socket" => "/tmp/trac-fastcgi.sock", 
     180                      "bin-path" => "/path/to/cgi-bin/trac.fcgi", 
     181                      "check-local" => "disable", 
     182                      "bin-environment" => 
     183                        ("TRAC_ENV" => "/path/to/projenv") 
     184                     ) 
     185                   ) 
     186                 ) 
     187} 
     188}}} 
     189The technique can be easily adapted for use with multiple projects by creating aliases for each of them, and wrapping the fastcgi.server declarations inside conditional configuration blocks. 
     190Also there is another way to handle multiple projects and it's to use TRAC_ENV_PARENT_DIR instead of TRAC_ENV and use global auth, let's see an example: 
     191{{{ 
     192#  This is for handling multiple projects 
     193  alias.url       = ( "/trac/" => "/path/to/trac/htdocs/" ) 
     194 
     195  fastcgi.server += ("/projects"  => 
     196                      ("trac" => 
     197                        ( 
     198                          "socket" => "/tmp/trac.sock", 
     199                          "bin-path" => "/path/to/cgi-bin/trac.fcgi", 
     200                          "check-local" => "disable", 
     201                          "bin-environment" => 
     202                            ("TRAC_ENV_PARENT_DIR" => "/path/to/parent/dir/of/projects/" ) 
     203                        ) 
     204                      ) 
     205                    ) 
     206#And here starts the global auth configuration 
     207  auth.backend = "htpasswd" 
     208  auth.backend.htpasswd.userfile = "/path/to/unique/htpassword/file/trac.htpasswd" 
     209  $HTTP["url"] =~ "^/projects/.*/login$" { 
     210    auth.require = ("/" => 
     211                     ( 
     212                       "method"  => "basic", 
     213                       "realm"   => "trac", 
     214                       "require" => "valid-user" 
     215                     ) 
     216                   ) 
     217  } 
     218}}} 
     219 
     220Changing date/time format also supported by lighttpd over environment variable LC_TIME 
     221{{{ 
     222fastcgi.server = ("/trac" => 
     223                   ("trac" => 
     224                     ("socket" => "/tmp/trac-fastcgi.sock", 
     225                      "bin-path" => "/path/to/cgi-bin/trac.fcgi", 
     226                      "check-local" => "disable", 
     227                      "bin-environment" => 
     228                        ("TRAC_ENV" => "/path/to/projenv", 
     229                        "LC_TIME" => "ru_RU") 
     230                     ) 
     231                   ) 
     232                 ) 
     233}}} 
     234For details about languages specification see TracFaq question 2.13. 
    51235 
    52236Other important information like [http://trac.lighttpd.net/trac/wiki/TracInstall this updated TracInstall page], [wiki:TracCgi#MappingStaticResources and this] are useful for non-fastcgi specific installation aspects. 
    53237 
     238If you use trac-0.9, read [http://lists.edgewall.com/archive/trac/2005-November/005311.html about small bug] 
     239 
    54240Relaunch lighttpd, and browse to `http://yourhost.example.org/trac` to access Trac. 
     241 
     242Note about running lighttpd with reduced permissions: 
     243 
     244  If nothing else helps and trac.fcgi doesn't start with lighttpd settings __server.username = "www-data"__, __server.groupname = "www-data"__, then in the `bin-environment` section set `PYTHON_EGG_CACHE` to the home directory of `www-data` or some other directory accessible to this account for writing. 
    55245 
    56246----