Compiling PHP7 on Ubuntu - 19/01/2016

PHP7 - Faster Than a Fast Thing That's Really Fast

PHP7 was released in December 2015, and promises a massive increase in speed. Some benchmarks have claimed it to be at least twice as fast as PHP 5.x.

So, is it really that fast? In a word yes, it's blindin'.

Because our servers use PHP-FPM it's actually really easy to test out the speed differences. I did a default installation of concrete5, 5.7.5.4 which is PHP7 compatible. Inserting some debug into the concrete5 core to log the time to render and shut down the concrete5 dispatcher, this is what I found.

  • PHP 5.3, all C5 caches OFF- 1.8 seconds
    Hmm. Typical slightly sluggish performance without the cache on.

  • PHP 5.3 all C5 caches ON- 0.7 seconds
    The benefit of the caching system is evident.

  • PHP 7.0 all C5 Caches OFF- 0.86 seconds
    Oh wow - that's over 100% faster - or less than half the time.

  • PHP 7.0 all C5 Caches OFF, Zend Opcache enabled - 0.4 seconds
    That's mental, but wait, there's more:

  • PHP 7.0 all C5 Caches ON, Zend Opcache enabled - 0.18 seconds
    That's 1000% faster, or just 10% of the first result.

So, yes, it really is that fast.

Compiling PHP can take a while to figure out. Most of the issues are to do with dependencies and some unexpected stupidity from the configure script (You'd think that it would use /usr/include as a default in all cases, but it doesn't, I'm looking at you libjpeg - "imagecreatefromstring(): No JPEG support in this PHP build").

You'll need the following development packages (for Debian/Ubuntu):

  • autoconf
  • make
  • gcc
  • g++
  • libxml2-dev
  • libcurl4-openssl-dev
  • lib32bz2-dev
  • libenchant-dev
  • libpng-dev
  • libxpm-dev
  • libfreetype6-dev
  • libicu-dev
  • libmcrypt-dev
  • libpspell-dev
  • libreadline-dev
  • libjpeg8-dev

which are installed with "sudo apt-get install"

The configure command we used, which gives us the same module list as the vendor supplied 5.3 version was:

./configure
--with-jpeg-dir=/usr/include
--with-mysqli
--enable-fpm
--with-gd
--enable-bcmath
--with-bz2
--enable-calendar
--enable-dba
--with-curl
--with-enchant
--with-gettext
--enable-intl
--enable-mbstring
--with-mcrypt
--with-mhash
--with-openssl
--with-pcre-regex
--with-pspell
--with-readline
--with-pdo-mysql
--enable-exif
--enable-ftp
--with-mhash
--enable-shmop
--enable-soap
--enable-sockets
--enable-sysvmsg
--enable-sysvsem
--enable-sysvshm
--enable-wddx
--enable-zip
--prefix=/usr/php7
--with-mysql-sock=/var/run/mysqld/mysqld.sock
--with-xpm-dir=/usr/include/X11
--with-freetype-dir=/usr/include/freetype2

Points to note.

  1. The --with-jpeg-dir=/usr/include is necessary otherwise the GD library throws a hissy fit about not having JPEG support.
  2. --with-freetype-dir=/usr/include/freetype2 is also needed otherwise GD can't use fonts which makes you CAPTCHA images a bit poorly and somewhat impossible to solve.

The next trick is to download Imagick for PHP7

  1. apt-get install libmagickwand-dev
  2. wget https://github.com/mkoppanen/imagick/archive/phpseven.zip
  3. unzip phpseven.zip
  4. cd imagick-phpseven
  5. /usr/php7/bin/phpize
  6. ./configure --with-php-config=/usr/php7/bin/php-config
  7. make
  8. make install

It's also necessary to add the module to your php.ini

extension=imagick.so

Previous comments on this post

Leave a Reply



(Your email will not be publicly displayed.)