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 -a
Example output of the command is shown below.
CC.UTF-8en_US.utf8fr_BE.utf8fr_CA.utf8fr_FR.utf8nl_BE.utf8nl_NL.utf8POSIX
List 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-de
If 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.4-fpm-sp restart
sudo service php8.3-fpm-sp restart
sudo service php8.2-fpm-sp restart
sudo service php8.1-fpm-sp restart
sudo service php8.0-fpm-sp restart
sudo service php7.4-fpm-sp restart
sudo service php7.3-fpm-sp restart
sudo service php7.2-fpm-sp restart
sudo service php7.1-fpm-sp restart
sudo service php7.0-fpm-sp restart
sudo service php5.6-fpm-sp restart
Change 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=POSIX
There are many environment variables that control different aspects of locale settings. Learn more about changing a server’s locale.