How to compile php7 on ubuntu 14.04

How to compile php7 on ubuntu 14.04

[slb_exclude]I’ve been reading great things about PHP 7, specifically the PHP7 infographic created by Zend. So today I decided to create a ubuntu droplet and go to work compiling php7 from source. I ran into a few problems along the way but eventually was successfully. Here is a quick howto that will help you avoid some the same pitfalls I experienced.
[/slb_exclude]

After installing a fresh copy of Ubuntu 14.04 lets install some dependencies and software we need to compile php from source.

A WORD OF CAUTION! Do not attempt to compile or install php7 on a production machine, you have been warned. While already published, this article is a work in progress and I’m still writing and editing it.

First Step, Install gcc compiler, php5 dependencies, and some required libraries.

sudo apt-get -y install build-essential git autoconf
sudo apt-get build-dep php5
sudo apt-get -y install libt1-dev libgmp-dev bison
sudo apt-get -y install mysql-server mysql-client libmysqlclient-dev
apt-get install libfcgi-dev libfcgi0ldbl

You may also have to create this symbolic link

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

Next, create a folder to download to and use git to clone the php7 codebase.

mkdir $HOME/php7
cd $HOME/php7
git clone https://git.php.net/repository/php-src.git
cd php-src

Running buildconf and configure is next  You may want to adjust the paths of –prefix and –with-config-file-path if you are attempting to make and install php7 to coexist with a php5 installation.

./buildconf

./configure \
--prefix=/usr \
--with-config-file-path=/etc \
--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-pdo-mysql=/usr \
--with-gettext=/usr \
--with-zlib=/usr \
--with-bz2=/usr \
--with-recode=/usr \
--with-mysqli=/usr/bin/mysql_config

And now, time to compile php7. This step might take a while depending on your machine. I first attempted to compile php7 on a DigitalOcean 512MB droplet and ran out of memory. Make sure your ubuntu machine has at least 1GB of RAM before proceeding.

make

The final step, install the compiled php7 binaries.

make install

Now lets execute php -v and to confirm the we are indeed running php 7.

cd /usr/bin
root@php7:~/usr/bin# ./php -v
PHP 7.0.0-dev (cli) (built: May 14 2015 17:35:28)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0-dev, Copyright (c) 1998-2015 Zend Technologies

That’s it, your first taste of php7. If you run into errors during the configure step the answer might be below.

Errors encountered while trying to compile PHP7 from source

Error
configure: error: xml2-config not found. Please check your libxml2 installation.

Solution
apt-get install libxml2-dev


Error
/usr/bin/mysql_config: No such file or directory

Solution
apt-get install mysql-server mysql-client libmysqlclient-dev


Error
Warning: Declaration of PEAR_Installer::download() should be compatible with & PEAR_Downloader::download($params) in phar:///root/php7/php-src/pear/install-pear-nozlib.phar/PEAR/Installer.php on line 43

<code>

Warning: Declaration of PEAR_PackageFile_Parser_v2::parse() should be compatible with PEAR_XMLParser::parse($data) in phar:///root/php7/php-src/pear/install-pear-nozlib.phar/PEAR/PackageFile/Parser/v2.php on line 113
[PEAR] Archive_Tar – installed: 1.3.13
[PEAR] Console_Getopt – installed: 1.3.1
[PEAR] Structures_Graph- installed: 1.0.4

<code>

Warning: Declaration of PEAR_Task_Replace::init() should be compatible with PEAR_Task_Common::init($xml, $fileAttributes, $lastVersion) in phar:///root/php7/php-src/pear/install-pear-nozlib.phar/PEAR/Task/Replace.php on line 31
[PEAR] XML_Util – installed: 1.2.3

<code>

Warning: Declaration of PEAR_Task_Windowseol::init() should be compatible with PEAR_Task_Common::init($xml, $fileAttributes, $lastVersion) in phar:///root/php7/php-src/pear/install-pear-nozlib.phar/PEAR/Task/Windowseol.php on line 76


Warning: Declaration of PEAR_Task_Unixeol::init() should be compatible with PEAR_Task_Common::init($xml, $fileAttributes, $lastVersion) in phar:///root/php7/php-src/pear/install-pear-nozlib.phar/PEAR/Task/Unixeol.php on line 76
[PEAR] PEAR - installed: 1.9.5
Wrote PEAR system config file at: /root/php7/usr/etc/pear.conf

