PDA

View Full Version : [Solved] Running Apache under a different locale


ricmik
February 9th, 2010, 04:28
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:

# setenv LANG "en_US.UTF-8"
# apachectl start


How can I achieve this when starting apache upon booting the server?

sixtydoses
February 9th, 2010, 05:45
Set the locale in your profile environment, or do it globally (/etc/profile).

http://www.freebsd.org/doc/handbook/using-localization.html

ricmik
February 9th, 2010, 13:41
OK, so the setting LANG=en_US.UTF-8 in /etc/profile will also apply for init-scripts?

sixtydoses
February 9th, 2010, 13:59
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.

ricmik
February 9th, 2010, 14:10
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).

sixtydoses
February 9th, 2010, 14:45
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.

ricmik
February 10th, 2010, 03:05
Setting LANG in /etc/profile didn't work either.
I also tried setenv LANG in /etc/csh.login and creating a login-class with :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 :(

sixtydoses
February 11th, 2010, 12:40
Do you have
AddDefaultCharset UTF-8
in your httpd.conf?

ricmik
February 16th, 2010, 02:52
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. :\

sixtydoses
February 16th, 2010, 03:29
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.

export LANG=en_US.UTF-8

Or, just write a simple script that set the lang variable first, and run apachectl.

ricmik
February 16th, 2010, 03:54
Thanks! :D
That worked.. I actually tried to alter the apache22 and apachectl scripts, but using "setenv" didn't work. export did the trick :)

sixtydoses
February 16th, 2010, 04:08
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.

BeastieBoy
July 5th, 2010, 12:18
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.

sixtydoses
July 5th, 2010, 12:23
Post #10.


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

export LANG=en_US.UTF-8

Or, just write a simple script that set the lang variable first, and run apachectl.

ricmik
July 5th, 2010, 13:16
I added the export into these scripts:

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