php 5 vs php 7 – WordPress sites with Nginx

php-7-v-php5w2

In this post we will test the performance of the new PHP version, php 7 for WordPress sites running on Nginx., along with how to upgrade from PHP 5.6 to PHP 7

How to upgrade from PHP 5.6 to PHP 7 (with Nginx) on Ubuntu 14.04 / 16.04 server

Step 1 : You need to add a PPA for PHP 7

After running this command, if you see an error message like :

This means that you need to install the package python-software-properties, using the following:

 

Step 2: Now you just need to update the local package cache and install PHP 7

If you are running Nginx :

If you are running Apache :

Also be sure to re-install PHP MYSQL for both Nginx and Apache, using :

 

Step 3: Update the Nginx site configs for PHP 7

Open the Nginx site config file

and  under the section “location ~ \.php$ “, replace the line that looks like :

fastcgi_pass unix:/var/run/php5-fpm.sock;

to

fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;

 

Step 4: Check the new PHP install

should show you an output like :

PHP 5 vs PHP 7

 Info about site used in the test

  • Site is the latest available WordPress version when the article was written WordPress 4.4.2
  • Site has over a 1000 blog posts
  • Selected theme is the TwentySixteen default theme
  • Has about 150 users
  • Around 500 comments

Info about Server used in the test

  • The site was hosted on an Ubuntu 14.04 server
  • Having 1GB Ram
  • 20GB SSD Disk
  • Running Nginx
  • Dedicated VPS

 

TEST 1 : Loadstorm test

The WordPress site was tested on loadstorm.com for both PHP 7 and PHP 5 for upto 10 concurrent users over a period of 10 minutes. There wasn’t any sort of caching activated for the site for any test.

PHP 5.6

 

loadstorm-php5

PHP 7

loadstorm-php7

We can see a clear difference between the same WordPress site running on PHP 5.6 and the one on PHP 7 here

loadstrom-php5-vs-php7

The main stat we want to see here is the Average Response Time. We can clearly see that the response time for PHP 7 is less than that of PHP 5.

We also need to keep in mind the fact that this is fairly small WordPress site running on the default TwentySixteen theme and no add on plugins installed. So even a small performance difference on such a simple site would mean a large difference on a medium to large WordPress site with a decent number of plugins.

TEST 2 : Webpagespeed test

In this  test we ran both the WordPress sites through the web page speed test tool at http://www.webpagetest.org/ multiple times through various global server locations.

 

PHP 5.6

WebPagetest-php5-uizen.com 03 31 16 14 08 23

 

PHP 7

WebPagetest Test Result-php7-uizen

 

We can see here as well that the WordPress site on PHP 7 performed better than the same WordPress site on PHP 5.6

TEST 3 : WP Performance Tester Plugin

For our 3rd test we use the Performance benchmark testing WordPress plugin ‘WP Performance tester’

WP-performance-test-php5-v-php7

This test only cements the performance of PHP 7 over it’s predecessor.  We can see the much higher number of queries per second that PHP 7 handles which gives it a much better ‘Execution Time’. The ‘math’ and ‘string manipulation’ functions are almost 3-4 times faster on PHP 7, giving it the edge.

Why you shouldn’t be in a hurry to upgrade your WordPress site to PHP 7 just yet

So from the simple performance tests above, we can clearly see that PHP 7 performace much better than PHP 5.6, but you should wait a little longer before upgrading to PHP 7. This is simply because most of the WordPress plugins and themes are not fully compatible with PHP 7 yet. Though the WordPress team is continuously working on making WordPress core fully compatible with PHP 7, it could be a little while when all your Plugins and Themes are fully tested and compatible for PHP 7. So upgrading to PHP 7 right now could potentially break your site, if any of your plugin or your theme is not compatible with PHP 7.

If you do decide to take the plunge and upgrade to PHP 7, you should take the following precautions:

  • Backup everything. Your site, database, uploads.
  • Upgrade all your Plugins and Themes to there respective latest versions.
  • It is always advisable to contact your hosting provider and discus if it is a good idea to upgrade to PHP 7 on there setup.

7 Replies to “php 5 vs php 7 – WordPress sites with Nginx”

    1. It’s only a matter of time. The authors will have their plugins and themes compatible with PHP 7.
      PHP 7 is the future. It is almost twice as fast as PHP 5 in most cases.

  1. I Just upgraded a client to 7 from 5.5 and saw the request time drop to half after a few weeks of testing to try to catch as many edge-cases as possible. That means fewer frustrated clients, fewer servers needed at scale and most importantly, they are not running on a dead version of PHP5-series any more. As soon as we add some caching, they will be even faster (hoping to get < 1s average for static pages with content that is not per-request).

    It's true there is no catch-all, fix-all magic wand; but there are principles of basic computer science we can apply. PHP7 uses less RAM, so if you are RAM bound (lots of dynamic languages are), then you get capacity. At the end of the day, if your tools suffer from newer technology; that could be a sign to stop and think, maybe re-evaluate choices, not hold on to dead or dying technology.

Leave a Reply

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