Reputation: 563
I'm trying to find out system locale from PHP script on Debian. The way I do:
<?php
$out = shell_exec('locale');
print_r($out);
?>
Result:
LANG=C
LANGUAGE=
LC_CTYPE="C"
LC_NUMERIC="C"
...
But when I write 'locale' command in my system console I get 'right' result:
LANG=ru_RU.UTF-8
LANGUAGE=
LC_CTYPE="ru_RU.UTF-8"
LC_NUMERIC="ru_RU.UTF-8"
...
What is the right way to get system locale from PHP script?
Overall purpose: In the request I accept a file path, which can contain cyrillic symbols. Then I need to access files in this directory. So I want to make my php script work with systems which use different locales (e.g. ru_Utf8, Koi8-r).
Upvotes: 0
Views: 475
Reputation: 1058
One method to get the true system locale from PHP:
1) create a .sh script containing the locale
command (and of course the #!/bin/bash
header)
2) Add to /etc/sudoers www-data ALL=NOPASSWD: /path/to/locale.sh
with the sh script you just created
3) Update your PHP shell_exec
to $out = shell_exec('sudo /bin/bash /path/to/locale.sh')
This would allow locale to execute as root, without requiring a password.
Upvotes: 1