Running Apache under a different locale

Hi!

I've installed a Kerberos integration application called Plexcel on a FreeBSD 7.2 box, running Apache 2.2.13 with PHP 5.2.11.

To get this working correctly with special characters, Apache needs to be running in a UTF-8 locale. Everything works perfectly when running Apache manually when setting the locale first, like this:
Code:
# setenv LANG "en_US.UTF-8"
# apachectl start

How can I achieve this when starting apache upon booting the server?
 
OK, so the setting LANG=en_US.UTF-8 in /etc/profile will also apply for init-scripts?
 
Not sure what you meant by init-scripts, were you referring to the apache script inside /usr/local/etc/rc.d?

If you've defined it as an environment variable inside the profile, there's no need to redefine it in the script.
 
Yep..
I need Apache to start with the UTF-8 locale at bootup.

The Plexcel manual have suggestions for Redhat Linux (adding HTTPD_LANG=en_US.UTF-8 to /etc/sysconfig/httpd) and Debian (adding LANG=en_US.UTF-8 in /etc/init.d/apache2) but had no suggestions for FreeBSD:
"On FreeBSD you can set the local Apache uses by setting the LANG variable before you start Apache (we do
not know how to make this change permanent – if you know please send us an email):
# setenv LANG "en_US.UTF-8"
# apachectl start
"​

I tried to add LANG=en_US.UTF-8 to the apachectl script to see if it was possible to start Apache in a UTF-8 locale when just running apachectl.
This did not work, so I didn't try adding it to the apache script in /usr/local/etc/rc.d (which is actually where I would like to "temporarily" change the locale just for Apache).
 
If you're going to start up apache on bootup, it should be fine by setting the locale in /etc/profile.

You can check it using the command locale.
 
Setting LANG in /etc/profile didn't work either.
I also tried setenv LANG in /etc/csh.login and creating a login-class with
Code:
:lang=en_US.UTF-8:\
None of these changes worked.. the only thing that changed was the locale for logged in users, not for init scripts :(
 
AddDefaultCharset doesn't apply to this problem :(

From the Apache HTTP Server manual:
Default charset parameter to be added when a response content-type is text/plain or text/html

AddDefaultCharset should only be used when all of the text resources to which it applies are known to be in that character encoding and it is too inconvenient to label their charset individually[...]

This does not change the locale that Apache is running under. :\
 
Hmm.. no idea at this point.

I don't play around with locale as much, and I thought by setting the environment variable lang in your profile would solve the problem, due to the fact that you had to run # setenv LANG "en_US.UTF-8" before firing up apachectl.

FWIW, you could try adding the following line in your /usr/local/sbin/apachectl script. But I don't know it that will work.

Code:
export LANG=en_US.UTF-8

Or, just write a simple script that set the lang variable first, and run apachectl.
 
Thanks! :D
That worked.. I actually tried to alter the apache22 and apachectl scripts, but using "setenv" didn't work. export did the trick :)
 
ricmik said:
Thanks! :D
That worked.. I actually tried to alter the apache22 and apachectl scripts, but using "setenv" didn't work. export did the trick :)

Awesome.

setenv didn't work in apachectl because it is a bourne shell script (/bin/sh), setenv is used by csh.
 
ricmik said:
Thanks! :D
That worked.. I actually tried to alter the apache22 and apachectl scripts, but using "setenv" didn't work. export did the trick :)

Where did you put the export statement? In /etc/profile?

I'm having the same problem with what you call init script, aka: daemons.
 
Post #10.

sixtydoses said:
FWIW, you could try adding the following line in your /usr/local/sbin/apachectl script. But I don't know it that will work.

Code:
export LANG=en_US.UTF-8

Or, just write a simple script that set the lang variable first, and run apachectl.
 
I added the export into these scripts:

/usr/local/etc/rc.d/apache22
/usr/local/sbin/apachectl
 
Back
Top