Skip to content

Instantly share code, notes, and snippets.

@Abukamel
Last active February 2, 2017 12:08
Show Gist options
  • Save Abukamel/37cf67198ab72c7cb6ae8f6ecefd6623 to your computer and use it in GitHub Desktop.
Save Abukamel/37cf67198ab72c7cb6ae8f6ecefd6623 to your computer and use it in GitHub Desktop.
Install PHP version 7 from source on Ubuntu 14.04+
#!/usr/bin/env bash
# Names of latest versions of PHP package
export VERSION_PHP=php-5.6.26
# PHP mirror URL
export SOURCE_PHP=http://php.net/get/${VERSION_PHP}.tar.bz2/from/this/mirror
# Path to local build
export BUILD_DIR=/usr/local/src/php
function setup() {
# create and clean build directory
mkdir -p ${BUILD_DIR}
rm -Rf ${BUILD_DIR}/*
# install build environment tools
apt -y install supervisor \
build-essential \ [109/3262]│
zlib1g-dev \
libpcre3 \
libpcre3-dev \
unzip \
libxpm-dev \
libgmp-dev \
libxmp-dev \
libjpeg-dev \
libpng12-dev \
libcurl4-gnutls-dev \
libbz2-dev \
libxml2-dev \
libfreetype6-dev \
libmcrypt-dev \
libxml2-dev \
libbz2-dev \
libjpeg-dev \
libx11-dev \
libgd-dev \
libmcrypt-dev \
libmysqld-dev \
libmysqlclient-dev \
libmhash-dev \
libevent-dev \
libc-client-dev \
zlib1g-dev \
libpng-dev \
libxslt-dev \
libfreetype6-dev \
libgmp-dev \
libxml2-dev \
libpcre3-dev \
libbz2-dev \
libjpeg-dev \
libxpm-dev \
libfreetype6-dev \
libmysqlclient-dev \
libt1-dev \
libgd2-xpm-dev \
libgmp-dev \
libsasl2-dev \
libmhash-dev \
unixodbc-dev \
freetds-dev \
libpspell-dev \
libsnmp-dev \
libtidy-dev \
libmcrypt-dev
}
function download_sources() {
# todo: verify checksum / integrity of downloads!
echo "Download sources"
pushd ${BUILD_DIR}
wget ${SOURCE_PHP} -O ${VERSION_PHP}.tar.bz2
popd
}
function extract_sources() {
pushd ${BUILD_DIR}
tar xvf ${VERSION_PHP}.tar.bz2
popd
}
function compile_php() {
pushd ${BUILD_DIR}/${VERSION_PHP}
make clean
./configure \
'--prefix=/usr/local/php7-fpm' \
'--with-mysql' \
'--with-gd' \
'--with-gettext' \
'--with-libdir=lib64' \
'--with-jpeg-dir' \
'--with-zlib' \
'--with-curl' \
'--with-config-file-scan-dir=/usr/local/php7-fpm/lib/php.d' \
'--with-freetype-dir' \
'--with-png-dir' \
'--with-xpm-dir' \
'--enable-gd-native-ttf' \
'--with-mysqli' \
'--with-pdo-mysql' \
'--with-gmp' \
'--enable-ftp' \
'--enable-magic-quotes' \
'--enable-sysvsem' \
'--enable-fpm' \
'--enable-sysvshm' \
'--enable-sysvmsg' \
'--with-kerberos' \
'--enable-shmop' \
'--with-libxml-dir' \
'--enable-xml' \
'--with-mcrypt' \
'--enable-soap'
make && make install
(/usr/local/php7-fpm/bin/pecl config-set php_ini /usr/local/php7-fpm/lib/php.ini; /usr/local/php7-fpm/bin/pear config-set php_ini /usr/local/php7-fpm/lib/php.ini) && (/usr/local/php7-fpm/bin/pecl config-set temp_dir /root || /usr/local/php7-fpm/bin/pear config-set temp_dir /root)
popd
# Create supervisord service file
}
echo "Building ${VERSION_PHP}"
setup && download_sources && extract_sources && compile_php
retval=$?
echo ""
if [ $retval -eq 0 ]; then
echo "Your php binary is located at /usr/local/php7-fpm/sbin/php7-fpm"
else
echo "Ooops, build failed. Check output!"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment