PHP setlocale / strftime output differs between cli and web

85 views Asked by At

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!

1

There are 1 answers

2
Gunnar Gläser On BEST ANSWER

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.