Created
June 25, 2018 04:17
-
-
Save sintret/b3b05a9ea2fbc5446386265d2914743b to your computer and use it in GitHub Desktop.
Compile libxl library to linux centos with php 7.1
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
#!/bin/bash | |
# | |
# ilia/php_excel extension example install script for PHP7+ on CentOS 7+ as base interpreatator | |
# | |
# For installation php nginx and mysql see at https://www.hostinger.com/tutorials/how-to-install-lemp-centos7 | |
# | |
# usage: | |
# > yum install epel-release -y | |
# > (optionally) sudo service php7.0-fpm restart) | |
# | |
# requirements: | |
# - yum install php-devel, gcc, unzip, wget | |
# | |
# | |
# PHP7 install example with Ubuntu/Debian: | |
# > sudo add-apt-repository -y ppa:ondrej/php; | |
# > sudo apt-get update; | |
# > sudo apt-get install php-devel php-cli php-xml php-fpm php-opcache php-common | |
# | |
# (optionally) | |
# php7.0-bcmath php7.0-mbstring | |
# php7.0-pgsql php7.0-soap php7.0-zip php7.0-json php7.0-mysql php7.0-bz2 php7.0-curl | |
# php7.0-gmp php7.0-ldap php7.0-mcrypt php7.0-readline php7.0-sqlite3 | |
# php7.0-gd php7.0-intl php7.0-xmlrpc | |
# php-imagick php-memcached | |
# | |
TMP_DIR=/tmp | |
# Release 1.0.2 contains a bug regarding license | |
# see https://github.com/iliaal/php_excel/issues/163 | |
# So we use the master branch instead | |
# Once the release 1.0.3 is available, uncomment the two | |
# following lines and comment the master ones | |
#PHP_EXCEL_URL=https://github.com/iliaal/php_excel/archive/Excel-1.0.2-PHP7.zip | |
#PHP_EXCEL_ARCHIVE_DIR=php_excel-Excel-1.0.2-PHP7 | |
PHP_EXCEL_URL=https://github.com/iliaal/php_excel/archive/php7.zip | |
PHP_EXCEL_ARCHIVE_DIR=php_excel-php7 | |
# LibXL params | |
LIBXL_VERSION=3.8.2 | |
LIBXL_ARCHIVE_VERSION=3.8.2.0 | |
LIBXL_INSTALL_PATH="/opt/libxl-$LIBXL_VERSION" | |
LIBXL_URL="http://www.libxl.com/download" | |
LIBXL_ARCHIVE="libxl-lin-$LIBXL_VERSION.tar.gz" | |
# PHP params | |
PHP_VERSION=7.1 | |
PHP_CONFIG=`which php-config` | |
PHPIZE=`which phpize` | |
PHP_MODS_AVAILABLE_PATH=/etc/php.d | |
set -e | |
install_libxl() { | |
echo "Installing LIBXL v$LIBXL_VERSION" | |
wget -O $TMP_DIR/$LIBXL_ARCHIVE $LIBXL_URL/$LIBXL_ARCHIVE | |
tar zxvf $TMP_DIR/$LIBXL_ARCHIVE --directory $TMP_DIR | |
sudo mkdir -p $LIBXL_INSTALL_PATH | |
sudo cp -r $TMP_DIR/libxl-$LIBXL_ARCHIVE_VERSION/* $LIBXL_INSTALL_PATH | |
} | |
install_phpexcel_extension() { | |
echo "Download and compling PHP_EXCEL extension for libxl" | |
wget -O $TMP_DIR/php_excel.zip $PHP_EXCEL_URL | |
if [ -d $TMP_DIR/$PHP_EXCEL_ARCHIVE_DIR ]; then | |
# REMOVE eventual previous buils | |
rm -r $TMP_DIR/$PHP_EXCEL_ARCHIVE_DIR/* | |
fi | |
unzip -o $TMP_DIR/php_excel.zip -d $TMP_DIR | |
cd $TMP_DIR/$PHP_EXCEL_ARCHIVE_DIR/ | |
eval "$PHPIZE" | |
./configure --with-php-config=$PHP_CONFIG --with-libxl-incdir=$LIBXL_INSTALL_PATH/include_c/ --with-libxl-libdir=$LIBXL_INSTALL_PATH/lib64/ --with-excel=$LIBXL_INSTALL_PATH | |
make | |
#make test | |
echo "Installing php extension (need sudo)" | |
sudo make install | |
echo "Install succeed, please add extension=20-excel.ini in your php.ini" | |
} | |
register_php_extension() { | |
echo "Registering available extension in $PHP_MODS_AVAILABLE_PATH/20-excel.ini" | |
echo "extension=excel.so" > $TMP_DIR/excel.ini | |
sudo cp $TMP_DIR/excel.ini $PHP_MODS_AVAILABLE_PATH/20-excel.ini | |
} | |
install_libxl; | |
install_phpexcel_extension; | |
register_php_extension; | |
echo "Install successfull" | |
echo "Optionally you can restart your fpm daemon" | |
echo "to reflect changes:" | |
echo " sudo systemctl restart php-fpm"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment