Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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 -o 'href=.[^/"]\+' | grep -o '".\+' | grep -o '[^"]\+'
fi
if [[ "$2" != "" && "$1" == 'install' ]]; then
which g++ || sudo apt-get install g++
if [[ $(which phpize) == "" ]]; then
echo 'You are to install phpize'
exit 1
fi
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 "http://download.icu-project.org/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
# Устанавливаем расширение PHP
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)
# Скачиваем код
ls -la
test -d php-src || git clone https://github.com/php/php-src.git
cd php-src/
git checkout "php-$PHP_VERSION" # подставьте свою версию из php -v
# Настраиваем и компилируем расширение
cd ext/intl
phpize
CPPFLAGS+=' -DU_USING_ICU_NAMESPACE=1' ./configure --with-php-config=/usr/bin/php-config --with-icu-dir="/opt/icu$ICU_VERSION"
make CXXFLAGS=$CXXFLAGS
# Устанавливаем расширение
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
# Убираем за собой
popd;
rm -fr build-intl
fi
@siffash

This comment has been minimized.

Copy link

@siffash siffash commented Feb 8, 2018

Тёска, спасибо за код, пробую инсталлировать, пишет:
icu-install.sh: line 66: /opt/60.2/bin/icu-config: No such file or directory
Допиши в 66-й строке "icu" перед ${ICU_VERSION}

@siffash

This comment has been minimized.

Copy link

@siffash siffash commented Feb 9, 2018

В 77-й строке должно быть:
make CXXFLAGS=$CXXFLAGS
иначе при установке новых версий ICU сыпятся ошибки

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