= Trac and Apache suEXEC =
Trac in CGI-mode doesn't play very well with [http://httpd.apache.org/docs/suexec.html Apache suEXEC].
Setting the TRAC_ENV environment variable as described in TracInstall will not work when using suEXEC feature because the environment variables are filtered and only a limited subset reaches the CGI program.
There are obvious workarounds to make things work:
1. Recompile suexec to let it pass the TRAC_ENV variable; which requires root permissions and is not really advisable anyway.
2. Change our trac.cgi script to set the TRAC_ENV variable by itself, to do this we edit trac.cgi file and add
{{{
import os;os.environ['TRAC_ENV'] = '/path/to/projectenv'
}}}
at the very beginning of the script.
3. Make a wrapper script
{{{
#!/bin/bash
export TRAC_ENV='/path/to/projectenv'
exec /path/to/trac/trac.cgi
}}}
'''Note: This is a kludge, but works.'''
----
== Multiple Projects under suEXEC ==
When hosting multiple projects under suEXEC, you can either copy the CGI script and change the TRAC_ENV setting for each script, or make a wrapper script around it.
Here's a contributed script to work around the stripping of environment variables done by suEXEC.
{{{
#!/bin/bash
user="marcenuc"
prj="${PATH_INFO#/}"
prj="${prj%%/*}"
export TRAC_ENV="/home/${user}/.trac/prj/${prj}"
export SCRIPT_NAME="/~${user}/prj/${prj}"
export PATH_INFO="${PATH_INFO#/${prj}}"
export PYTHONPATH="/home/${user}/sw/lib/python2.3/site-packages"
exec ./trac.cgi
}}}
== Multiple Projects under Plesk/suEXEC/same domain ==
'''Added by torgny at sbbs.se'''
The above script works well if you want to have a Trac
instance for each user, but it does not really help if you have
several projects under the same site. In order to solve this under
Linux Red Hat with Plesk, I did the following:
First, from the Apache configuration ('''vhost.conf''' in this case),
replace '''DOMAIN''' with the domain you are adding:
{{{
RewriteEngine on
RewriteRule ^/projects/+$ /projects/index.php [L]
RewriteCond /home/httpd/vhosts/DOMAIN/private/tracs/$1 -d
RewriteRule ^/projects/([^/]+)(/?.*) /projects/wrap.cgi$2 [S=1,E=TRAC_ENV:/home/httpd/vhosts/DOMAIN/private/tracs/$1]
RewriteRule ^/projects/(.*) /projects/index.php
Alias /trac/ /usr/share/trac/htdocs/
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
AllowOverride None
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
AddHandler cgi-script .cgi
Order allow,deny
Allow from all
AuthType Basic
AuthName "Trac"
AuthUserFile /home/httpd/vhosts/DOMAIN/private/.htpasswd_trac
Require valid-user
}}}
And after that, add the folder to '''~/httpdocs/projects'''.
In that folder, either symlink '''trac.cgi''' or place a copy, and add '''index.html'''.
Index.php acts as the default page when a project without an existing
Trac environment is requested.
Now, for the wrap.cgi bash script:
{{{
#!/bin/bash
project="${SCRIPT_NAME#/projects/}"
export TRAC_ENV="/home/httpd/vhosts/DOMAIN/private/tracs/${project}"
export SCRIPT_NAME="/projects/${project}"
export PATH_INFO="${PATH_INFO#/${SCRIPT_NAME}}"
exec ./trac.cgi
}}}
The script above does all the work-around magic to make sure everything
works between suEXEC and Trac in CGI mode. It also gives you multiple
projects support.
----
See also: TracInstall, TracMultipleProjects