losing locale when running fcgi script
Question: I'm facing an issue with encoding in running a django app. I finally found out
my django app has no locale set.

The weird thing is that I did set up the envvars file correctly. With this in
envvars :

    
    
    export APACHE_RUN_USER=www-data
    export APACHE_RUN_GROUP=www-data
    export APACHE_PID_FILE=/var/run/apache2.pid
    
    ## The locale used by some modules like mod_dav
    export LANG=C
    ## Uncomment the following line to use the system default locale instead:
    . /etc/default/locale
    
    export LANG
    locale
    

When I restart apache the locale command gets executed and I get correct
fr_FR.UTF-8 settings for LANG and LC_*.

Now I set up a little test.fcgi script :

    
    
    #!/usr/bin/python
    def myapp(environ, start_response):
        start_response('200 OK', [('Content-Type', 'text/plain')])
        from commands import getoutput
        return ["%s"%getoutput("locale")]
    
    from flup.server.fcgi import WSGIServer
    WSGIServer(myapp).run()
    

when I run it with

    
    
    sudo -u www-data test.fcgi
    

I get the correct locale settings as well. But whenever I access the script
through a web browser, I get no locale settings :

    
    
    LANG=
    LC_CTYPE="POSIX"
    LC_NUMERIC="POSIX"
    LC_TIME="POSIX"
    LC_COLLATE="POSIX"
    LC_MONETARY="POSIX"
    LC_MESSAGES="POSIX"
    LC_PAPER="POSIX"
    LC_NAME="POSIX"
    LC_ADDRESS="POSIX"
    LC_TELEPHONE="POSIX"
    LC_MEASUREMENT="POSIX"
    LC_IDENTIFICATION="POSIX"
    LC_ALL=
    

How come Apache has the right setting but my fcgi script hasn't?


Answer: I solved it by adding `DefaultInitEnv LANG "en_US.UTF-8"` in my `sites-
available/default`. Now the fcgi script tells me UTF-8 !

