Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
#
# Example script to install LibXL, ilia/php_excel on PHP 7.2 (ondrej/ppa)
#
# Usage:
# > sudo ./install_phpexcel_php72.sh
# > sudo service php7.2-fpm reload (if using fpm)
#
# Requirements:
# - Tested with Ubuntu 64bits (14.04, 16.04+)
# - "sudo" access required for installing the extension.
# - "unzip", "wget" and "tar" commands (`sudo apt install unzip wget tar`)
# - Install based on php 7.2 from ondrej/ppa
#
# Example install for PHP7.2 with ondrej ppa :
# > sudo add-apt-repository -y ppa:ondrej/php;
# > sudo apt-get update;
# > sudo apt-get install php7.2 php7.2-dev php7.2-cli php7.2-xml php7.2-common php7.2-json
#
# (optionally)
# php7.2-fpm php7.2-opcache
# php7.2-mbstring php7.2-bcmath php7.2-zip php7.2-bz2 php7.2-curl
# php7.2-gd php7.2-intl php7.2-xmlrpc php7.2-soap
# php7.2-sqlite3 php7.2-pgsql php7.2-mysql
# php7.2-gmp php7.2-ldap php7.2-readline
# php-imagick php-memcached
#
# @author Vanvelthem Sébastien
# @homepage https://github.com/belgattitude
#
## SET the versions here (for PHP_VERSION, do not add 'patch' number)
PHP_VERSION=7.2
LIBXL_VERSION=3.8.2
LIBXL_INSTALL_PATH="/opt/libxl-$LIBXL_VERSION"
TMP_DIR=/tmp
set -e
# (SHOULD NOT BE EDITED)
LIBXL_ARCHIVE_VERSION=$LIBXL_VERSION.0
LIBXL_INSTALL_PATH="/opt/libxl-$LIBXL_VERSION"
LIBXL_URL="http://www.libxl.com/download"
LIBXL_ARCHIVE="libxl-lin-$LIBXL_VERSION.tar.gz"
# (SHOULD NOT BE EDITED)
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"
# (SHOULD NO BE EDITED)
# Release 1.0.2 contains a bug regarding license
# see https://github.com/iliaal/php_excel/issues/163
# So we use the master branch
PHP_EXCEL_URL=https://github.com/iliaal/php_excel/archive/php7.zip
PHP_EXCEL_ARCHIVE_DIR=php_excel-php7
install_libxl() {
echo "Download and install 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, configure and compile ilia/phpexcel extension"
echo " -> downloading"
wget -O $TMP_DIR/php_excel.zip $PHP_EXCEL_URL
if [ -d $TMP_DIR/$PHP_EXCEL_ARCHIVE_DIR ]; then
# REMOVE previous build if exists
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/
echo " -> configuring"
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
echo " -> compiling"
make
#make test -> Does not work without license anyway.
echo " -> compiling (needs sudo)"
sudo make install
echo "Install succeed"
}
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
You can’t perform that action at this time.