<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://t2bwiki.iihe.ac.be/index.php?action=history&amp;feed=atom&amp;title=TracCgi</id>
	<title>TracCgi - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://t2bwiki.iihe.ac.be/index.php?action=history&amp;feed=atom&amp;title=TracCgi"/>
	<link rel="alternate" type="text/html" href="https://t2bwiki.iihe.ac.be/index.php?title=TracCgi&amp;action=history"/>
	<updated>2026-04-20T23:48:02Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://t2bwiki.iihe.ac.be/index.php?title=TracCgi&amp;diff=298&amp;oldid=prev</id>
		<title>Maintenance script: Created page with &quot; == Installing Trac as CGI ==  &lt;pre&gt; #div class=important   &#039;&#039;Please note that using Trac via CGI is the slowest deployment method available. It is slower than [TracModPython ...&quot;</title>
		<link rel="alternate" type="text/html" href="https://t2bwiki.iihe.ac.be/index.php?title=TracCgi&amp;diff=298&amp;oldid=prev"/>
		<updated>2015-08-26T12:29:15Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot; == Installing Trac as CGI ==  &amp;lt;pre&amp;gt; #div class=important   &amp;#039;&amp;#039;Please note that using Trac via CGI is the slowest deployment method available. It is slower than [TracModPython ...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
== Installing Trac as CGI ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#div class=important&lt;br /&gt;
  &amp;#039;&amp;#039;Please note that using Trac via CGI is the slowest deployment method available. It is slower than [TracModPython mod_python], [TracFastCgi FastCGI] and even [trac:TracOnWindowsIisAjp IIS/AJP] on Windows.&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
