Skip to content

Instantly share code, notes, and snippets.

@boynoiz
Last active September 5, 2018 16:30
Show Gist options
  • Save boynoiz/f7d4bfd1835395175a40 to your computer and use it in GitHub Desktop.
Save boynoiz/f7d4bfd1835395175a40 to your computer and use it in GitHub Desktop.
PHP 7.0 on Debian 7 Wheezy
#!/bin/bash
set -e
PHP_VERSION=7.0
# Script base on php7.sh by Tom Van Looy https://gist.github.com/tvlooy/881d0d67d0ad699c38a3
# Dont use this shell script in production server unless you dont care
# You must first add the testing repository in your sourcelist before run this
# You must stop php7-fpm service if you already install
# Dependencies
sudo apt-get update
sudo apt-get -t testing install -y \
build-essential \
pkg-config \
git-core \
autoconf \
bison \
libxml2-dev \
libbz2-dev \
libmcrypt-dev \
libicu-dev \
libssl-dev \
libcurl4-openssl-dev \
libltdl-dev \
libjpeg-dev \
libpng-dev \
libpspell-dev \
libreadline-dev \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng12-dev \
libxpm-dev \
libreadline6-dev \
libxslt1-dev
#clean exits PHP7
rm -rf /etc/php7
rm -rf /usr/local/php-${PHP_VERSION}
#create new PHP7 directory
mkdir -p /etc/php7/{cli,fpm}/conf.d
mkdir -p /etc/php7/mods-available
mkdir /usr/local/php-${PHP_VERSION}
# Check if php-src directory is exits
if [ -d "php-src" ]
then
cd php-src
git checkout PHP-${PHP_VERSION}
git pull
else
git clone https://github.com/php/php-src.git
cd php-src
git checkout PHP-${PHP_VERSION}
git pull
fi
CONFIGURE_STRING="--prefix=/usr/local/php-${PHP_VERSION} \
--enable-bcmath \
--with-bz2 \
--with-zlib \
--enable-zip \
--enable-calendar \
--enable-exif \
--enable-dba \
--enable-ftp \
--with-gettext \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-xpm-dir \
--enable-mbstring \
--with-mcrypt \
--with-mhash \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-openssl \
--with-pspell \
--enable-shmop \
--enable-intl \
--enable-soap \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-readline \
--with-curl \
--with-xsl \
--disable-cgi"
# Build CLI
make distclean
./buildconf --force
./configure \
$CONFIGURE_STRING \
--enable-pcntl \
--with-config-file-path=/etc/php7/cli \
--with-config-file-scan-dir=/etc/php7/cli/conf.d
# Change download location for nozlib in Makefile. it's has issue about ssl cerificate on pear.php.net
sed -i 's/https:\/\/pear.php.net\/install-pear-nozlib.phar/http:\/\/pear.php.net\/install-pear-nozlib.phar/g' Makefile
make -j2
make install
# Build FPM
make distclean
./buildconf --force
./configure \
$CONFIGURE_STRING \
--with-config-file-path=/etc/php7/fpm \
--with-config-file-scan-dir=/etc/php7/fpm/conf.d \
--disable-cli \
--enable-fpm \
--with-fpm-user=www-data \
--with-fpm-group=www-data
# Change download location for nozlib in Makefile. it's has issue about ssl cerificate on pear.php.net
sed -i 's/https:\/\/pear.php.net\/install-pear-nozlib.phar/http:\/\/pear.php.net\/install-pear-nozlib.phar/g' Makefile
make -j2
make install
# Install config files
cp php.ini-production /etc/php7/cli/php.ini
cp php.ini-production /etc/php7/fpm/php.ini
sed -i 's/;date.timezone =.*/date.timezone = Asia\/Bangkok/' /etc/php7/fpm/php.ini
sed -i 's/;date.timezone =.*/date.timezone = Asia\/Bangkok/' /etc/php7/cli/php.ini
cp sapi/fpm/php-fpm.conf.in /etc/php7/fpm/php-fpm.conf
sed -i 's#^include=.*/#include=/etc/php7/fpm/pool.d/#' /etc/php7/fpm/php-fpm.conf
mkdir /etc/php7/fpm/pool.d/
cp /usr/local/php-${PHP_VERSION}/etc/php-fpm.d/www.conf.default /etc/php7/fpm/pool.d/www.conf
sed -i 's/listen = 127.0.0.1:9000/listen = 127.0.0.1:9070/g' /etc/php7/fpm/pool.d/www.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php7-fpm
sed -i 's/Provides: php-fpm/Provides: php7-fpm/' /etc/init.d/php7-fpm
sed -i 's#^php_fpm_CONF=.*#php_fpm_CONF=/etc/php7/fpm/php-fpm.conf#' /etc/init.d/php7-fpm
sed -i 's#^php_fpm_PID=.*#php_fpm_PID=/var/run/php7-fpm.pid#' /etc/init.d/php7-fpm
# Build extensions
cd ..
PATH=/usr/local/php-${PHP_VERSION}/bin:/usr/local/php-${PHP_VERSION}/sbin/$PATH
# opcache
echo "zend_extension=opcache.so" > /etc/php7/mods-available/opcache.ini
ln -s /etc/php7/mods-available/opcache.ini /etc/php7/cli/conf.d/opcache.ini
ln -s /etc/php7/mods-available/opcache.ini /etc/php7/fpm/conf.d/opcache.ini
chmod +x /etc/init.d/php7-fpm
update-rc.d php7-fpm defaults
service php7-fpm start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment