Setting Trac Locale with mod_wsgi

109 views
Skip to first unread message

Andrea Tomasini

unread,
Jan 21, 2009, 6:34:52 AM1/21/09
to trac-...@googlegroups.com
Hi there,
I am having problem in passing the right locale to trac using
mod_wsgi, with mod_python it used to work with a PythonOption
directive in the apache configuration, with mod_wsgi, I tried to use
the following:

SetEnv trac.locale "en_US.UTF-8"

but doesn't seem to have any effect. It also looks like the wsgi
script needs to be loaded with explicit os.environ settings to work.
My actual configuration:

# Define WSGI parameters
WSGIDaemonProcess wsgi-project user=www-data group=www-data threads=25
WSGIScriptAlias / /var/www/project/trac.wsgi

<Directory /var/www/project/trac/>
WSGIProcessGroup wsgi-project
WSGIApplicationGroup %{GLOBAL}
SetEnv trac.env_path /var/www/project/trac/
SetEnv trac.locale "en_US.UTF-8"
Order deny,allow
Allow from all
</Directory>

and the wsgi script contains:

import os
os.environ['TRAC_ENV'] = '/var/www/project/trac'
os.environ['PYTHON_EGG_CACHE'] = '/var/cache/python'
import trac.web.main
application = trac.web.main.dispatch_request

Looks like without the os.environ apache raises a 500 Internal Error,
and the log sais that Trac needs to have the environment variables set.

I would like to use only one of the two way, and have it working :-)

Ideas?

Thanks
ANdreaT

Graham Dumpleton

unread,
Jan 21, 2009, 9:35:00 PM1/21/09
to Trac Users
Can you post the exact error messages from the log.

Graham

Andrea Tomasini

unread,
Jan 22, 2009, 3:41:04 AM1/22/09
to trac-...@googlegroups.com

On 22 Jan, 2009, at 3:35 , Graham Dumpleton wrote:
>
> Can you post the exact error messages from the log.

[Wed Jan 21 11:15:50 2009] [error] [client X.X.X.X] mod_wsgi
(pid=16999): Exception occurred processing WSGI script '/var/www/
project/trac.wsgi'., referer: https://localhost/admin/ticket/milestones
[Wed Jan 21 11:15:50 2009] [error] [client X.X.X.X] Traceback (most
recent call last):, referer: https:/
/localhost/admin/ticket/milestones
[Wed Jan 21 11:15:50 2009] [error] [client X.X.X.X] File "/usr/lib/
python2.5/site-packages/Trac-0.11.2
.1-py2.5.egg/trac/web/main.py", line 381, in dispatch_request,
referer: https://localhost/admin/ticket/milestones
[Wed Jan 21 11:15:50 2009] [error] [client X.X.X.X] raise
EnvironmentError('The environment options "TRAC_ENV" or ', referer: https://localhost/admin/ticket/milestones
[Wed Jan 21 11:15:50 2009] [error] [client X.X.X.X] EnvironmentError:
The environment options "TRAC_ENV" or "TRAC_ENV_PARENT_DIR" or the
mod_python options "TracEnv" or "TracEnvParentDir" are missing. Trac
requires
one of these options to locate the Trac environment(s)., referer: https://localhost/admin/ticket/milestones

> Graham
Thanks Graham :-)

Best
ANdreaT

Graham Dumpleton

unread,
Jan 22, 2009, 10:02:40 AM1/22/09
to Trac Users
And what happens if you don't have a trailing slash on:

SetEnv trac.env_path /var/www/project/trac/

and leave out TRAC_ENV os.environ setting?

Are you running mod_python with the same Apache or any other instance
of Trac using either mod_python or mod_wsgi?

Graham

> ANdreaT

Andrea Tomasini

unread,
Jan 22, 2009, 12:37:36 PM1/22/09
to trac-...@googlegroups.com

On 22 Jan, 2009, at 16:02 , Graham Dumpleton wrote:

> And what happens if you don't have a trailing slash on:
>
> SetEnv trac.env_path /var/www/project/trac/
>
> and leave out TRAC_ENV os.environ setting?

Same... same error, without slash and removing all the os.environ from
the WSGI script. I have also noticed that in the Trac wiki page for
wsgi is not at all mentioned to set environment variables for WSGI
using the mod_env (SetEnv directive). Is this something new that
requires a specific version of mod_wsgi? I am running debian lenny
with mod_wsgi 2.3.*

> Are you running mod_python with the same Apache or any other instance
> of Trac using either mod_python or mod_wsgi?

mod_python is not even installed :-)

> Graham

ANdreaT

Graham Dumpleton

unread,
Jan 23, 2009, 4:41:41 AM1/23/09
to Trac Users


On Jan 23, 4:37 am, Andrea Tomasini <tumm...@gmail.com> wrote:
> On 22 Jan, 2009, at 16:02 , Graham Dumpleton wrote:
>
> > And what happens if you don't have a trailing slash on:
>
> >  SetEnv trac.env_path /var/www/project/trac/
>
> > and leave out TRAC_ENV os.environ setting?
>
> Same... same error, without slash and removing all the os.environ from  
> the WSGI script. I have also noticed that in the Trac wiki page for  
> wsgi is not at all mentioned to set environment variables for WSGI  
> using the mod_env (SetEnv directive). Is this something new that  
> requires a specific version of mod_wsgi? I am running debian lenny  
> with mod_wsgi 2.3.*

