# Running Apache under a different locale



## ricmik (Feb 9, 2010)

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 (Feb 9, 2010)

Set the locale in your profile environment, or do it globally (/etc/profile).

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


----------



## ricmik (Feb 9, 2010)

OK, so the setting LANG=en_US.UTF-8 in /etc/profile will also apply for init-scripts?


----------



## sixtydoses (Feb 9, 2010)

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 (Feb 9, 2010)

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 (Feb 9, 2010)

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 (Feb 10, 2010)

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 (Feb 11, 2010)

Do you have 

```
AddDefaultCharset   UTF-8
```
in your httpd.conf?


----------



## ricmik (Feb 16, 2010)

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 (Feb 16, 2010)

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 (Feb 16, 2010)

Thanks! 
That worked.. I actually tried to alter the apache22 and apachectl scripts, but using "setenv" didn't work. export did the trick


----------



## sixtydoses (Feb 16, 2010)

ricmik said:
			
		

> Thanks!
> 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 (Jul 5, 2010)

ricmik said:
			
		

> Thanks!
> 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 (Jul 5, 2010)

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.
> 
> 
> ```
> ...


----------



## ricmik (Jul 5, 2010)

I added the export into these scripts:

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


----------

