Skip to content

Instantly share code, notes, and snippets.

@siffash
Forked from aminin/icu-install.sh
Last active December 6, 2023 13:30
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save siffash/76676186de0ffc6eb6cbf89abc7a5e2f to your computer and use it in GitHub Desktop.
Save siffash/76676186de0ffc6eb6cbf89abc7a5e2f to your computer and use it in GitHub Desktop.
Install ICU from source and build php-intl with the specific version of ICU
#!/usr/bin/env bash
if [[ -x $(which php) ]]; then
PHP_ICU_VERSION=$(php -r 'echo defined("INTL_ICU_VERSION") ? INTL_ICU_VERSION : "none";')
echo "PHP ICU version: $PHP_ICU_VERSION"
else
echo 'WARNING: PHP not installed'
PHP_ICU_VERSION=none
fi
if [[ -x $(which icuinfo) ]]; then
echo System ICU version: $(icuinfo | grep -o '"version">[^<]\+' | grep -o '[^"><]\+$')
else
echo 'System ICU not installed'
fi
if [[ "$1" == '' ]]; then
echo ''
echo 'Usage:'
echo ''
echo '1) bash icu-install.sh versions'
echo ''
echo '2) bash icu-install.sh install <version>'
fi
if [[ "$1" == 'versions' ]]; then
echo ''
echo 'Available ICU versions'
wget -O - http://download.icu-project.org/files/icu4c/ 2>/dev/null | grep -P -o '(?<=<span class="name">)[\d\.]+'
fi
if [[ "$2" != "" && "$1" == 'install' ]]; then
which g++ || sudo apt-get install g++
which phpize || (echo 'You are to install phpize' && exit 1)
if [[ "$PHP_ICU_VERSION" != 'none' ]]; then
echo 'Remove your old php-intl before installing a new one'
exit 1
fi
ICU_VERSION=$2
ICU_SRC_FILE="icu4c-$(echo $ICU_VERSION | sed -e 's/\./_/')-src.tgz"
echo "Trying to install ICU version: $ICU_VERSION"
if [[ ! -e "$ICU_SRC_FILE" ]]; then
wget "https://sourceforge.net/projects/icu/files/ICU4C/$ICU_VERSION/$ICU_SRC_FILE"
fi
if [[ ! -e "$ICU_SRC_FILE" ]]; then
exit 1;
fi
test -d icu/source || tar zxvf "$ICU_SRC_FILE"
which g++ || sudo apt-get install g++
if [[ ! -e "/opt/icu$ICU_VERSION" ]]; then
pushd icu/source
sudo mkdir "/opt/icu$ICU_VERSION"
./configure --prefix="/opt/icu$ICU_VERSION" && make && sudo make install
popd
else
echo "ICU already installed at (/opt/icu$ICU_VERSION)"
fi
# Install PHP extension
test -d build-intl || mkdir build-intl
pushd build-intl
PHP_VERSION=$(php -r 'echo preg_replace("~-.*$~", "", phpversion());')
export CXXFLAGS=$(/opt/icu${ICU_VERSION}/bin/icu-config --cxxflags)
# Download the code
ls -la
test -d php-src || git clone https://github.com/php/php-src.git
cd php-src/
git checkout "php-$PHP_VERSION" # put your version from php -v
# Configure & compile the extension
cd ext/intl
phpize
./configure --with-php-config=/usr/bin/php-config --with-icu-dir="/opt/icu$ICU_VERSION"
make CXXFLAGS=$CXXFLAGS
# Install the extension
sudo make install
PHP_INI_SCAN_DIR=$(php -r 'phpinfo();' | grep 'Scan this dir' | grep -o '/.\+')
if [[ -d "$PHP_INI_SCAN_DIR" ]]; then
pushd "$PHP_INI_SCAN_DIR"
test -e ../../mods-available/intl.ini && sudo ln -s ../../mods-available/intl.ini 20-intl.ini
popd
else
esle 'You are to add intl extension in your php.ini'
fi
# Clean the mess
popd;
rm -fr build-intl icu
rm -f "$ICU_SRC_FILE"
fi
@andrea-daru
Copy link

saved me from a day spent compiling php-intl... very useful!

@yamilramilev
Copy link

yamilramilev commented Apr 10, 2018

Centos 7 && PHP 7.2.4 && ICU 61.1 не работает

@avoropaev
Copy link

I also needed to change the environment variable
LD_LIBRARY_PATH=/opt/icu[[ICU_VERSION]]/lib
http://php.net/manual/ru/intl.installation.php

@siffash
Copy link
Author

siffash commented Feb 13, 2019

Centos 7 && PHP 7.2.4 && ICU 61.1 не работает

Проверялось только в Ubuntu 16.04.

@freeradicalx
Copy link

Getting this error on Ubuntu 16.04 when running ./icu-install.sh install 63.1:

./configure: line 4051: syntax error near unexpected token `ICU,'
./configure: line 4051: ` PKG_CHECK_MODULES(ICU, icu-io >= 50.1)'
make: *** No targets specified and no makefile found. Stop.
make: *** No rule to make target 'install'. Stop.

@redragon
Copy link

Centos 7 && PHP 7.2.4 && ICU 61.1 не работает

sudo yum install centos-release-scl
sudo yum install devtoolset-7
scl enable devtoolset-7 bash

@stevechilds
Copy link

stevechilds commented Sep 30, 2020

wget -O - http://download.icu-project.org/files/icu4c/ 2>/dev/null | grep -P -o '(?<=<span class="name">)[\d\.]+'

This appears not to work any longer, is it because the page has changed its layout?

When i run /tmp/icu-install/icu-install.sh versions nothing is returned

But I can run the command to install a version, however on Ubuntu 20 it fails to compile php.

HEAD is now at 1bc56dbdba Update versions for PHP 7.4.3                                                                                                                                                            
Configuring for:                                                                                                                                                                                                   
PHP Api Version:         20190902                                                                                                                                                                                  
Zend Module Api No:      20190902                                                                                                                                                                                  
Zend Extension Api No:   320190902                                                                                                                                                                                 
configure: WARNING: unrecognized options: --with-icu-dir 
.
.
.
checking whether to enable internationalization support... yes, shared                                                                                                                                             
checking for icu-uc >= 50.1 icu-io icu-i18n... no                                                                                                                                                                  
configure: error: Package requirements (icu-uc >= 50.1 icu-io icu-i18n) were not met:                                                                                                                              
                                                                                                                                                                                                                   
No package 'icu-uc' found                                                                                                                                                                                          
No package 'icu-io' found                                                                                                                                                                                          
No package 'icu-i18n' found                                                                                                                                                                                        

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables ICU_CFLAGS
and ICU_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
make: *** No targets specified and no makefile found.  Stop.
make: *** No rule to make target 'install'.  Stop.

@nidgetgod
Copy link

After some study, I finally got it work icu-install.sh

It only tested on PHP 7.4, if anyone tested on PHP 8.0 or above please let me know the result. Thanks.

@PallyTekoom
Copy link

It works on php 8.1

For ubuntu: apt install php-intl

https://www.php.net/manual/en/intl.installation.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment