Last active
October 11, 2019 15:57
-
-
Save aminin/a26964ef88569645786299b0404deae6 to your computer and use it in GitHub Desktop.
Install ICU from source and build php-intl with the specific version of ICU
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
В 77-й строке должно быть:
make CXXFLAGS=$CXXFLAGS
иначе при установке новых версий ICU сыпятся ошибки
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Тёска, спасибо за код, пробую инсталлировать, пишет:
icu-install.sh: line 66: /opt/60.2/bin/icu-config: No such file or directory
Допиши в 66-й строке "icu" перед ${ICU_VERSION}