TheTracGuide is not editable on this site. Changes should insteadbe made on theTrac Development site.
Please note that using Trac viaCGI is the slowest deployment method available. It is slower thanmod_wsgi,mod_python,FastCGI and evenIIS/AJP on Windows.
CGI script is the entrypoint that web-server calls when a web-request to an application is made. Thetrac.cgi
script can be created using thetrac-admin <env> deploy <dir>
command which automatically substitutes the required paths, seeTracInstall#cgi-bin. Make sure the script is executable by your web server.
InApache there are two ways to run Trac asCGI:
ScriptAlias
directive that maps aURL to thetrac.cgi
script (recommended)trac.cgi
file into the directory forCGI executables used by your web server (commonly namedcgi-bin
). You can also create a symbolic link, but in that case make sure that theFollowSymLinks
option is enabled for thecgi-bin
directory.To make Trac available athttp://yourhost.example.org/trac
addScriptAlias
directive to Apache configuration file, changingtrac.cgi
path to match your installation:
ScriptAlias/trac/path/to/www/trac/cgi-bin/trac.cgi
Note that this directive requires that the
mod_alias
module is enabled.
If you're using Trac with a single project you need to set its location using theTRAC_ENV
environment variable:
<Location"/trac">SetEnv TRAC_ENV"/path/to/projectenv"</Location>
Or to use multiple projects you can specify their common parent directory using theTRAC_ENV_PARENT_DIR
variable:
<Location"/trac">SetEnv TRAC_ENV_PARENT_DIR"/path/to/project/parent/dir"</Location>
Note that the
SetEnv
directive requires that themod_env
module is enabled.
An alternative toSetEnv
is editingTRAC_ENV
orTRAC_ENV_PARENT_DIR
intrac.cgi
:
os.environ['TRAC_ENV']="/path/to/projectenv"
os.environ['TRAC_ENV_PARENT_DIR']="/path/to/parent/dir"
If you are using theApache suEXEC feature please seeApacheSuexec.
On some systems, youmay need to edit the shebang line in thetrac.cgi
file to point to your real Python installation path. On a Windows system you may need to configure Windows to know how to execute a.cgi
file (Explorer -> Tools -> Folder Options -> File Types ->CGI).
Theegg-cache can be configured using anos.environ
statement intrac.cgi
, as shown above.To do the same from the Apache configuration, use theSetEnv
directive:
SetEnv PYTHON_EGG_CACHE/path/to/dir
Put this directive next to where you set the path to theTrac environment, i.e. in the same<Location>
block.
<Location/trac>SetEnv TRAC_ENV/path/to/projenvSetEnv PYTHON_EGG_CACHE/path/to/dir</Location>
You can run aWSGI handlerunder CGI. You canwrite your own application function, or use the deployed trac.wsgi's application.
SeeTracInstall#MappingStaticResources.
SeeTracInstall#ConfiguringAuthentication.
See also:TracInstall,TracModWSGI,TracFastCgi,TracModPython