PHP 7 vs PHP5 Speed Showdown

PHP 7 – Speed of lightning?

PHP 7 Logo
PHP 7 is fast. Really fast.

WordPress is a beast. Most people who have gotten into the weeds of performance tuning WordPress will be all too familiar with this statement. PHP 5.6 helped, as did WordPress 4.4. There are numerous ways to speed up your WordPress site, to include caching plugins, faster DNS, CDNs, faster hosting hardware, etc. When PHP 7 officially released in December I had already been on the prowl for a speed solution. I had explored HHVM which certainly boasts some impressive speed improvements. I didn’t have the time or desire to implement a PHP replacement for my sites at that time, so the arrival of PHP 7 was quite timely.

Upgrading to from PHP 5.6 to PHP 7

My test host was an Ubuntu 14.04.03 LTS server running Apache and PHP 5.6.

The upgrade path was surprisingly easy, which is one of the benefits of keeping the same core technology in place, as opposed to jumping to a new technology (such as HHVM). If you’re looking for a quick, relatively painless speed boost to any PHP site, here is how I migrated up to the newest version!

CYA Note:

In the previous paragraph I extolled the simplicity and easy with which this upgrade was done; with that said, though BACKUP YOUR SYSTEM BEFORE TRYING THIS. If that means taking a VM snapshot, backing up your /var/www, backing up your apache & PHP configs, backing up your db, or anything else you can think of, do it.

Another note, this article is specifically for Apache web servers, I have not tried this with Nginx at this point.

Also for the love of all that is holy, try this in a DEV environment firstThis is informational only and I can’t be held responsible if you break your production site!

Good?

Good.

Onward!

Adding the PPA

PHP 7 isn’t part of the official Ubuntu 14.04 repositories yet. That will likely change with the next LTS release of Ubuntu. In the meantime, drop to a terminal session and run the following command to add the Personal Package Archive for PHP 7:

sudo add-apt-repository ppa:ondrej/php

Installing the packages

The next step is to refresh your Apt-Get cache to do this we issue the command:

sudo apt-get update

Your server will now pull down the updated list of packages. Once that process is complete we move on to installation.

sudo apt-get install php7.0 php7.0-mysql

This will install PHP 7, but we’re probably not done, yet.

Chances are that you have a customized PHP5 config file to adjust max file size for uploads, etc. Those alterations will need to be replicated over to the now-sensibly-structured /etc/php/7.0/apache2/php.ini file.

nanophpini

Once you’ve replicated those settings that you want to carry over, you should be good to go! You can confirm this by issuing the following command:

php -v

Additionally, your website should also work… which is, you know, pretty important.

The performance of a lifetime!?

Here’s where it gets good. Really good.

After upgrading Zutfen.com to PHP 7, I saw CPU load and processing time drop significantly. I also saw page load times go down by, on average, 40-55%. In a world where speed matter so very, very much for site rankings and so forth, that’s a huge improvement. Your mileage may vary, of course, but I’ve had nothing but a positive experience with PHP 7 for my sites, zutfen.com included. I will probably revisit HHVM for purely “I’m a huge nerd” reasons, for now I’m happy with the performance of WordPress with the latest version of PHP.

Have you moved to PHP 7 yet? How did it go?

 

6 thoughts on “PHP 7 vs PHP5 Speed Showdown”

Leave a comment

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