Use of SetEnv is mentioned in:

http://code.google.com/p/modwsgi/wiki/IntegrationWithTrac

Any page on the Trac wiki isn't going to mention all different
possible ways that mod_wsgi can be configured.

The mod_wsgi wiki also mentions use of SetEnv in:

http://code.google.com/p/modwsgi/wiki/IntegrationWithTrac

Trying using first recipe in section at:

http://code.google.com/p/modwsgi/wiki/DebuggingTechniques#Tracking_Request_and_Response

to wrap Trac application and verify what environment is being passed
to Trac. If the correct environment is being passed, then something
must be going wrong in Trac.

What version of Trac are you using?

Graham

Andrea Tomasini

unread,
Jan 24, 2009, 4:57:20 AM1/24/09
to trac-...@googlegroups.com

On 23 Jan, 2009, at 10:41 , Graham Dumpleton wrote:

> On Jan 23, 4:37 am, Andrea Tomasini <tumm...@gmail.com> wrote:
>
>> On 22 Jan, 2009, at 16:02 , Graham Dumpleton wrote:
>
> Use of SetEnv is mentioned in:
>
> http://code.google.com/p/modwsgi/wiki/IntegrationWithTrac
>
> Any page on the Trac wiki isn't going to mention all different
> possible ways that mod_wsgi can be configured.

I figured it out, that's where I copied the configuration from...

> Trying using first recipe in section at:
>
> http://code.google.com/p/modwsgi/wiki/DebuggingTechniques#Tracking_Request_and_Response
>
> to wrap Trac application and verify what environment is being passed
> to Trac. If the correct environment is being passed, then something
> must be going wrong in Trac.

I tried it out... and beside logging a _lot_ there is actually no trac
or TRAC variable in there... even if the SetEnv is set in the
Directory section of the apache config.

> What version of Trac are you using?

Trac 0.11.2.1
Apache+mod_wsgi+python2.5 on debian lenny :-)

Thanks for your help

> Graham
ANdreaT

Graham Dumpleton

unread,
Jan 24, 2009, 9:36:46 AM1/24/09
to Trac Users
I should have spotted it earlier. The following is wrong:

<Directory /var/www/project/trac/>

It should be:

<Directory /var/www/project/>

Because it was wrong you weren't even running in daemon mode but still
in embedded mode.

BTW, the mod_wsgi documentation says to put the WSGI script file in a
special subdirectory of its own, not in the parent directory to the
Trac instance. A subdirectory is used so that you are not telling
Apache that it could technically serve up files from your Trac
instance. A misconfiguration of your server could at the moment
technically allow people to download your Trac instance data because
of security on the file system being too loose.

Graham

On Jan 24, 5:57 pm, Andrea Tomasini <tumm...@gmail.com> wrote:
> On 23 Jan, 2009, at 10:41 , Graham Dumpleton wrote:
>
> > On Jan 23, 4:37 am, Andrea Tomasini <tumm...@gmail.com> wrote:
>
> >> On 22 Jan, 2009, at 16:02 , Graham Dumpleton wrote:
>
> > Use of SetEnv is mentioned in:
>
> >  http://code.google.com/p/modwsgi/wiki/IntegrationWithTrac
>
> > Any page on the Trac wiki isn't going to mention all different
> > possible ways that mod_wsgi can be configured.
>
> I figured it out, that's where I copied the configuration from...
>
> > Trying using first recipe in section at:
>
> >  http://code.google.com/p/modwsgi/wiki/DebuggingTechniques#Tracking_Re...

Andrea Tomasini

unread,
Jan 24, 2009, 12:15:57 PM1/24/09
to trac-...@googlegroups.com

On 24 Jan, 2009, at 15:36 , Graham Dumpleton wrote:

Hi Graham :-)

> I should have spotted it earlier. The following is wrong:
>
> <Directory /var/www/project/trac/>
>
> It should be:
>
> <Directory /var/www/project/>
>
> Because it was wrong you weren't even running in daemon mode but still
> in embedded mode.

Well this was it, now it works, also the locale settings ;-)

> BTW, the mod_wsgi documentation says to put the WSGI script file in a
> special subdirectory of its own, not in the parent directory to the
> Trac instance. A subdirectory is used so that you are not telling
> Apache that it could technically serve up files from your Trac
> instance. A misconfiguration of your server could at the moment
> technically allow people to download your Trac instance data because
> of security on the file system being too loose.

Fixed also this... thanks ;-)

> Graham

ANdreaT

Graham Dumpleton

unread,
Jan 24, 2009, 8:46:08 PM1/24/09
to Trac Users
Except that since you have Trac instance under /var/www/ then still
potentially exposed.

You shouldn't put the Trac instance anywhere under Apache document
root. It was only that you wrongly had it there in the first place
that the WSGI script was even half working. If it was elsewhere and
that path to Directory directive was wrong, you would have got
forbidden access as WSGI script file hadn't been marked as being
usable by Apache.

Graham
Reply all
Reply to author
Forward
0 new messages