| Version 79 (modified by anon, 6 years ago) |
|---|
Trac with FastCGI
Since version 0.9, Trac supports being run through the FastCGI interface. Like mod_python, this allows Trac to remain resident, and is faster than external CGI interfaces which must start a new process for each request. However, unlike mod_python, it is able to support SuEXEC. Additionally, it is supported by much wider variety of web servers.
Simple Apache configuration
There are two FastCGI modules commonly available for Apache: mod_fastcgi and mod_fcgid. The FastCgiIpcDir and FastCgiConfig directives discussed below are mod_fastcgi directives; the DefaultInitEnv is a mod_fgcid directive.
For mod_fastcgi, add the following to an appropriate Apache configuration file:
# Enable fastcgi for .fcgi files # (If you're using a distro package for mod_fcgi, something like # this is probably already present) <IfModule mod_fastcgi.c> AddHandler fastcgi-script .fcgi FastCgiIpcDir /var/lib/apache2/fastcgi </IfModule> LoadModule fastcgi_module /usr/lib/apache2/modules/mod_fastcgi.so
Setting FastCgiIpcDir is optional if the default is suitable. Note that the LoadModule line must be after the IfModule group.
Configure ScriptAlias or similar options as described in TracCgi, but calling trac.fcgi instead of trac.cgi.
You can set up the TRAC_ENV as an overall default:
FastCgiConfig -initial-env TRAC_ENV=/path/to/env/trac
Or you can serve multiple Trac projects in a directory like:
FastCgiConfig -initial-env TRAC_ENV_PARENT_DIR=/parent/dir/of/projects
But neither of these will work for mod_fcgid. A similar but partial solution for mod_fcgid is:
DefaultInitEnv TRAC_ENV /path/to/env/trac/
But this cannot be used in Directory or Location context, which makes it difficult to support multiple projects.
A better method which works for both of these modules (and for lighttpd and CGI as well), because it involves no server configuration settings for environment variables, is to set one of the variables in trac.fcgi, e.g.:
import os os.environ['TRAC_ENV'] = "/path/to/projectenv"
or
import os os.environ['TRAC_ENV_PARENT_DIR'] = "/path/to/project/parent/dir"
Using this method, different projects can be supported by using different .fcgi scripts with different ScriptAliases, copying and appropriately renaming trac.fcgi and adding the above code to create each such script.
Simple Lighttpd Configuration
The FastCGI front-end was developed primarily for use with alternative webservers, such as lighttpd.
lighttpd is a secure, fast, compliant and very flexible web-server that has been optimized for high-performance environments. It has a very low memory footprint compared to other web servers and takes care of CPU load.
For using trac.fcgi with lighttpd add the following to your lighttpd.conf:
fastcgi.server = ("/trac" =>
("trac" =>
("socket" => "/tmp/trac-fastcgi.sock",
"bin-path" => "/path/to/cgi-bin/trac.fcgi",
"check-local" => "disable",
"bin-environment" =>
("TRAC_ENV" => "/path/to/projenv")
)
)
)
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, and you may set one of the two in trac.fcgi instead of in lighttpd.conf using bin-environment (as in the section above on Apache configuration).
For using two projects with lighttpd add the following to your lighttpd.conf:
fastcgi.server = ("/first" =>
("first" =>
("socket" => "/tmp/trac-fastcgi-first.sock",
"bin-path" => "/path/to/cgi-bin/trac.fcgi",
"check-local" => "disable",
"bin-environment" =>
("TRAC_ENV" => "/path/to/projenv-first")
)
),
"/second" =>
("second" =>
("socket" => "/tmp/trac-fastcgi-second.sock",
"bin-path" => "/path/to/cgi-bin/trac.fcgi",
"check-local" => "disable",
"bin-environment" =>
("TRAC_ENV" => "/path/to/projenv-second")
)
)
)
Note that field values are different. If you prefer setting the environment variables in the .fcgi scripts, then copy/rename trac.fcgi, e.g., to first.fcgi and second.fcgi, and reference them in the above settings. Note that the above will result in different processes in any event, even if both are running from the same trac.fcgi script.