In my last post I discussed the problem of transliteration, and how it can be implemented using PHP’s Intl extension, which is a wrapper for ICU library. Each release of the library supports more scripts, language pairs and transliteration standards, that’s why it’s so vital to use the latest version.
Now let’s check the version of ICU our PHP 7 currently uses. Run:
Scroll down to the list of installed PHP modules and find intl:
Internationalization support => enabled
version => 1.1.0
ICU version => 55.1
ICU Data version => 55.1
Now it’s time to cry your eyes out! 55.1 was released on 2015-04-01. Since then 5 new versions have been released. 55.1 has 286 possible language parameters, while 60.2 has 639 – it increased by more than twice! Let’s upgrade!
To be honest, it wasn’t an easy task whatsoever. You can spend your whole life trying to find out how to manually upgrade ICU in Intl for Linux. But I’m going to reveal the secret right away.
Basically all the magic came from a post in Sergey Stoyanov’s blog, where he describes the upgrading process to ICU v. 56.1 for PHP 5 in Ubuntu 14.04. If you want to upgrade to 60.2, and you have PHP 7 installed on Ubuntu 16.04, the process will differ drastically, but nevertheless Sergey’s solution was used as a basis. The comments to the post were highly useful and helped me as well.
So here are all the steps:
- Check the list of installed PHP modules, find intl, and find out its version (I bet it’s php7.0-intl):
sudo dpkg --get-selections | grep -v deinstall | grep php
- Remove intl (e.g. it’s php7.0-intl):
sudo apt-get remove php7.0-intl
- Install phpize:
sudo apt install php7.0-dev
- If you don’t have git, install it:
sudo apt install git
- Download icu-install.sh (it’s my fork of Anton Minin’s shell script):
git -C /tmp clone https://gist.github.com/siffash/76676186de0ffc6eb6cbf89abc7a5e2f icu-install
- Add execute permissions to the file:
sudo chmod +x /tmp/icu-install/icu-install.sh
- Run the file and check all available ICU releases:
sudo /tmp/icu-install/icu-install.sh versions
- Run the file and launch installation of ICU’s latest release:
sudo /tmp/icu-install/icu-install.sh install 60.2
- Once successfully completed, add 20-intl.ini:
sudo touch /etc/php/7.0/apache2/conf.d/20-intl.ini && sudo bash -c 'echo "extension=intl.so" > /etc/php/7.0/apache2/conf.d/20-intl.ini'
- Restart Apache:
- Remove phpize:
sudo apt-get purge --auto-remove php7.0-dev
- Remove icu-install:
rm -rf /tmp/icu-install
Now you can check the current ICU version by running:
I bet now it’s 60.2!
Check the list of parameters you have now available:
$list = transliterator_list_ids(); // get the list natcasesort ($list); // sort in an alphabetical order foreach ($list as $v) // iterate echo $v . "\n"; // print exit;