Skip to content

Instantly share code, notes, and snippets.

@pentagonal
Last active March 17, 2019 19:47
Show Gist options
  • Save pentagonal/bae094b2a07d742b484b3f8c4f5df362 to your computer and use it in GitHub Desktop.
Save pentagonal/bae094b2a07d742b484b3f8c4f5df362 to your computer and use it in GitHub Desktop.
Php Lambda Binary (placed on : /opt/)
#!/bin/bash
# Binary Compilation Placed on
# /opt/
# Please Make Sure no /opt/bin/ or /opt/lambda/ directory
# CENTOS x64 only
########################################################
#### NOTE PLEASE RUN #####
#$ rpm -Uvh https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm
#
########################################################
# change to another PHP Version
# see @ https://github.com/php/php-src/releases
php='7.2.16'
imagemagick='7.0.8-27'
freetype='2.10.0'
# https://launchpad.net/libmemcached/+download
# https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz
awselasticcache='v2.0.3'
# https://github.com/awslabs/aws-elasticache-cluster-client-libmemcached/archive/v1.0.18.tar.gz
awslibmemcached='v1.0.18'
cmake='3.13.4'
libpng='1.6.36'
libjpeg='2.0.2'
libgd='2.2.5'
zlib='1.2.11'
openssl='1.0.2r'
libssh2='1.8.0'
curl='7.64.0'
libxml2='2.9.9'
libzip='1.5.1'
libsodium='1.0.17'
postgres='11.2'
libwebp='v1.0.2'
RELEASE='/etc/centos-release'
if [[ ! -f $RELEASE ]]; then
echo 'Looks like your OS is not centos'
exit 255;
fi
RELEASE=$(cat $RELEASE)
if [[ $RELEASE =~ ^(.+)release\ +7 ]];then
echo "Operating System: ${RELEASE}"
else
echo 'Looks like your centos is not supported yet'
exit 255;
fi
# https://nchc.dl.sourceforge.net/project/libpng/libpng16/1.6.36/libpng-1.6.36.tar.gz
# We need a base path for all the sourcecode we will build from.
BUILD_DIR="/tmp/build"
# We need a base path for the builds to install to. This path must
# match the path that bref will be unpackaged to in Lambda.
INSTALL_DIR="/opt/lambda"
# ##########################################
# EXPORT
# ##########################################
export PKG_CONFIG_PATH="${INSTALL_DIR}/lib64/pkgconfig:${INSTALL_DIR}/lib/pkgconfig"
export PKG_CONFIG="/usr/bin/pkg-config"
export PATH="${INSTALL_DIR}/bin:${PATH}"
export LD_LIBRARY_PATH="${INSTALL_DIR}/lib64:${INSTALL_DIR}/lib"
# cmake
# https://cmake.org/files/
VERSION_CMAKE=${cmake}
CMAKE_BUILD_DIR=${BUILD_DIR}/cmake
CMAKE_BUILD_BIN=/usr/local/bin/cmake
#zlib
# https://github.com/madler/zlib/releases
VERSION_ZLIB=${zlib}
ZLIB_BUILD_DIR=${BUILD_DIR}/zlib
# LIBPNG
# https://github.com/libgd/libgd/releases
VERSION_LIBPNG=${libpng}
LIBPNG_BUILD_DIR=${BUILD_DIR}/libpng
VERSION_LIBJPEG=${libjpeg}
LIBJPEG_BUILD_DIR=${BUILD_DIR}/libjpeg
# LIBWEBP
# https://github.com/webmproject/libwebp/release
VERSION_LIBWEBP=${libwebp}
LIBWEBP_BUILD_DIR=${BUILD_DIR}/libwebp
# libgd
# https://github.com/libgd/libgd/releases
VERSION_LIBGD=${libgd}
LIBGD_BUILD_DIR=${BUILD_DIR}/libgd
# openssl
# https://github.com/openssl/openssl/releases
VERSION_OPENSSL=${openssl}
OPENSSL_BUILD_DIR=${BUILD_DIR}/openssl
CA_BUNDLE_SOURCE="https://curl.haxx.se/ca/cacert.pem"
CA_BUNDLE="${INSTALL_DIR}/ssl/cert.pem"
# libssh2
# https://github.com/libssh2/libssh2/releases/
VERSION_LIBSSH2=${libssh2}
LIBSSH2_BUILD_DIR=${BUILD_DIR}/libssh2
# curl
# https://github.com/curl/curl/releases/
VERSION_CURL=${curl}
CURL_BUILD_DIR=${BUILD_DIR}/curl
# LIBXML2 Build
# https://github.com/GNOME/libxml2/releases
VERSION_XML2=${libxml2}
XML2_BUILD_DIR=${BUILD_DIR}/xml2
# LIBZIP Build
# https://github.com/nih-at/libzip/releases
VERSION_ZIP=${libzip}
ZIP_BUILD_DIR=${BUILD_DIR}/zip
# LIBSODIUM Build
# https://github.com/jedisct1/libsodium/releases
VERSION_LIBSODIUM=${libsodium}
LIBSODIUM_BUILD_DIR=${BUILD_DIR}/libsodium
# Postgres Build
# https://github.com/postgres/postgres/releases/
VERSION_POSTGRES=${postgres}
POSTGRES_BUILD_DIR=${BUILD_DIR}/postgres
# FREETYPE Build
# https://github.com/ImageMagick/ImageMagick/release
VERSION_FREETYPE=${freetype}
FREETYPE_BUILD_DIR=${BUILD_DIR}/freetype
# IMAGEMAGICK Build
# https://download.savannah.gnu.org/releases/freetype/
VERSION_IMAGEMAGICK=${imagemagick}
IMAGEMAGICK_BUILD_DIR=${BUILD_DIR}/imagemagick
# LIBMEMCACHED
LIBMEMCACHED_BUILD_DIR=${BUILD_DIR}/libmemcached
# AWS LIB MEMCACHED
VERSION_AWS_LIBMEMCACHED=${awslibmemcached}
AWS_LIBMEMCACHED_BUILD_DIR=${BUILD_DIR}/awslibmemcached
# AWS ELASTIC CACHE
VERSION_AWS_ELASTIC_CACHE=${awselasticcache}
AWS_ELASTIC_CACHE_BUILD_DIR=${BUILD_DIR}/awselasticcache
# PHP Build
# https://github.com/php/php-src/releases
VERSION_PHP=${php}
PHP_BUILD_DIR=${BUILD_DIR}/php
echo -e 'Creating Directories'
# Ensure we have all the directories we require in the container.
mkdir -p ${BUILD_DIR} \
${INSTALL_DIR}/aws/lib \
${INSTALL_DIR}/aws/include \
${INSTALL_DIR}/aws/share \
${INSTALL_DIR}/bin \
${INSTALL_DIR}/doc \
${INSTALL_DIR}/etc/php \
${INSTALL_DIR}/etc/php/conf.d \
${INSTALL_DIR}/include \
${INSTALL_DIR}/lib \
${INSTALL_DIR}/lib64 \
${INSTALL_DIR}/libexec \
${INSTALL_DIR}/sbin \
${INSTALL_DIR}/share
echo -e 'Adding Epel Repositories'
# Preparation
LD_LIBRARY_PATH= echo 'y' | sudo rpm -Uvh https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm
echo -e 'Installing Prerequiries Dependencies'
LD_LIBRARY_PATH= sudo yum -y install \
curl \
libtool \
bison \
gcc gcc-c++ \
zlib-devel bison \
automake \
autoconf \
readline-devel \
gettext-devel \
libicu-devel \
libcurl-devel \
libxml2-devel \
perl \
perl-devel \
openssl-devel \
libjpeg-turbo-devel \
nasm \
cyrus-sasl-devel
if [[ ! -f $CMAKE_BUILD_BIN ]]; then
echo -e "Downloading CMAKE ${VERSION_CMAKE}"
##########################################
# CMAKE
##########################################
mkdir -p ${CMAKE_BUILD_DIR}
# Download and upack the source code
curl -Ls https://cmake.org/files/LatestRelease/cmake-3.13.4.tar.gz \
| tar xzC ${CMAKE_BUILD_DIR} --strip-components=1
cd ${CMAKE_BUILD_DIR}
echo -e "Configure & Install CMAKE"
sudo make distclean
sudo ./bootstrap \
--prefix=/usr/local \
sudo make install
fi
##########################################
# LIBJPEG
##########################################
echo -e "Downloading LIBJPEG ${VERSION_LIBJPEG}"
mkdir -p ${LIBJPEG_BUILD_DIR}
# curl -Ls https://github.com/libjpeg-turbo/libjpeg-turbo/archive/${VERSION_LIBJPEG}.tar.gz \
# | tar xzC ${LIBJPEG_BUILD_DIR} --strip-components=1
cd ${LIBJPEG_BUILD_DIR}
echo -e "Configure & Install LIBJPEG"
make distclean
${CMAKE_BUILD_BIN} . \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} \
-DCMAKE_BUILD_TYPE=RELEASE
${CMAKE_BUILD_BIN} --build . --target install
# CFLAGS="" \
# CPPFLAGS="-I${INSTALL_DIR}/include -I/usr/include" \
# LDFLAGS="-L${INSTALL_DIR}/lib64 -L${INSTALL_DIR}/lib" \
# ./configure --prefix=${INSTALL_DIR}
# make install
##########################################
# LIBPNG
##########################################
echo -e "Downloading LIBPNG ${VERSION_LIBPNG}"
mkdir -p ${LIBPNG_BUILD_DIR}
curl -Ls https://nchc.dl.sourceforge.net/project/libpng/libpng16/${VERSION_LIBPNG}/libpng-${VERSION_LIBPNG}.tar.gz \
| tar xzC ${LIBPNG_BUILD_DIR} --strip-components=1
cd ${LIBPNG_BUILD_DIR}
echo -e "Configure & Install LIBPNG"
make distclean
CFLAGS="" \
CPPFLAGS="-I${INSTALL_DIR}/include -I/usr/include" \
LDFLAGS="-L${INSTALL_DIR}/lib64 -L${INSTALL_DIR}/lib" \
./configure --prefix=${INSTALL_DIR}
make install
##########################################
# LIBWEBP
##########################################
echo -e "Downloading LIBWEBP ${VERSION_LIBWEBP}"
#https://github.com/webmproject/libwebp/archive/v1.0.2.tar.gz
mkdir -p ${LIBWEBP_BUILD_DIR}
curl -Ls https://github.com/webmproject/libwebp/archive/${VERSION_LIBWEBP}.tar.gz \
| tar xzC ${LIBWEBP_BUILD_DIR} --strip-components=1
cd ${LIBWEBP_BUILD_DIR}/
echo -e "Configure & Install LIBWEBP"
make distclean
./autogen.sh
CFLAGS="" \
CPPFLAGS="-I${INSTALL_DIR}/include -I/usr/include" \
LDFLAGS="-L${INSTALL_DIR}/lib64 -L${INSTALL_DIR}/lib" \
./configure --prefix=${INSTALL_DIR}
make install
##########################################
# FREETYPE
##########################################
# https://download.savannah.gnu.org/releases/freetype/freetype-2.10.0.tar.gz
echo -e "Downloading FREETYPE ${VERSION_FREETYPE}"
mkdir -p ${FREETYPE_BUILD_DIR}
curl -Ls https://download.savannah.gnu.org/releases/freetype/freetype-${VERSION_FREETYPE}.tar.gz \
| tar xzC ${FREETYPE_BUILD_DIR} --strip-components=1
cd ${FREETYPE_BUILD_DIR}/
echo -e "Configure & Install FREETYPE"
make distclean
./autogen.sh
CFLAGS="" \
CPPFLAGS="-I${INSTALL_DIR}/include -I/usr/include" \
LDFLAGS="-L${INSTALL_DIR}/lib64 -L${INSTALL_DIR}/lib" \
./configure --prefix=${INSTALL_DIR} \
--enable-freetype-config
make install
##########################################
# LIBGD
##########################################
echo -e "Downloading LIBGD ${VERSION_LIBGD}"
#https://github.com/libgd/libgd/archive/gd-2.2.5.tar.gz
mkdir -p ${LIBGD_BUILD_DIR}
curl -Ls https://github.com/libgd/libgd/archive/gd-${VERSION_LIBGD}.tar.gz \
| tar xzC ${LIBGD_BUILD_DIR} --strip-components=1
cd ${LIBGD_BUILD_DIR}
echo -e "Configure & Install LIBGD"
make distclean
./bootstrap.sh
CFLAGS="" \
CPPFLAGS="-I${INSTALL_DIR}/include -I/usr/include" \
LDFLAGS="-L${INSTALL_DIR}/lib64 -L${INSTALL_DIR}/lib" \
./configure \
--prefix=${INSTALL_DIR} \
--with-png=${INSTALL_DIR} \
--with-jpeg=${INSTALL_DIR} \
--with-webp=${INSTALL_DIR} \
--with-freetype=${INSTALL_DIR} \
--without-xpm
make install
# cp -r $LIBGD_BUILD_DIR/include/X11 ${INSTALL_DIR}/include/
##########################################
# ZLIB
##########################################
echo -e "Downloading ZLIB ${VERSION_ZLIB}"
mkdir -p ${ZLIB_BUILD_DIR}
# Download and upack the source code
curl -Ls http://zlib.net/zlib-${VERSION_ZLIB}.tar.xz \
| tar xJC ${ZLIB_BUILD_DIR} --strip-components=1
# Move into the unpackaged code directory
cd ${ZLIB_BUILD_DIR}/
echo -e "Configure & Install ZLIB"
# Configure the build
make distclean
./autogen.sh
CFLAGS="" \
CPPFLAGS="-I${INSTALL_DIR}/include -I/usr/include" \
LDFLAGS="-L${INSTALL_DIR}/lib64 -L${INSTALL_DIR}/lib" \
# configure
./configure \
--prefix=${INSTALL_DIR} \
--64
# install
make install
# remove libz.a
rm ${INSTALL_DIR}/lib/libz.a
##########################################
# OPENSSL
##########################################
echo -e "Downloading OPENSSL ${VERSION_OPENSSL}"
mkdir -p ${OPENSSL_BUILD_DIR}
# Download and upack the source code
curl -Ls https://github.com/openssl/openssl/archive/OpenSSL_${VERSION_OPENSSL//./_}.tar.gz \
| tar xzC ${OPENSSL_BUILD_DIR} --strip-components=1
echo -e "Configure & Install OPENSSL"
cd ${OPENSSL_BUILD_DIR}/
make distclean
# Configure the build
export CFLAGS="" \
CPPFLAGS="-I${INSTALL_DIR}/include -I/usr/include" \
LDFLAGS="-L${INSTALL_DIR}/lib64 -L${INSTALL_DIR}/lib"
./config \
--prefix=${INSTALL_DIR} \
--openssldir=${INSTALL_DIR}/ssl \
no-tests \
shared \
zlib
# install
make install
# put certificate
curl -k -o ${CA_BUNDLE} ${CA_BUNDLE_SOURCE}
##########################################
# LIBSSH2
##########################################
echo -e "Downloading LIBSSH2 ${VERSION_LIBSSH2}"
mkdir -p ${LIBSSH2_BUILD_DIR}/bin
# Download and upack the source code
curl -Ls https://github.com/libssh2/libssh2/releases/download/libssh2-${VERSION_LIBSSH2}/libssh2-${VERSION_LIBSSH2}.tar.gz \
| tar xzC ${LIBSSH2_BUILD_DIR} --strip-components=1
# Move into the unpackaged code directory
cd ${LIBSSH2_BUILD_DIR}/bin/
echo -e "Configure & Install LIBSSH2"
# Configure the build
export CFLAGS="" \
CPPFLAGS="-I${INSTALL_DIR}/include -I/usr/include" \
LDFLAGS="-L${INSTALL_DIR}/lib64 -L${INSTALL_DIR}/lib"
${CMAKE_BUILD_BIN} .. \
-DBUILD_SHARED_LIBS=ON \
-DCRYPTO_BACKEND=OpenSSL \
-DENABLE_ZLIB_COMPRESSION=ON \
-DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} \
-DCMAKE_BUILD_TYPE=RELEASE
${CMAKE_BUILD_BIN} --build . --target install
##########################################
# CURL
##########################################
echo -e "Downloading CURL ${VERSION_CURL}"
mkdir -p ${CURL_BUILD_DIR}/bin;
curl -Ls https://github.com/curl/curl/archive/curl-${VERSION_CURL//./_}.tar.gz \
| tar xzC ${CURL_BUILD_DIR} --strip-components=1
cd ${CURL_BUILD_DIR}/
echo -e "Configure & Install CURL"
make distclean
# set -xe; \
./buildconf
export CFLAGS="" \
CPPFLAGS="-I${INSTALL_DIR}/include -I/usr/include" \
LDFLAGS="-L${INSTALL_DIR}/lib64 -L${INSTALL_DIR}/lib"
./configure \
--prefix=${INSTALL_DIR} \
--with-ca-bundle=${CA_BUNDLE} \
--enable-shared \
--disable-static \
--enable-optimize \
--disable-warnings \
--disable-dependency-tracking \
--with-zlib \
--enable-http \
--enable-ftp \
--enable-file \
--enable-ldap \
--enable-ldaps \
--enable-proxy \
--enable-tftp \
--enable-ipv6 \
--enable-openssl-auto-load-config \
--enable-cookies \
--with-gnu-ld \
--with-ssl \
--with-libssh2
make install
##########################################
# XML2
##########################################
echo -e "Downloading XML2 ${VERSION_XML2}"
mkdir -p ${XML2_BUILD_DIR}
# Download and upack the source code
curl -Ls http://xmlsoft.org/sources/libxml2-${VERSION_XML2}.tar.gz \
| tar xzC ${XML2_BUILD_DIR} --strip-components=1
# Move into the unpackaged code directory
cd ${XML2_BUILD_DIR}/
echo -e "Configure & Install XML2"
make distclean
# Configure the build
# set -xe; \
CFLAGS="" \
CPPFLAGS="-I${INSTALL_DIR}/include -I/usr/include" \
LDFLAGS="-L${INSTALL_DIR}/lib64 -L${INSTALL_DIR}/lib" \
./configure \
--prefix=${INSTALL_DIR} \
--with-sysroot=${INSTALL_DIR} \
--enable-shared \
--disable-static \
--with-html \
--with-history \
--enable-ipv6=no \
--with-icu \
--with-zlib=${INSTALL_DIR} \
--without-python
# set -xe; \
make install
cp -f xml2-config ${INSTALL_DIR}/bin/xml2-config
##########################################
# ZIP
##########################################
echo -e "Downloading ZIP ${VERSION_ZIP}"
mkdir -p ${ZIP_BUILD_DIR}/bin/
# Download and upack the source code
curl -Ls https://github.com/nih-at/libzip/archive/rel-${VERSION_ZIP//./-}.tar.gz \
| tar xzC ${ZIP_BUILD_DIR} --strip-components=1
# Move into the unpackaged code directory
cd ${ZIP_BUILD_DIR}/bin/
echo -e "Configure & Install ZIP"
# Configure the build
# set -xe; \
CFLAGS="" \
CPPFLAGS="-I${INSTALL_DIR}/include -I/usr/include" \
LDFLAGS="-L${INSTALL_DIR}/lib64 -L${INSTALL_DIR}/lib" \
${CMAKE_BUILD_BIN} .. \
-DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} \
-DCMAKE_BUILD_TYPE=RELEASE
${CMAKE_BUILD_BIN} --build . --target install
##########################################
# LIBSODIUM
##########################################
echo -e "Downloading LIBSODIUM ${VERSION_LIBSODIUM}"
mkdir -p ${LIBSODIUM_BUILD_DIR};
# Download and upack the source code
curl -Ls https://github.com/jedisct1/libsodium/archive/${VERSION_LIBSODIUM}.tar.gz \
| tar xzC ${LIBSODIUM_BUILD_DIR} --strip-components=1
# Move into the unpackaged code directory
cd ${LIBSODIUM_BUILD_DIR}/
echo -e "Configure & Install LIBSODIUM"
make distclean
# Configure the build
CFLAGS="" \
CPPFLAGS="-I${INSTALL_DIR}/include -I/usr/include" \
LDFLAGS="-L${INSTALL_DIR}/lib64 -L${INSTALL_DIR}/lib" \
./autogen.sh \
&& ./configure --prefix=${INSTALL_DIR} --enable-opt
make install
##########################################
# IMAGEMAGICK
##########################################
echo -e "Downloading IMAGEMAGICK ${VERSION_IMAGEMAGICK}"
mkdir -p ${IMAGEMAGICK_BUILD_DIR};
curl -Ls https://github.com/ImageMagick/ImageMagick/archive/${VERSION_IMAGEMAGICK}.tar.gz \
| tar xzC ${IMAGEMAGICK_BUILD_DIR} --strip-components=1
cd ${IMAGEMAGICK_BUILD_DIR}/
echo -e "Configure & Install IMAGEMAGICK"
make distclean
CFLAGS="" \
CPPFLAGS="-I${INSTALL_DIR}/include -I/usr/include" \
LDFLAGS="-L${INSTALL_DIR}/lib64 -L${INSTALL_DIR}/lib" \
./configure --prefix=${INSTALL_DIR} \
--disable-dependency-tracking \
--with-zlib \
--with-png-dir=${INSTALL_DIR} \
--with-jpeg-dir=${INSTALL_DIR} \
--with-webp-dir=${INSTALL_DIR} \
--with-freetype-dir=${INSTALL_DIR}
make install
##########################################
# POSTGRES
##########################################
echo -e "Downloading POSTGRES ${VERSION_POSTGRES}"
mkdir -p ${POSTGRES_BUILD_DIR}/bin;
curl -Ls https://github.com/postgres/postgres/archive/REL_${VERSION_POSTGRES//./_}.tar.gz \
| tar xzC ${POSTGRES_BUILD_DIR} --strip-components=1
cd ${POSTGRES_BUILD_DIR}/
echo -e "Configure & Install POSTGRES"
make distclean
CFLAGS="" \
CPPFLAGS="-I${INSTALL_DIR}/include -I/usr/include" \
LDFLAGS="-L${INSTALL_DIR}/lib64 -L${INSTALL_DIR}/lib" \
./configure --prefix=${INSTALL_DIR} --with-openssl --without-readline
# set -xe;
cd ${POSTGRES_BUILD_DIR}/src/interfaces/libpq && make && make install
# set -xe;
cd ${POSTGRES_BUILD_DIR}/src/bin/pg_config && make && make install
# set -xe;
cd ${POSTGRES_BUILD_DIR}/src/backend && make generated-headers
# set -xe;
cd ${POSTGRES_BUILD_DIR}/src/include && make install
##########################################
# LIBMEMCACHED
##########################################
echo -e "Downloading LIBMEMCACHED 1.0.18"
mkdir -p ${LIBMEMCACHED_BUILD_DIR}
# Download and upack the source code
curl -Ls https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz \
| tar xzC ${LIBMEMCACHED_BUILD_DIR} --strip-components=1
# Move into the unpackaged code directory
cd ${LIBMEMCACHED_BUILD_DIR}/
echo -e "Configure & Install LIBMEMCACHED"
make distclean
CFLAGS="" \
CPPFLAGS="-I${INSTALL_DIR}/include -I/usr/include" \
LDFLAGS="-L${INSTALL_DIR}/lib64 -L${INSTALL_DIR}/lib" \
./configure --prefix=${INSTALL_DIR} --with-pic
make install
##########################################
# PHP
##########################################
echo -e "Downloading PHP ${VERSION_PHP}"
mkdir -p ${PHP_BUILD_DIR}
rm -rf ${PHP_BUILD_DIR}/*
# Download and upack the source code
curl -Ls https://github.com/php/php-src/archive/php-${VERSION_PHP}.tar.gz \
| tar xzC ${PHP_BUILD_DIR} --strip-components=1
# Move into the unpackaged code directory
cd ${PHP_BUILD_DIR}/
echo -e "Configure & Install PHP"
make distclean
./buildconf --force \
&& CFLAGS="-fstack-protector-strong -fpic -fpie -Os -I${INSTALL_DIR}/include -I/usr/include -ffunction-sections -fdata-sections" \
CPPFLAGS="-fstack-protector-strong -fpic -fpie -Os -I${INSTALL_DIR}/include -I/usr/include -ffunction-sections -fdata-sections" \
LDFLAGS="-L${INSTALL_DIR}/lib64 -L${INSTALL_DIR}/lib -Wl,-O1 -Wl,--strip-all -Wl,--hash-style=both -pie" \
./configure \
--build=x86_64-pc-linux-gnu \
--prefix=${INSTALL_DIR} \
--enable-option-checking=fatal \
--enable-maintainer-zts \
--with-config-file-path=${INSTALL_DIR}/etc/php \
--with-config-file-scan-dir=${INSTALL_DIR}/etc/php/conf.d:/var/task/php/conf.d \
--with-gd \
--with-png-dir=${INSTALL_DIR} \
--with-jpeg-dir=${INSTALL_DIR} \
--with-webp-dir=${INSTALL_DIR} \
--with-freetype-dir=${INSTALL_DIR} \
--with-xpm-dir=no \
--enable-fpm \
--enable-cli \
--disable-phpdbg \
--disable-phpdbg-webhelper \
--with-sodium \
--with-readline \
--with-openssl \
--with-zlib=${INSTALL_DIR} \
--with-zlib-dir=${INSTALL_DIR} \
--with-curl \
--enable-exif \
--enable-ftp \
--with-gettext \
--enable-mbstring \
--with-pdo-mysql=shared,mysqlnd \
--enable-pcntl \
--enable-zip \
--with-pdo-pgsql=shared,${INSTALL_DIR} \
--enable-intl=shared \
--enable-opcache-file \
--enable-cgi \
--enable-mbstring \
--with-pdo-mysql \
--with-pdo-sqlite \
--with-sqlite3 \
--with-mysqli \
--enable-sockets
make -j $(nproc)
make install PEAR_INSTALLER_URL='https://github.com/pear/pearweb_phars/raw/master/install-pear-nozlib.phar'
{ find ${INSTALL_DIR}/bin ${INSTALL_DIR}/sbin -type f -perm +0111 -exec strip --strip-all '{}' + || true; }
make clean
cp -f php.ini-production ${INSTALL_DIR}/etc/php/php.ini
EXTENSION_DIR=${INSTALL_DIR}/etc/php/conf.d/
FILEOPCACHE=$(php-config --extension-dir)/opcache.so
FILEPOSTGRESQL=$(php-config --extension-dir)/pdo_pgsql.so
FILEINTL=$(php-config --extension-dir)/intl.so
if [[ -f $FILEOPCACHE ]]; then
echo 'zend_extension=opcache.so' > ${EXTENSION_DIR}/opcache.ini
fi
if [[ -f $FILEPOSTGRESQL ]]; then
echo 'extension=pdo_pgsql.so' > ${EXTENSION_DIR}/pdo_pgsql.ini
fi
if [[ -f $FILEINTL ]]; then
echo 'extension=intl.so' > ${EXTENSION_DIR}/intl.ini
fi
##########################################
# INSTALL ADDITIONAL MODULES
##########################################
echo '' | ${INSTALL_DIR}/bin/pecl install igbinary
if [[ -f $(php-config --extension-dir)/igbinary.so ]]; then
echo 'extension=igbinary.so' > ${EXTENSION_DIR}/igbinary.ini
fi
echo '' | ${INSTALL_DIR}/bin/pecl install mongodb
if [[ -f $(php-config --extension-dir)/mongodb.so ]]; then
echo 'extension=mongodb.so' > ${EXTENSION_DIR}/mongodb.ini
fi
echo 'yes' | ${INSTALL_DIR}/bin/pecl install redis
if [[ -f $(php-config --extension-dir)/redis.so ]]; then
echo 'extension=redis.so' > ${EXTENSION_DIR}/redis.ini
fi
echo '' | ${INSTALL_DIR}/bin/pecl install APCu
if [[ -f $(php-config --extension-dir)/apcu.so ]]; then
echo 'extension=apcu.so' > ${EXTENSION_DIR}/apcu.ini
fi
echo $INSTALL_DIR | ${INSTALL_DIR}/bin/pecl install imagick
if [[ -f $(php-config --extension-dir)/imagick.so ]]; then
echo 'extension=imagick.so' > ${EXTENSION_DIR}/imagick.ini
fi
LIBSASL="/usr/lib64/libsasl2.so.3.0.0"
if [[ -f $LIBSASL ]]; then
cp -f $LIBSASL $INSTALL_DIR/lib64
cd ${INSTALL_DIR}/lib64
ln -s libsasl2.so.3.0.0 libsasl2.so.3
##########################################
# AWS LIBMEMCACHED
##########################################
echo -e "Downloading AWS LIBMEMCACHED${VERSION_AWS_LIBMEMCACHED}"
mkdir -p ${AWS_LIBMEMCACHED_BUILD_DIR}/build
rm -rf ${AWS_LIBMEMCACHED_BUILD_DIR}/build/*
curl -Ls https://github.com/awslabs/aws-elasticache-cluster-client-libmemcached/archive/${VERSION_AWS_LIBMEMCACHED}.tar.gz \
| tar xzC ${AWS_LIBMEMCACHED_BUILD_DIR} --strip-components=1
cd ${AWS_LIBMEMCACHED_BUILD_DIR}
touch configure.ac aclocal.m4 configure Makefile.am Makefile.in
cd ${AWS_LIBMEMCACHED_BUILD_DIR}/build
make distclean
../configure --prefix=${INSTALL_DIR}/aws \
--disable-memcached-sasl \
--with-pic \
--enable-memcached-igbinary
make install
##########################################
# AWS ELASTICACHE CLUSTER CLIENT
##########################################
echo -e "Downloading AWS ELASTICACHE CLUSTER CLIENT ${VERSION_AWS_ELASTIC_CACHE}"
mkdir -p ${AWS_ELASTIC_CACHE_BUILD_DIR}
# Download and upack the source code
curl -Ls https://github.com/awslabs/aws-elasticache-cluster-client-memcached-for-php/archive/${VERSION_AWS_ELASTIC_CACHE}.tar.gz \
| tar xzC ${AWS_ELASTIC_CACHE_BUILD_DIR} --strip-components=1
echo -e "Configure & Install AWS ELASTICACHE CLUSTER CLIENT"
# Move into the unpackaged code directory
cd ${AWS_ELASTIC_CACHE_BUILD_DIR}
make distclean
$INSTALL_DIR/bin/phpize
CFLAGS="" \
CPPFLAGS="-I${INSTALL_DIR}/include -I/usr/include" \
LDFLAGS="-L${INSTALL_DIR}/lib64 -L${INSTALL_DIR}/aws/lib -L${INSTALL_DIR}/lib" \
./configure --prefix=${INSTALL_DIR} \
--with-libmemcached-dir=${INSTALL_DIR}/aws \
--enable-memcached-igbinary \
--disable-memcached-sasl
sed -i "s#-lmemcached#${INSTALL_DIR}/aws/lib/libmemcachedutil.a ${INSTALL_DIR}/aws/lib/libmemcached.a -lcrypt -lpthread -lm -lstdc++ -lsasl2#" Makefile
sed -i "s#-lmemcachedutil##" Makefile
sed -i "s#-L${INSTALL_DIR}/aws/lib##" Makefile
make install
AWS_CLUSTER_SO=$(php-config --extension-dir)/amazon-elasticache-cluster-client.so
if [[ ! -f $AWS_CLUSTER_SO ]]; then
if [[ -f $(php-config --extension-dir)/memcached.so ]]; then
mv $(php-config --extension-dir)/memcached.so $AWS_CLUSTER_SO
fi
fi
if [[ -f $AWS_CLUSTER_SO ]]; then
echo 'extension=amazon-elasticache-cluster-client.so' > ${EXTENSION_DIR}/amazon-elasticache-cluster-client.ini
fi
fi
##########################################
# PTHREADS
##########################################
echo -e "Configure & Install PTHREADS Php Extension"
PTHREADS_BUILD_DIR=${BUILD_DIR}/pthreads
# Build from master because there are no pthreads release compatible with PHP 7.3
mkdir -p ${PTHREADS_BUILD_DIR}/bin; \
curl -Ls https://github.com/krakjoe/pthreads/archive/master.tar.gz \
| tar xzC ${PTHREADS_BUILD_DIR} --strip-components=1
cd ${PTHREADS_BUILD_DIR}/
make distclean
${INSTALL_DIR}/bin/phpize \
&& ./configure \
&& make \
&& make install
# pthreads does not support on fpm cgi
# if [[ -f $(php-config --extension-dir)/pthreads.so ]]; then
# echo 'extension=pthreads.so' > ${EXTENSION_DIR}/pthreads.ini
# fi
echo 'Optimize Libraries'
# Strip all the unneeded symbols from shared libraries to reduce size.
find ${INSTALL_DIR} -type f -name "*.so*" -o -name "*.a" -exec strip --strip-unneeded {} \;
find ${INSTALL_DIR} -type f -executable -exec sh -c "file -i '{}' | grep -q 'x-executable; charset=binary'" \; -print|xargs strip --strip-all
# Cleanup all the binaries we don't want.
find ${INSTALL_DIR}/bin -mindepth 1 -maxdepth 1 ! -name 'php' ! -name 'php-fpm' ! -name 'php-cgi' -exec rm {} \+
#find ${INSTALL_DIR}/bin -mindepth 1 -maxdepth 1 ! -name 'php' ! -name 'php-fpm' ! -name 'pear' ! -name 'pecl' ! -name 'php-cgi' -exec rm {} \+
# Cleanup all the files we don't want either
#
# We do not support running pear functions in Lambda
# Please remove this delete data command if you want full backup
echo 'Cleanup Unwanted Data for Lambda'
rm -rf ${INSTALL_DIR}/lib/php/PEAR
rm -rf ${INSTALL_DIR}/share/doc
rm -rf ${INSTALL_DIR}/share/man
rm -rf ${INSTALL_DIR}/share/gtk-doc
rm -rf ${INSTALL_DIR}/include
rm -rf ${INSTALL_DIR}/tests
rm -rf ${INSTALL_DIR}/doc
rm -rf ${INSTALL_DIR}/docs
rm -rf ${INSTALL_DIR}/man
rm -rf ${INSTALL_DIR}/www
rm -rf ${INSTALL_DIR}/cfg
rm -rf ${INSTALL_DIR}/libexec
rm -rf ${INSTALL_DIR}/var
rm -rf ${INSTALL_DIR}/data
rm -rf ${INSTALL_DIR}/aws
rm -rf ${INSTALL_DIR}/ssl/man
rm -rf ${INSTALL_DIR}/lib/php/test/
# Symlink all our binaries into /opt/bin so that Lambda sees them in the path.
mkdir -p /opt/bin
ln -s ${INSTALL_DIR}/bin/* /opt/bin
ln -s ${INSTALL_DIR}/sbin/* /opt/bin
# WRITE TO CONFIG FPM
# pools socket is on /tmp/.nusaraya/php-fpm.sock
# please run multiple configuration with copy of below
# and add another files to socket (eg: increment to make sure lambda could run multiple fpm process)
echo -e "; Logging anywhere on disk doesn't make sense on lambda since instances are ephemeral\n\
error_log = /dev/null\n\
; Log above warning because PHP-FPM logs useless notices\n\
; We must comment this flag else uncaught exceptions/fatal errors are not reported in the logs!\n\
; TODO: report that to the PHP bug tracker\n\
;log_level = 'warning'\n\
\n\
[default]\n\
pm = static\n\
; We only need one child because a lambda can process only one request at a time\n\
pm.max_children = 1\n\
listen = /tmp/.nusaraya/php-fpm.sock\n\
; Allows PHP processes to access the lambda's environment variables\n\
clear_env = no\n\
; Forward stderr of PHP processes to stderr of PHP-FPM (so that it can be sent to cloudwatch)\n\
catch_workers_output = yes\n\
; New PHP 7.3 option that disables a verbose log prefix\n\
; Disabled for now until we switch to PHP 7.3\n\
;decorate_workers_output = no" > ${INSTALL_DIR}/etc/php-fpm.conf
@pentagonal
Copy link
Author

pentagonal commented Mar 15, 2019

You are not run as sudo, but have sudoers group.

chown /opt/ to your username access

Install

wget -q -O -  https://gist.github.com/pentagonal/bae094b2a07d742b484b3f8c4f5df362/raw/installer.sh | bash

You can use automatically without prompt :

Download Installer first

wget https://gist.github.com/pentagonal/bae094b2a07d742b484b3f8c4f5df362/raw/installer.sh

And run installer

bash installer.sh

After installation no error go to /opt/

and run

zip -r9y  /tmp/lambda.zip ./bin ./lambda

Your file is on /tmp/lambda.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment