setting the LANG environment variable

997 views
Skip to first unread message

Gábor Farkas

unread,
Sep 24, 2009, 9:18:48 AM9/24/09
to mod...@googlegroups.com
hi,

i'm trying to setup a django application using modwsgi
in the daemon mode,
and i need to make sure the locale is set up correctly,
meaning sys.environment['LANG'] is 'en_US.utf8',
and not 'C'.

what is the recommended way to do this?

should i do it in my python-wsgi script with
"
sys.environment['LANG'] = 'en_US.utf8'
"

or is there a way to do it in the apache config file?

in the past i was using mod_fcgid, and there i could
set environment variables with something like this:
RewriteRule .* - [E=name:value]

but it does not seem to work here.

thanks,
gabor

Graham Dumpleton

unread,
Sep 24, 2009, 6:54:20 PM9/24/09
to mod...@googlegroups.com
2009/9/24 Gábor Farkas <ga...@nekomancer.net>:

>
> hi,
>
> i'm trying to setup a django application using modwsgi
> in the daemon mode,
> and i need to make sure the locale is set up correctly,
> meaning sys.environment['LANG'] is 'en_US.utf8',
> and not 'C'.
>
> what is the recommended way to do this?
>
> should i do it in my python-wsgi script with
> "
> sys.environment['LANG'] = 'en_US.utf8'
> "

You mean:

os.environ['LANG'] = 'en_US.utf8'

I am not sure that will work if this is done from WSGI script file as
it may be too late if it was needed to be set when Python was being
first initialised.

> or is there a way to do it in the apache config file?

No, can't be done in Apache configuration file.

> in the past i was using mod_fcgid, and there i could
> set environment variables with something like this:
> RewriteRule .* - [E=name:value]
>
> but it does not seem to work here.

This only works for FASTCGI/SCGI/CGI because they fork off separate
processes when needed and the SetEnv variables become process level
environment variables. In mod_wsgi the SetEnv variables are specific
to the WSGI environment dictionary passed to the WSGI application and
don't affect the whole process.

The only way I know that is 100% guaranteed to work is for stock
standard Apache installation, ie., from original source code, you
modify the 'envvars' file that should be in same directory as the
'httpd' executable. In this you would add:

LANG='en_US.utf8'
export LANG

On Linux distributions with packaged Apache, this file doesn't
generally exist. The only solution in that case is to modify the init
startup file for Apache service and add it there instead.

Graham

Gábor Farkas

unread,
Sep 25, 2009, 5:41:08 AM9/25/09
to mod...@googlegroups.com
Fri, Sep 25, 2009 at 12:54 AM, Graham Dumpleton

<graham.d...@gmail.com> wrote:
>
> 2009/9/24 Gábor Farkas <ga...@nekomancer.net>:
>>
>> hi,
>>
>> i'm trying to setup a django application using modwsgi
>> in the daemon mode,
>> and i need to make sure the locale is set up correctly,
>> meaning sys.environment['LANG'] is 'en_US.utf8',
>> and not 'C'.
>>
>> what is the recommended way to do this?
>>
>> should i do it in my python-wsgi script with
>> "
>> sys.environment['LANG'] = 'en_US.utf8'
>> "
>
> You mean:
>
>  os.environ['LANG'] = 'en_US.utf8'

yes :)

>
> The only way I know that is 100% guaranteed to work is for stock
> standard Apache installation, ie., from original source code, you
> modify the 'envvars' file that should be in same directory as the
> 'httpd' executable. In this you would add:
>
>  LANG='en_US.utf8'
>  export LANG
>
> On Linux distributions with packaged Apache, this file doesn't
> generally exist. The only solution in that case is to modify the init
> startup file for Apache service and add it there instead.

i'm running debian lenny, and '/etc/apache2/envvars' exists there.
i added
EXPORT LANG=en_US.utf8
to it, and it sends it correctly to the python wsgi application.

thanks for the help,
gabor

Reply all
Reply to author
Forward
0 new messages