Install locales and change a server's locale
A server’s locale settings determine the language used in the output of some programs.
Installing additional locales enables the use of PHP’s
setlocale()
function so other functions such as
localeconv() will
return text formatted for a specific language or region.
List installed locales
To list a server’s installed locales, SSH into the server and run the following command.
locale -aExample output of the command is shown below.
CC.UTF-8en_US.utf8fr_BE.utf8fr_CA.utf8fr_FR.utf8nl_BE.utf8nl_NL.utf8POSIXList available locales
List all locales that are available for installation.
apt-cache search language-pack- | grep -v -E -- '-kde|-base|-gnome'Install a locale
Locales can be installed through the server’s package manager. For example:
sudo apt-get install language-pack-deIf you installed a locale for use in a PHP app, restart the PHP version the app is using after installing a new locales.
sudo service php8.5-fpm-sp restartsudo service php8.4-fpm-sp restartsudo service php8.3-fpm-sp restartsudo service php8.2-fpm-sp restartsudo service php8.1-fpm-sp restartsudo service php8.0-fpm-sp restartsudo service php7.4-fpm-sp restartsudo service php7.3-fpm-sp restartsudo service php7.2-fpm-sp restartsudo service php7.1-fpm-sp restartsudo service php7.0-fpm-sp restartsudo service php5.6-fpm-sp restartChange the server’s locale
Use the update-locale command to change the server’s default locale.
For example:
sudo update-locale LANG=de_DE.UTF-8 LC_MESSAGES=POSIXThere are many environment variables that control different aspects of locale settings. Learn more about changing a server’s locale.