Skip to content

Instantly share code, notes, and snippets.

@cyber01

cyber01/icu-install.sh

Forked from aminin/icu-install.sh
Last active Oct 1, 2018
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
PHP_BIN='php70' # CentOS 7 PHP из Remi, укажите соответствующий файл, получить его можно через which php
PHPIZE_BIN_PATH='/opt/remi/php70/root/bin/phpize' # CentOS 7 PHP из Remi, укажите соответствующий файл, получить его можно через which phpize
COMPILER_PACKAGE_INSTALL_COMMAND='yum install gcc-c++ php71-php-devel' # CentOS 7 PHP из Remi, для Debian/Ubuntu это apt-get install g++
PHPCONFIG_BIN_PATH='/opt/remi/php70/root/bin/php-config' # CentOS 7 PHP из Remi, укажите соответствующий файл, получить его можно через which php-config
if [[ -x $(which $PHP_BIN) ]]; then
PHP_ICU_VERSION=$($PHP_BIN -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 $COMPILER_PACKAGE_INSTALL_COMMAND
which $PHPIZE_BIN_PATH || (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 "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 $COMPILER_PACKAGE_INSTALL_COMMAND
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_BIN -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_BIN_PATH
./configure --with-php-config=$PHPCONFIG_BIN_PATH --with-icu-dir="/opt/icu$ICU_VERSION"
make CXXFLAGS=$CXXFLAGS
# Устанавливаем расширение
sudo make install
PHP_INI_SCAN_DIR=$($PHP_BIN -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 icu
rm -f "$ICU_SRC_FILE"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment