We may earn a referral fee at no additional cost to you when you shop through the links on this page.
You deploy a PHP app to a fresh Ubuntu server, call setlocale(LC_TIME, 'fr_FR.UTF-8') to get French dates, and nothing changes, or the call returns false. The locale simply is not installed on the box. This DevAnswers guide fixes that by generating the missing system locale, then shows the modern way to format localized dates now that strftime() is deprecated.
Why setlocale() Returns false
setlocale() does not carry its own language data. It hands the request to the operating system’s C library, which can only honor a locale that has actually been generated on that machine. Minimal server images, including most Ubuntu and Debian cloud images, ship with little more than English and the C locale to save space; the rest are templates you build on demand. Ask for one that is not present and setlocale() quietly returns false, leaving your dates stuck in English with no error of its own, which is exactly what makes this bug so confusing to track down at first.
// Returns false when fr_FR is not generated on the server
var_dump( setlocale(LC_TIME, 'fr_FR.UTF-8') );
bool(false)
To actually see the deprecation and locale warnings while you debug, it helps to turn on PHP error display on your development machine.
Check Which Locales Are Installed
Before generating anything, list what the server already has. Connect over SSH and run locale -a, which prints every locale currently available on the system:
locale -a
C
C.utf8
en_US.utf8
POSIX
If the locale you need, say fr_FR.utf8, is missing from that list, that is the whole problem. Mind the spelling: the system prints it as fr_FR.utf8, while PHP also accepts the fr_FR.UTF-8 form. The language and country part must match a generated entry exactly, or setlocale() will keep failing.
Generate the Missing Locale
The most portable way to generate a locale is localedef, the low-level glibc tool that the higher-level helpers wrap. A single command builds the locale the same way on both Debian and Ubuntu:
sudo localedef -i fr_FR -f UTF-8 fr_FR.UTF-8
locale -a | grep fr_FR
fr_FR.utf8
Most distributions also ship higher-level wrappers, but they behave differently, which is what trips people up. On Debian, add the locale to /etc/locale.gen and run sudo locale-gen. On Ubuntu, pass it straight to sudo locale-gen fr_FR.UTF-8 instead, because Ubuntu’s locale-gen accepts the locale as an argument while Debian’s reads only the file (append plus a bare locale-gen will silently do nothing on Ubuntu). The interactive sudo dpkg-reconfigure locales works on both. Because of that split, the localedef command above is the most reliable choice in a script.
Confirm setlocale() Works
Run locale -a again and fr_FR.utf8 should now appear. Confirm it from PHP, this time expecting the locale name back instead of false:
var_dump( setlocale(LC_TIME, 'fr_FR.UTF-8') );
string(11) "fr_FR.UTF-8"
A returned string means the locale is active. Two things still trip people up at this stage:
- Generated while PHP was running. A long-lived process will not see a brand-new locale until it restarts, so restart PHP-FPM (or Apache) after generating the locale.
- Multithreaded servers. On a multithreaded SAPI, the process-wide locale can change mid-request because another thread called
setlocale(); set it explicitly where it matters rather than assuming it stays put.
strftime() Is Deprecated: Use IntlDateFormatter
With the locale fixed, resist the urge to print the date with strftime(). It and gmstrftime() were deprecated in PHP 8.1 and are slated for removal, and the manual now points you to date() and IntlDateFormatter::format(). For translated month and weekday names, IntlDateFormatter is the right tool. It belongs to the intl extension, so confirm ext-intl is enabled, then format the date directly:
$fmt = new IntlDateFormatter('fr_FR', IntlDateFormatter::FULL, IntlDateFormatter::NONE);
echo $fmt->format(new DateTime('2026-02-21'));
samedi 21 février 2026
The constructor arguments set the locale and how much of the date and time to show: IntlDateFormatter::FULL for the date, and IntlDateFormatter::NONE to drop the time. A neat bonus is that IntlDateFormatter uses ICU’s own bundled locale data, so it does not even depend on the system locale you just generated, which makes localized output far more portable across servers. When you only need a plain numeric date, reach for the simpler date() format characters instead, and save IntlDateFormatter for language-dependent output.
Still Not Working?
If setlocale() still returns false after generating the locale, run through these:
- Managed or shared hosting. You often cannot run
localedeforlocale-genwithout root. Ask the host to add the locale, or sidestep the system locale entirely by usingIntlDateFormatter, which carries its own data. - An LC_ALL override. When you rely on environment defaults with
setlocale(LC_TIME, ''), anLC_ALLset in the environment wins overLC_TIME(an explicitsetlocale(LC_TIME, 'fr_FR.UTF-8')argument is not affected). Check the environment withlocaleand unsetLC_ALLif it is forcing the wrong locale. - Name mismatch.
fr_FRalone is not a full locale; pass the fullfr_FR.UTF-8(or the exactfr_FR.utf8thatlocale -areports). - Wrong default for Intl.
IntlDateFormatterignoressetlocale(); set its locale in the constructor, or globally via theintl.default_localedirective inphp.ini.
Summary
A false from setlocale() almost always means the locale is missing from the operating system, not that your code is wrong. From here you have two clean paths. To keep existing setlocale()-based code working, generate the locale with localedef (or your distro’s locale-gen/dpkg-reconfigure), match the name exactly, and restart PHP-FPM. The more future-proof path is to move off the deprecated strftime() to IntlDateFormatter, which carries its own locale data and needs no system locale at all. Either way, keep your PHP output encoding on UTF-8 so those accented month names actually render.
Comments