Solution

You may want to add: /root/php7/usr/lib/php to your php.ini include_path
/root/php7/php-src/build/shtool install -c ext/phar/phar.phar /root/php7/usr/bin


Error
configure: WARNING: unrecognized options: --with-mysql


Error
checking for bison version... invalid
configure: WARNING: This bison version is not supported for regeneration of the Zend/PHP parsers (found: none, min: 204, excluded: ).
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
configure: error: bison is required to build PHP/Zend when building a GIT checkout!

Solution
apt-get install bison


Error
configure: error: Cannot find OpenSSL's

Solution
apt-get install libssl-dev


Error
configure: error: Cannot find OpenSSL's libraries

Solution
apt-get install libssl-dev


Error
checking for BZip2 in default path… not found
configure: error: Please reinstall the BZip2 distribution

Solution
apt-get install libbz2-dev


Error
configure: error: Please reinstall the libcurl distribution –
easy.h should be in /include/curl/

Solution
apt-get install libcurl4-openssl-dev


Error
If configure fails try --with-vpx-dir=
configure: error: jpeglib.h not found.

Solution
apt-get install libjpeg-dev


Error
configure: error: png.h not found.

Solution
apt-get install libpng12-dev


Error
configure: error: freetype-config not found.

Solution
apt-get install libfreetype6-dev


Error
configure: error: mcrypt.h not found. Please reinstall libmcrypt.

Solution
apt-get install libmcrypt-dev


Error
configure: error: Cannot find pspell

Solution
apt-get install libpspell-dev


Error
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.

Solution
pear install pear/PHP_Archive


Error
checking for recode support... yes
configure: error: Can not find recode.h anywhere under /usr /usr/local /usr /opt.

Solution
apt-get install librecode-dev


Error
virtual memory exhausted: Cannot allocate memory
make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1

Solution
Install more RAM or increase the size of your VPS, it looks like 512MB is not enough to compile php7 from source.

Disk and Memory Requirements to compile PHP7

You will need atleast 1GB of RAM to compile php 7 on Ubuntu 14.04.

References

I hope you enjoyed this post and found it useful.  As always, I invite you to join the conversation or point out anything I missed by leaving a comment below.

16 Replies to “How to compile php7 on ubuntu 14.04”

  1. Running .configure fails with error: Unable to locate gmp.h. The symlink to /usr/include/x86_64-linux-gnu/gmp.h is broken. When i locate gmp.h, I only get:

    /usr/src/linux-headers-3.13.0-24/include/linux/igmp.h
    /usr/src/linux-headers-3.13.0-24/include/uapi/linux/igmp.h
    /usr/src/linux-headers-3.13.0-24-powerpc-smp/include/linux/igmp.h

    Already tried to install libgmp-dev / libgmp3-dev, both are installed, but no gmp.h is found. Any idea’s how to solve this / find these files?

    1. Try to install locate (sudo apt-get install locate)

      then updatedb (updatedb)

      then locate gmp.h

      In my case:

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

  2. Error:
    configure: error: Unable to detect ICU prefix or no failed. Please verify ICU install prefix and make sure icu-config works.

    Solution:
    apt-get install icu

  3. Greate article!I had took it in my pocket yet.

    There is my solution for the Error “configure: WARNING: unrecognized options: –with-mysql”:

    Solution1: `–with-pdo-mysql` instead of `–with-mysql`
    Solution2:`–with-mysqli` instead of `–with-mysql`

    But I don’t know which one is the better than?

  4. I found this article after weaving my way through some of the woes whilst trying to compile PHP 7.1.0 with phpbrew on a fesh Ubujtu 16.04.1 install on after replacing my drive with an SDD.

    Thank you for this fantiastic and helpful article, pretty mush working through them one by one as specified above :-)

    Here are a couple which I don’t think you have listed…

    ———-
    Problem: configure: error: Please reinstall readline – I cannot find readline.h

    Solution: sudo apt-get install libreadline-dev
    ———-
    Problem: configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution

    Solution: sudo apt-get install libxslt-dev

  5. Error:
    configure: error: Unable to detect ICU prefix or no failed. Please verify ICU install prefix and make sure icu-config works.

    Solution: apt-get install libicu-dev

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.