Skip to content

Instantly share code, notes, and snippets.

@nidgetgod
Forked from siffash/icu-install.sh
Last active June 27, 2024 07:40
Show Gist options
  • Save nidgetgod/259903c46fbc5ea67fc0f0148df09c81 to your computer and use it in GitHub Desktop.
Save nidgetgod/259903c46fbc5ea67fc0f0148df09c81 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 - "https://github.com/unicode-org/icu/releases?q=Unicode%C2%AE%20ICU" 2>/dev/null | grep -oP '(?<=hl">ICU</mark> )[\d\.]+(?=</a>)'
fi
if [[ "$2" != "" && "$1" == 'install' ]]; then
which g++ || sudo apt-get install g++ -y
which phpize || (echo 'You have 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=$(echo $2 | sed -e 's/\./\-/')
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 -q "https://github.com/unicode-org/icu/releases/download/release-$ICU_VERSION/$ICU_SRC_FILE"
fi
if [[ ! -e "$ICU_SRC_FILE" ]]; then
exit 1;
fi
test -d icu/source || tar zxvf "$ICU_SRC_FILE"
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)
export ICU_CFLAGS=$(/opt/icu$ICU_VERSION/bin/icu-config --cppflags-searchpath)
export ICU_LIBS=$(/opt/icu$ICU_VERSION/bin/icu-config --ldflags --ldflags-icuio)
# 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
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 have to add intl extension in your php.ini'
fi
# Clean the mess
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