How to install PHP7 nightly on Linux


PHP

Deprecation

Without creating an another article to instal PHP7, I prefer to share with you this great post: How to Install PHP 7.0, Apache 2.4.17, & MySQL 5.6 on Ubuntu 15.10 & 14.
So, the following information in my article bellow are now deprecated and was only effective to the nightly version of PHP7.

Preamble

sudo nano /etc/apt/sources.list
deb http://archive.ubuntu.com/ubuntu jessie main
aptitude update

Using early access repo

Add Zends PHP7 early access repo:

echo "deb http://repos.zend.com/zend-server/early-access/php7/repos ubuntu/" >> /etc/apt/sources.list

To install PHP7 nighly build:

apt-get update && apt-get install php7-nightly

Installing Apache 2.4

aptitude install apache2 apache2-mpm-worker libapache2-mod-fastcgi

Then create the file “/etc/apache2/conf-available/php7-fpm.conf” with the contents:

<IfModule mod_fastcgi.c>
    AddHandler php7-fcgi .php
    Action php7-fcgi /php7-fcgi
    Alias /php7-fcgi /usr/lib/cgi-bin/php7-fcgi
    FastCgiExternalServer /usr/lib/cgi-bin/php7-fcgi -socket /var/run/php7-fpm.sock -pass-header Authorization
</IfModule>

Then enable the new mods and config:

a2enmod actions fastcgi alias
a2enconf php7-fpm
a2dismod mpm_event
a2enmod mpm_prefork
service apache2 reload

Install of MySQL

aptitude install mysql-server mysql-client

Build and configure PHP7

To get, build and install PHP7 from sources, you will need some tools to be installed in your linux. Use the next command to install the needed tools:

aptitude install git make autoconf build-essential libt1-dev libgmp-dev bison re2c libxml2-dev libcurl4-openssl-dev libssl-dev libsslcommon2-dev libbz2-dev libjpeg-dev libfreetype6-dev libmcrypt-dev libmysqlclient-dev libaspell-dev

Create a temporary directory:

mkdir ~/tmp
cd ~/tmp

Clone sources from git repository:

git clone https://git.php.net/repository/php-src.git

You can now build and configure your env

cd php-src
./buildconf
./configure \
    --prefix=/usr/local/php7 \
    --with-config-file-path=/usr/local/etc/php7 \
    --localstatedir=/usr/local/var \
    --sysconfdir=/usr/local/etc/php7 \
    --enable-mbstring \
    --enable-zip \
    --enable-bcmath \
    --enable-pcntl \
    --enable-ftp \
    --enable-exif \
    --enable-calendar \
    --enable-sysvmsg \
    --enable-sysvsem \
    --enable-sysvshm \
    --enable-wddx \
    --with-curl \
    --with-mcrypt \
    --with-iconv \
    --with-gmp \
    --with-pspell \
    --with-gd \
    --with-jpeg-dir=/usr \
    --with-png-dir=/usr \
    --with-zlib-dir=/usr \
    --with-xpm-dir=/usr \
    --with-freetype-dir=/usr \
    --with-t1lib=/usr \
    --enable-gd-native-ttf \
    --enable-gd-jis-conv \
    --with-openssl \
    --with-mysql=/usr \
    --with-pdo-mysql=/usr \
    --with-pgsql=/usr \
    --with-pdo-pgsql=/usr \
    --with-firebird=/usr \
    --with-pdo-firebird=/usr \
    --with-pdo-odbc=unixODBC,/usr/ \
    --with-oci8=instantclient,/usr/lib/oracle/12.1/client64/lib \
    --with-pdo-oci=instantclient,/usr,12.1 \
    --with-interbase=/usr \
    --with-gettext=/usr \
    --with-zlib=/usr \
    --with-bz2=/usr \
    --with-recode=/usr \
    --with-mysqli=/usr/bin/mysql_config

You can now make and install sources

make
make test
sudo make install

We now need to create a symlink:

sudo ln -sf /usr/local/php7/bin/php /usr/bin/php

add to /etc/apache2/sites-enabled/000-default.conf or other vhost conf file:

AddType application/x-httpd-php .php .phtml

php.ini

cd /usr/local/etc/php7
sudo nano php.ini

paste the code:

max_execution_time=600
memory_limit=128M
error_reporting=1
display_errors=1
log_errors=1
user_ini.filename=
realpath_cache_size=2M
cgi.check_shebang_line=0

zend_extension=opcache.so
opcache.enable_cli=1
opcache.save_comments=1
opcache.fast_shutdown=1
opcache.validate_timestamps=1
opcache.revalidate_freq=60
opcache.use_cwd=1
opcache.max_accelerated_files=100000
opcache.max_wasted_percentage=5
opcache.memory_consumption=128
opcache.consistency_checks=0

Common errors

Unable to locate gmp.h

ln -s /usr/include/x86_64-linux-gnu/gmp.h /usr/include/gmp.h

libfbclient, libgds or libib_util not found!

aptitude install firebird2.5-dev

Cannot find header file(s) for pdo_odbc

aptitude install unixodbc-dev unixodbc-bin unixodbc

Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path

aptitude install libpq-dev