Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save 13i/b4ebaba9a402f1f2f3d7c6d64183edaa to your computer and use it in GitHub Desktop.
Save 13i/b4ebaba9a402f1f2f3d7c6d64183edaa to your computer and use it in GitHub Desktop.
Install libxl/php_excel for PHP5.6 (ondrej/php ppa)
#!/bin/bash
#
# ilia/php_excel extension example install script
#
# usage:
# > sudo ./install_phpexcel_php5.6.sh
# > (optionally) sudo service php5.6-fpm restart
#
# requirements:
# - Ubuntu 64bits (trusty/xenial)
# - php5.6 from ondrej/php ppa
# - unzip, wget
# - sudo access
#
# PHP install example :
# > sudo add-apt-repository -y ppa:ondrej/php;
# > sudo apt-get update;
# > sudo apt-get install php5.6 php5.6-fpm php5.6-dev php5.6-common php5.6-xml
# (optionally)
# php5.6-bcmath php5.6-mbstring \
# php5.6-pgsql php5.6-soap php5.6-zip php5.6-json php5.6-mysql \
# php5.6-bz2 php5.6-curl php5.6-gmp php5.6-ldap \
# php5.6-mcrypt php5.6-readline php5.6-sqlite3 php5.6-gd php5.6-intl \
# php5.6-xmlrpc php5.6-opcache
#
TMP_DIR=/tmp
# 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=5.6
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"
# php_excel params
#PHP_EXCEL_URL=https://github.com/iliaal/php_excel/archive/Excel-1.0.2-PHP5.zip
#PHP_EXCEL_ARCHIVE_DIR=php_excel-Excel-1.0.2-PHP5
# Jan-E forked repository
PHP_EXCEL_URL=https://github.com/Jan-E/php_excel/archive/php5_with_pulls.zip
PHP_EXCEL_ARCHIVE_DIR=php_excel-php5_with_pulls
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