Skip to content

Instantly share code, notes, and snippets.

@belgattitude
Last active February 17, 2019 17:24
Show Gist options
  • Save belgattitude/999aee8eb6bd73fd0a7367ad896c76c3 to your computer and use it in GitHub Desktop.
Save belgattitude/999aee8eb6bd73fd0a7367ad896c76c3 to your computer and use it in GitHub Desktop.
Install libxl, php_excel extension on PHP7.1 (ondrej/ppa)
#!/bin/bash
#
# ilia/php_excel extension example install script for PHP7+
#
# usage:
# > sudo ./install_phpexcel_php7.sh
# > (optionally) sudo service php7.1-fpm restart)
#
# requirements:
# - Ubuntu 64bits (trusty/xenial)
# - sudo access
# - php7.1 from ondrej/php ppa
# - unzip, wget
#
# PHP7.1 install example :
# > sudo add-apt-repository -y ppa:ondrej/php;
# > sudo apt-get update;
# > sudo apt-get install php7.1 php7.1-dev php7.1-cli php7.1-xml php7.1-fpm php7.1-opcache php7.1-common
#
# (optionally)
# php7.1-bcmath php7.1-mbstring
# php7.1-pgsql php7.1-soap php7.1-zip php7.1-json php7.1-mysql php7.1-bz2 php7.1-curl
# php7.1-gmp php7.1-ldap php7.1-mcrypt php7.1-readline php7.1-sqlite3
# php7.1-gd php7.1-intl php7.1-xmlrpc
# php-imagick php-memcached
#
# @author Vanvelthem Sébastien
# @homepage https://github.com/belgattitude
#
TMP_DIR=/tmp
# Params for php extension php-excel
# 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$PHP_VERSION`
PHPIZE=`which phpize$PHP_VERSION`
PHP_MODS_AVAILABLE_PATH=/etc/php/$PHP_VERSION/mods-available
PHPENMOD="phpenmod -v $PHP_VERSION"
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=excel.so in your php.ini"
}
register_php_extension() {
echo "Registering available extension in $PHP_MODS_AVAILABLE_PATH/excel.ini"
echo "extension=excel.so" > $TMP_DIR/excel.ini
sudo cp $TMP_DIR/excel.ini $PHP_MODS_AVAILABLE_PATH/excel.ini
cmd="sudo $PHPENMOD excel"
echo "Activating: $cmd";
eval $cmd;
}
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 service php$PHP_VERSION-fpm restart";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment