Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install script for ilia/php_excel with PHP7.3
#!/bin/bash
#
# Example script to install LibXL, ilia/php_excel on PHP 7.3 (ondrej/ppa)
#
# Usage:
# > sudo ./install_phpexcel_php73.sh
# > sudo service php7.3-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.3 from ondrej/ppa
#
# Example install for PHP7.3 with ondrej ppa :
# > sudo add-apt-repository -y ppa:ondrej/php;
# > sudo apt-get update;
# > sudo apt-get install php7.3 php7.3-dev php7.3-cli php7.3-xml php7.3-common php7.3-json
#
# (optionally)
# php7.3-fpm php7.3-opcache
# php7.3-mbstring php7.3-bcmath php7.3-zip php7.3-bz2 php7.3-curl
# php7.3-gd php7.3-intl php7.3-xmlrpc php7.3-soap
# php7.3-sqlite3 php7.3-pgsql php7.3-mysql
# php7.3-gmp php7.3-ldap php7.3-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.3
# > 3.8.2 requires the use of jan-e fork, see below
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
# THIS FORK CONTAINS UPDATED VERSION
#PHP_EXCEL_URL=https://github.com/Jan-E/php_excel/archive/php7_with_pulls.zip
#PHP_EXCEL_ARCHIVE_DIR=php_excel-php7_with_pulls
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