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
sudo add-apt-repository ppa:ondrej/php
After running this command, if you see an error message like :
sudo: add-apt-repository: command not found
This means that you need to install the package python-software-properties, using the following:
sudo apt-get install python-software-properties
Step 2: Now you just need to update the local package cache and install PHP 7
sudo apt-get update
If you are running Nginx :
sudo apt-get install php7.0-fpm
If you are running Apache :
sudo apt-get install php7.0
Also be sure to re-install PHP MYSQL for both Nginx and Apache, using :
sudo apt-get install php7.0-mysql
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 :
Step 4: Check the new PHP install
should show you an output like :
PHP 7.0.4-7+deb.sury.org~trusty+2 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
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.
We can see a clear difference between the same WordPress site running on PHP 5.6 and the one on PHP 7 here
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.
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’
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.