John Davidson

apache2 - Different locale in PHP-FPM vs PHP

0 comments
Message:


I'm struggling with an encoding problem switching from regular PHP to PHP-FPM. The php.ini's are the same. It seems as if php-fpm is picking up the locale settings from the user that the service is running.


PHP:


Code: $currentLocale = setlocale(LC_ALL, 0); echo $currentLocale;


Output: C


PHP-FPM:


Code: $currentLocale = setlocale(LC_ALL, 0); echo $currentLocale;


Output: LC_CTYPE=C.UTF-8;LC_NUMERIC=C;LC_TIME=C;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=C;LC_PAPER=C;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=C;LC_IDENTIFICATION=C


The goal is to get "C" in PHP-FPM, the same as in PHP (old application using utf8-encode). Ubuntu server with Apache2



My Answer:
One possible solution is to explicitly set the locale in your PHP-FPM configuration file. You can do this by adding the following line to your php-fpm.conf or www.conf file:


env[LC_ALL] = C


This will ensure that the locale is set to "C" for PHP-FPM, just like it is for regular PHP. Make sure to restart PHP-FPM after making this change for it to take effect.

Alternatively, you can also set the locale directly in your PHP script using the setlocale function:


setlocale(LC_ALL, 'C');


This will override any system or environment settings and force the locale to be set to "C" for your PHP-FPM script.

Rate this post

5 of 5 based on 9484 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us