1

I know there are many questions about locale issues in PHP. But I can't find any similar question or answer. I need to output German month names on a website. German locale is installed. Here is the output of locale -a:

# locale -a
C
C.UTF-8
POSIX
de_DE
de_DE.iso88591
de_DE.iso885915@euro
de_DE.utf8
de_DE@euro
deutsch
en_US.utf8
german

Now I just use a little test snippet:

<?php
echo setlocale(LC_ALL, 'de_DE.utf8')."\n";
echo strftime('%B %Y', strtotime('2022-03-20'))."\n";

Here is the correct output from executing it on the command line:

# php test.php
de_DE.utf8
März 2022

Now when I execute the same snippet on the same server with a web browser (file:///x.php) the correct locale will be loaded, but the output is in English:

de_DE.utf8
March 2022

Apache 2.4.38 is used as the web server. The php cli version is 7.2.34 and the php module on apache is php7_module (shared). There must be a difference between the php cli and php apache modules, but I don't know the solution?

Thanks for help!

Gunnar Gläser
  • 337
  • 5
  • 13
  • From [another question](https://stackoverflow.com/a/70312801/1685196): try setting multiple names. Perhaps cli and module use different names for the same locale? – Michel Apr 13 '22 at 12:21
  • Thanks, yes i tried also `de_DE`, `de_DE.UTF-8`, `de_DE.iso88591`. Always the same problem? – Gunnar Gläser Apr 13 '22 at 12:31

1 Answers1

0

I found the solution. The problem was solved after disabling the Perl module with a2dismod perl. After this the website shows also the correct date format.

Luuk
  • 12,245
  • 5
  • 22
  • 33
Gunnar Gläser
  • 337
  • 5
  • 13
  • 1
    [Difference between executing PHP code from the commandline and from the HTTP side](https://stackoverflow.com/questions/3016281/difference-between-executing-php-code-from-the-commandline-and-from-the-http-sid). Check the difference for this: [php_ini_loaded_file](https://www.php.net/manual/en/function.php-ini-loaded-file.php) – Luuk Jan 21 '23 at 12:04
  • Thanks for your hint. I just compared the cli and apache php.ini version and I don't find a difference that causes this problem. – Gunnar Gläser Jan 21 '23 at 15:09