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
1 |
sudo add-apt-repository ppa:ondrej/php |
After running this command, if you see an error message like :
1 |
sudo: add-apt-repository: command not found |
This means that you need to install the package python-software-properties, using the following:
1 |
sudo apt-get install python-software-properties |
Step 2: Now you just need to update the local package cache and install PHP 7
1 |
sudo apt-get update |
If you are running Nginx :
1 |
sudo apt-get install php7.0-fpm |
If you are running Apache :
1 |
sudo apt-get install php7.0 |
Also be sure to re-install PHP MYSQL for both Nginx and Apache, using :
1 |
sudo apt-get install php7.0-mysql |
Step 3: Update the Nginx site configs for PHP 7
Open the Nginx site config file
1 |
nano /etc/nginx/sites-available/<sitename> |
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
1 |
php -v |
should show you an output like :
1 2 3 4 |
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.
PHP 5.6
PHP 7
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.
PHP 5.6
PHP 7
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.
thanks
As we say technology is advancing, but in PHP version case, we would say old is gold.
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.
What about Compatibility?
Is WordPress compatible with PHP 7 or there are any known issues?
As of now the WordPress core is fully compatibile with PHP 7
https://make.wordpress.org/core/2015/09/10/wordpress-and-php7/
But not all the plugins and themes are fully compatible or tested with PHP 7. It’s only a matter of time when the plugin and theme authors also make their plugins/themes fully compatible with PHP 7
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.
Thanks for the great article