Search code examples
phpdebianlocalesetlocale

php setLocale fails, but that locale is installed on my server


I have these 3 locales installed and generated in my debian VPS

enter image description here

Generating locales is doing this

enter image description here

About webserver, I am using Apache with php-fpm

In my code i do this

echo "\n<!-- locale:\n" ;
var_dump($locale);
echo "  -->\n";
putenv("LC_ALL=$locale");

$_dbg_set_locale = setlocale(LC_ALL, $locale);
echo "\n<!-- esit setLocale:\n" ;
var_dump($_dbg_set_locale);
echo "  -->\n";

And I got that result

<!-- locale:
string(5) "en_GB"
  -->

<!-- esit setLocale:
bool(false)
  -->

As you can see setLocale is failing, returning a boolean false

why setLocale is faling?


Solution

  • As suggested in comments, I was simply missing to restart services.

    To be precise: because I'm using apache with php-fpm, I must restart ONLY php-fpm because all is related only to php-fpm

    Important side note: if you, future googler, are using apache with mod-php, I'm pretty sure this is not enough. Other questions/answers points to need to change something into apache configs and then restart apache2 (of course because there is not php-fpm at all)