Compiling And Installing PHP7 On Ubuntu

At the LAMP and Beyond III event (run by PHPNW) this weekend we set ourselves the task of giving PHP7 a go. Below is some nodes from that session.

This assumes that you’ve already installed PHP5.6 along with Apache and MySQL. Installing PHP5.6 via apt-get is fine as we just need some of the dependencies to be present.

To get the the code for PHP7 you need to clone from the PHP repo on Github.

git clone [email protected]:php/php-src.git php-src

Go into the php-src directory and run the ./buildconf command, this will generate a configuration file.


Before you run config you’ll need to install some dependencies (there are one or two).

sudo apt-get install autoconf bison libxml2-dev apache2-dev systemtap-sdt-dev openssl pkg-config libssl-dev libcurl4-openssl-dev libbz2-dev libgdbm-dev libjpeg62 libjpeg62-dev libpng12-0 libpng12-dev libfreetype6-dev libicu-dev libiodbc2-dev libxslt1-dev

Now you can run ./configure to configure PHP. You’ll need to add a few flags to let PHP know what extensions to install and where some of the software lives.

./configure --prefix=/usr/local/php7/7.0.0 --localstatedir=/usr/local/var --sysconfdir=/usr/local/etc/php/7 --with-config-file-path=/usr/local/etc/php/7 --with-config-file-scan-dir=/usr/local/etc/php/7/conf.d --mandir=/usr/local/php7/7.0.0/share/man --enable-bcmath --enable-calendar --enable-dba --enable-exif --enable-ftp --enable-gd-native-ttf --enable-intl --enable-mbregex --enable-mbstring --enable-shmop --enable-soap --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --enable-zip --with-freetype-dir=/usr/local/opt/freetype --with-gd --with-gettext=/usr/local/opt/gettext --with-iconv-dir=/usr --with-icu-dir=/usr/local/opt/icu4c --with-jpeg-dir=/usr/local/opt/jpeg --with-kerberos=/usr --with-libedit --with-mhash --with-ndbm=/usr --with-openssl=/usr/local/opt/openssl --with-pdo-odbc=unixODBC,/usr/local/opt/unixodbc --with-png-dir=/usr/local/opt/libpng --with-unixODBC=/usr/local/opt/unixodbc --with-xmlrpc --with-zlib=/usr/local/opt/zlib --with-apxs2=/usr/bin/apxs --libexecdir=/usr/local/php7/7.0.0/libexec --with-bz2=/usr --disable-debug --enable-fpm --with-fpm-user=_www --with-fpm-group=_www --with-curl --with-xsl=/usr --with-ldap --with-ldap-sasl=/usr --with-mysql-sock=/tmp/mysql.sock --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --disable-opcache --enable-pcntl --enable-dtrace --disable-phpdbg --enable-zend-signals

Once the configure has completed you need to compile PHP7. Do this with the make command.


Once that has finished you can optionally run the PHP test suite with the 'make test' command.

make test

Finally, you can run ‘make install’ to install PHP7 into your system. You’ll need to run this step as root as it updated a few system files.

sudo make install

Once done you’ll need to setup Apache to use the new version of PHP. The following lines will disable the original PHP5 version and enable the new PHP7 version.

sudo a2dismod php5
sudo service apache2 restart

One thing that was missing was a PHP7 configuration file. Luckily, the PHP5 version works very well with PHP7 so that was needed was to copy it across.

sudo cp /etc/apache2/mods-available/php5.conf /etc/apache2/mods-enabled/php7.conf

All you need to do now is restart Apache2 for the change to take effect.

sudo service apache2 restart

If you want to run PHP on the command line then you’ll need to relink the current system PHP with the PHP7 version. To find out where your current PHP command line client is installed run the which command.

which php

You can then run the following with the output of the previous command to swap out your PHP cli version.

sudo rm -rf /usr/bin/php && sudo ln -s /usr/local/php7/7.0.0/bin/php /usr/bin/php

Now, when you run PHP on the command line you will be running PHP7.

$ php -v
PHP 7.0.0-dev (cli) (built: Apr 11 2015 12:11:25)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0-dev, Copyright (c) 1998-2015 Zend Technologies

You are now running PHP7!


Didn't work for me. PHP stopped working on my Apache. On my php7.conf, there is no reference to the actual php7 path, is it normal ?
In my ubuntu it was necessary to remove the "7.0.0" command sudo rm -rf /usr/bin/php && sudo ln -s /usr/local/php7/7.0.0/bin/php /usr/bin/php

Add new comment

The content of this field is kept private and will not be shown publicly.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
1 + 1 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.