CGI script is the entrypoint that web-server calls when a web-request to an application is made. To generate the &amp;lt;tt&amp;gt;trac.cgi&amp;lt;/tt&amp;gt; script run:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
trac-admin /path/to/env deploy /path/to/www/trac&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;trac.cgi&amp;lt;/tt&amp;gt; will be in the &amp;lt;tt&amp;gt;cgi-bin&amp;lt;/tt&amp;gt; folder inside the given path. Make sure it is executable by your web server. This command also copies &amp;lt;tt&amp;gt;static resource&amp;lt;/tt&amp;gt; files to a &amp;lt;tt&amp;gt;htdocs&amp;lt;/tt&amp;gt; directory of a given destination.&lt;br /&gt;
&lt;br /&gt;
=== Apache web-server configuration ===&lt;br /&gt;
&lt;br /&gt;
In [http://httpd.apache.org/ Apache] there are two ways to run Trac as CGI:&lt;br /&gt;
&lt;br /&gt;
#Use a &amp;lt;tt&amp;gt;ScriptAlias&amp;lt;/tt&amp;gt; directive that maps an URL to the &amp;lt;tt&amp;gt;trac.cgi&amp;lt;/tt&amp;gt; script (recommended)&lt;br /&gt;
 2. Copy the &amp;lt;tt&amp;gt;trac.cgi&amp;lt;/tt&amp;gt; file into the directory for CGI executables used by your web server (commonly named &amp;lt;tt&amp;gt;cgi-bin&amp;lt;/tt&amp;gt;). You can also create a symbolic link, but in that case make sure that the &amp;lt;tt&amp;gt;FollowSymLinks&amp;lt;/tt&amp;gt; option is enabled for the &amp;lt;tt&amp;gt;cgi-bin&amp;lt;/tt&amp;gt; directory.&lt;br /&gt;
&lt;br /&gt;
To make Trac available at &amp;lt;tt&amp;gt;http://yourhost.example.org/trac&amp;lt;/tt&amp;gt; add &amp;lt;tt&amp;gt;ScriptAlias&amp;lt;/tt&amp;gt; directive to Apache configuration file, changing &amp;lt;tt&amp;gt;trac.cgi&amp;lt;/tt&amp;gt; path to match your installation:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ScriptAlias /trac /path/to/www/trac/cgi-bin/trac.cgi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;#039;&amp;#039;Note that this directive requires enabled &amp;lt;tt&amp;gt;mod_alias&amp;lt;/tt&amp;gt; module.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
If you&amp;#039;re using Trac with a single project you need to set its location using the &amp;lt;tt&amp;gt;TRAC_ENV&amp;lt;/tt&amp;gt; environment variable:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;Location &amp;quot;/trac&amp;quot;&amp;gt;&lt;br /&gt;
  SetEnv TRAC_ENV &amp;quot;/path/to/projectenv&amp;quot;&lt;br /&gt;
&amp;lt;/Location&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or to use multiple projects you can specify their common parent directory using the &amp;lt;tt&amp;gt;TRAC_ENV_PARENT_DIR&amp;lt;/tt&amp;gt; variable:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;Location &amp;quot;/trac&amp;quot;&amp;gt;&lt;br /&gt;
  SetEnv TRAC_ENV_PARENT_DIR &amp;quot;/path/to/project/parent/dir&amp;quot;&lt;br /&gt;
&amp;lt;/Location&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;#039;&amp;#039;Note that the &amp;lt;tt&amp;gt;SetEnv&amp;lt;/tt&amp;gt; directive requires enabled &amp;lt;tt&amp;gt;mod_env&amp;lt;/tt&amp;gt; module. It is also possible to set TRAC_ENV in trac.cgi. Just add the following code between &amp;quot;try:&amp;quot; and &amp;quot;from trac.web ...&amp;quot;:&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    import os&lt;br /&gt;
    os.environ[&amp;#039;TRAC_ENV&amp;#039;] = &amp;quot;/path/to/projectenv&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;#039;&amp;#039; Or for TRAC_ENV_PARENT_DIR: &amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    import os&lt;br /&gt;
    os.environ[&amp;#039;TRAC_ENV_PARENT_DIR&amp;#039;] = &amp;quot;/path/to/project/parent/dir&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you are using the [http://httpd.apache.org/docs/suexec.html Apache suEXEC] feature please see http://trac.edgewall.org/wiki/ApacheSuexec.&lt;br /&gt;
&lt;br /&gt;
On some systems, you &amp;#039;&amp;#039;may&amp;#039;&amp;#039; need to edit the shebang line in the &amp;lt;tt&amp;gt;trac.cgi&amp;lt;/tt&amp;gt; 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 -&amp;gt; Tools -&amp;gt; Folder Options -&amp;gt; File Types -&amp;gt; CGI).&lt;br /&gt;
&lt;br /&gt;
=== Mapping Static Resources ===&lt;br /&gt;
&lt;br /&gt;
Out of the box, Trac will pass static resources such as style sheets or images through itself. For a CGI setup this is &amp;#039;&amp;#039;&amp;#039;highly undesirable&amp;#039;&amp;#039;&amp;#039;, because this way CGI script is invoked for documents that could be much more efficiently served directly by web server.&lt;br /&gt;
&lt;br /&gt;
Web servers such as [http://httpd.apache.org/ Apache] allow you to create “Aliases” to resources, giving them a virtual URL that doesn&amp;#039;t necessarily reflect the layout of the servers file system. We already used this capability by defining a &amp;lt;tt&amp;gt;ScriptAlias&amp;lt;/tt&amp;gt; for the CGI script. We also can map requests for static resources directly to the directory on the file system, avoiding processing these requests by CGI script.&lt;br /&gt;
&lt;br /&gt;
There are two primary URL paths for static resources - &amp;lt;tt&amp;gt;/chrome/common&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;/chrome/site&amp;lt;/tt&amp;gt;. Plugins can add their own resources usually accessible by &amp;lt;tt&amp;gt;/chrome/plugin&amp;lt;/tt&amp;gt; path, so its important to override only known paths and not try to make universal &amp;lt;tt&amp;gt;/chrome&amp;lt;/tt&amp;gt; alias for everything.&lt;br /&gt;
&lt;br /&gt;
Add the following snippet to Apache configuration &amp;#039;&amp;#039;&amp;#039;before&amp;#039;&amp;#039;&amp;#039; the &amp;lt;tt&amp;gt;ScriptAlias&amp;lt;/tt&amp;gt; for the CGI script, changing paths to match your deployment:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Alias /trac/chrome/common /path/to/trac/htdocs&lt;br /&gt;
&amp;lt;Directory &amp;quot;/path/to/www/trac/htdocs&amp;quot;&amp;gt;&lt;br /&gt;
  Order allow,deny&lt;br /&gt;
  Allow from all&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that we mapped &amp;lt;tt&amp;gt;/trac&amp;lt;/tt&amp;gt; part of the URL to the &amp;lt;tt&amp;gt;trac.cgi&amp;lt;/tt&amp;gt; script, and the path &amp;lt;tt&amp;gt;/chrome/common&amp;lt;/tt&amp;gt; is the path you have to append to that location to intercept requests to the static resources. &lt;br /&gt;
&lt;br /&gt;
For example, if Trac is mapped to &amp;lt;tt&amp;gt;/cgi-bin/trac.cgi&amp;lt;/tt&amp;gt; on your server, the URL of the Alias should be &amp;lt;tt&amp;gt;/cgi-bin/trac.cgi/chrome/common&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Similarly, if you have static resources in a project&amp;#039;s htdocs directory (which is referenced by /chrome/site URL in themes), you can configure Apache to serve those resources (again, put this &amp;#039;&amp;#039;&amp;#039;before&amp;#039;&amp;#039;&amp;#039; the &amp;lt;tt&amp;gt;ScriptAlias&amp;lt;/tt&amp;gt; for the CGI script, and adjust names and locations to match your installation):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Alias /trac/chrome/site /path/to/projectenv/htdocs&lt;br /&gt;
&amp;lt;Directory &amp;quot;/path/to/projectenv/htdocs&amp;quot;&amp;gt;&lt;br /&gt;
  Order allow,deny&lt;br /&gt;
  Allow from all&lt;br /&gt;
&amp;lt;/Directory&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively to hacking &amp;lt;tt&amp;gt;/trac/chrome/site&amp;lt;/tt&amp;gt;, you can directly specify path to static resources using &amp;lt;tt&amp;gt;htdocs_location&amp;lt;/tt&amp;gt; configuration option in [[TracIni| trac.ini]]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[trac]&lt;br /&gt;
htdocs_location = http://yourhost.example.org/trac-htdocs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Trac will then use this URL when embedding static resources into HTML pages. Of course, you still need to make the Trac &amp;lt;tt&amp;gt;htdocs&amp;lt;/tt&amp;gt; directory available through the web server at the specified URL, for example by copying (or linking) the directory into the document root of the web server:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ln -s /path/to/www/trac/htdocs /var/www/yourhost.example.org/trac-htdocs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that in order to get this &amp;lt;tt&amp;gt;htdocs&amp;lt;/tt&amp;gt; directory, you need first to extract the relevant Trac resources using the &amp;lt;tt&amp;gt;deploy&amp;lt;/tt&amp;gt; command of TracAdmin:&lt;br /&gt;
[[TracAdminHelp(deploy)]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Adding Authentication ===&lt;br /&gt;
&lt;br /&gt;
The simplest way to enable authentication with Apache is to create a password file. Use the &amp;lt;tt&amp;gt;htpasswd&amp;lt;/tt&amp;gt; program to create the password file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ htpasswd -c /somewhere/trac.htpasswd admin&lt;br /&gt;
New password: &amp;lt;type password&amp;gt;&lt;br /&gt;
Re-type new password: &amp;lt;type password again&amp;gt;&lt;br /&gt;
Adding password for user admin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the first user, you dont need the &amp;quot;-c&amp;quot; option anymore:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ htpasswd /somewhere/trac.htpasswd john&lt;br /&gt;
New password: &amp;lt;type password&amp;gt;&lt;br /&gt;
Re-type new password: &amp;lt;type password again&amp;gt;&lt;br /&gt;
Adding password for user john&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;#039;&amp;#039;See the man page for &amp;lt;tt&amp;gt;htpasswd&amp;lt;/tt&amp;gt; for full documentation.&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
After you&amp;#039;ve created the users, you can set their permissions using TracPermissions.&lt;br /&gt;
&lt;br /&gt;
Now, you&amp;#039;ll need to enable authentication against the password file in the Apache configuration:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;Location &amp;quot;/trac/login&amp;quot;&amp;gt;&lt;br /&gt;
  AuthType Basic&lt;br /&gt;
  AuthName &amp;quot;Trac&amp;quot;&lt;br /&gt;
  AuthUserFile /somewhere/trac.htpasswd&lt;br /&gt;
  Require valid-user&lt;br /&gt;
&amp;lt;/Location&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you&amp;#039;re hosting multiple projects you can use the same password file for all of them:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;LocationMatch &amp;quot;/trac/[^/]+/login&amp;quot;&amp;gt;&lt;br /&gt;
  AuthType Basic&lt;br /&gt;
  AuthName &amp;quot;Trac&amp;quot;&lt;br /&gt;
  AuthUserFile /somewhere/trac.htpasswd&lt;br /&gt;
  Require valid-user&lt;br /&gt;
&amp;lt;/LocationMatch&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For better security, it is recommended that you either enable SSL or at least use the “digest” authentication scheme instead of “Basic”. Please read the [http://httpd.apache.org/docs/2.0/ Apache HTTPD documentation] to find out more. For example, on a Debian 4.0r1 (etch) system the relevant section  in apache configuration can look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;Location &amp;quot;/trac/login&amp;quot;&amp;gt;&lt;br /&gt;
    LoadModule auth_digest_module /usr/lib/apache2/modules/mod_auth_digest.so&lt;br /&gt;
    AuthType Digest&lt;br /&gt;
    AuthName &amp;quot;trac&amp;quot;&lt;br /&gt;
    AuthDigestDomain /trac&lt;br /&gt;
    AuthUserFile /somewhere/trac.htpasswd&lt;br /&gt;
    Require valid-user&lt;br /&gt;
&amp;lt;/Location&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and you&amp;#039;ll have to create your .htpasswd file with htdigest instead of htpasswd as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# htdigest /somewhere/trac.htpasswd trac admin&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
where the &amp;quot;trac&amp;quot; parameter above is the same as AuthName above  (&amp;quot;Realm&amp;quot; in apache-docs). &lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
See also:  TracGuide, TracInstall, [[TracModWSGI]], TracFastCgi, TracModPython&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{TracNotice|{{PAGENAME}}}}&lt;/div&gt;</summary>
		<author><name>Maintenance script</name></author>
	</entry>
</feed>