More Than Just Web Design | INTERNET ENGINEERING | APPLICATION | DESIGN
Compiling PHP7 on Ubuntu
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, 18.104.22.168 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):
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
The next trick is to download Imagick for PHP7
Points to note.
- The --with-jpeg-dir=/usr/include is necessary otherwise the GD library throws a hissy fit about not having JPEG support.
- --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.
- apt-get install libmagickwand-dev
- wget https://github.com/mkoppanen/imagick/archive/phpseven.zip
- unzip phpseven.zip
- cd imagick-phpseven
- ./configure --with-php-config=/usr/php7/bin/php-config
- make install
It's also necessary to add the module to your php.ini