{"id":1418,"date":"2024-03-28T11:40:27","date_gmt":"2024-03-28T06:10:27","guid":{"rendered":"http:\/\/blog.wpoven.com\/?p=1418"},"modified":"2024-05-03T12:31:27","modified_gmt":"2024-05-03T07:01:27","slug":"php-5-6-vs-php-7-wordpress-sites-nginx","status":"publish","type":"post","link":"https:\/\/www.wpoven.com\/blog\/php-5-6-vs-php-7-wordpress-sites-nginx\/","title":{"rendered":"php 5 vs php 7 &#8211; WordPress sites with Nginx"},"content":{"rendered":"<p><a href=\"https:\/\/www.wpoven.com\/blog\/wp-content\/uploads\/2016\/03\/php7-v-php5w2.jpg\"><img decoding=\"async\" class=\"aligncenter size-large wp-image-1501\" src=\"https:\/\/www.wpoven.com\/blog\/wp-content\/uploads\/2016\/03\/php7-v-php5w2-1024x581.jpg\" alt=\"php-7-v-php5w2\" title=\"\"><\/a><\/p>\n<p>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<\/p>\n\n<h2>How to upgrade from PHP 5.6 to PHP 7 (with Nginx) on Ubuntu 14.04 \/ 16.04 server<\/h2>\n<p><span style=\"text-decoration: underline;\"><strong>Step 1<\/strong><\/span> : You need to add a PPA for PHP 7<\/p>\n<pre class=\"line-height:18 top-set:false top-margin:2 bottom-set:false bottom-margin:2 toolbar:0 lang:default decode:true\">sudo add-apt-repository ppa:ondrej\/php<\/pre>\n<p>After running this command, if you see an error message like :<\/p>\n<pre class=\"line-height:18 top-margin:2 bottom-margin:2 toolbar:0 lang:default decode:true\">sudo: add-apt-repository: command not found<\/pre>\n<p>This means that you need\u00a0to install the package python-software-properties, using the following:<\/p>\n<pre class=\"line-height:18 top-set:false top-margin:2 bottom-set:false bottom-margin:2 toolbar:0 lang:default decode:true\">sudo apt-get install python-software-properties<\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>Step 2<\/strong><\/span>: Now you just need to update the local package cache and install PHP 7<\/p>\n<pre class=\"line-height:18 top-set:false bottom-set:false toolbar:0 lang:default decode:true\">sudo apt-get update<\/pre>\n<p>If you are running\u00a0<strong>Nginx<\/strong> :<\/p>\n<pre class=\"line-height:18 top-set:false bottom-set:false toolbar:0 lang:default decode:true\">sudo apt-get install php7.0-fpm<\/pre>\n<p>If you are running\u00a0<strong>Apache<\/strong> :<\/p>\n<pre class=\"line-height:18 top-set:false bottom-set:false toolbar:0 lang:default decode:true\">sudo apt-get install php7.0<\/pre>\n<p>Also be sure to re-install <strong>PHP MYSQL <\/strong>for both Nginx and Apache, using :<\/p>\n<pre class=\"line-height:18 top-set:false bottom-set:false toolbar:0 lang:default decode:true\">sudo apt-get install php7.0-mysql<\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>Step 3<\/strong><\/span>: Update the Nginx site configs for PHP 7<\/p>\n<p>Open the Nginx site config file<\/p>\n<pre class=\"line-height:18 top-set:false bottom-set:false toolbar:0 lang:default decode:true\">nano \/etc\/nginx\/sites-available\/&lt;sitename&gt;<\/pre>\n<p>and \u00a0under the section &#8220;<em>location ~ \\.php$<\/em> &#8220;,\u00a0replace the line that looks like :<\/p>\n<p><em>fastcgi_pass unix:\/var\/run\/php5-fpm.sock;<\/em><\/p>\n<p>to<\/p>\n<p><em>fastcgi_pass\u00a0unix:\/var\/run\/php\/php7.0-fpm.sock;<\/em><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>Step 4<\/strong><\/span>: Check the new PHP install<\/p>\n<pre class=\"line-height:18 top-set:false bottom-set:false toolbar:0 lang:default decode:true\">php -v<\/pre>\n<p>should show you an output like :<\/p>\n<pre class=\"top-set:false bottom-set:false toolbar:0 lang:default decode:true\">PHP 7.0.4-7+deb.sury.org~trusty+2 (cli) ( NTS )\r\nCopyright (c) 1997-2016 The PHP Group\r\nZend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies\r\nwith Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies<\/pre>\n<h2><\/h2>\n<h2 style=\"text-align: center;\"><span style=\"text-decoration: underline;\">PHP 5 vs PHP 7<\/span><\/h2>\n<h2><\/h2>\n<h2>\u00a0Info about site used in the test<\/h2>\n<ul>\n<li><span style=\"line-height: 13px;\">Site is the latest available WordPress version when the article was written <strong>WordPress 4.4.2<\/strong><\/span><\/li>\n<li>Site has over a <strong>1000 blog posts<\/strong><\/li>\n<li>Selected theme is the\u00a0<strong>TwentySixteen <\/strong>default theme<\/li>\n<li>Has about <strong>150 users<\/strong><\/li>\n<li>Around <strong>500 comments<\/strong><\/li>\n<\/ul>\n<h2>Info about Server used in the test<\/h2>\n<ul>\n<li><span style=\"line-height: 13px;\">The site was hosted on an <strong>Ubuntu 14.04<\/strong> server<\/span><\/li>\n<li>Having <strong>1GB Ram<\/strong><\/li>\n<li>20GB <strong>SSD<\/strong> Disk<\/li>\n<li>Running <strong>Nginx<\/strong><\/li>\n<li>Dedicated <strong>VPS<\/strong><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2><span style=\"text-decoration: underline;\">TEST 1 : Loadstorm test<\/span><\/h2>\n<p>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&#8217;t any sort of caching activated for the site for any test.<\/p>\n<h3 style=\"text-align: center;\">PHP 5.6<\/h3>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-1436 size-large\" src=\"https:\/\/www.wpoven.com\/blog\/wp-content\/uploads\/2016\/03\/loadstorm-php5-1024x682.png\" alt=\"loadstorm-php5\" width=\"1024\" height=\"682\" title=\"\"><\/p>\n<h3 style=\"text-align: center;\">PHP 7<\/h3>\n<p><a href=\"https:\/\/www.wpoven.com\/blog\/wp-content\/uploads\/2016\/03\/loadstorm-php7.png\"><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/www.wpoven.com\/blog\/wp-content\/uploads\/2016\/03\/loadstorm-php7-1024x682.png\" alt=\"loadstorm-php7\" width=\"1024\" height=\"682\" title=\"\"><\/a><\/p>\n<p style=\"text-align: left;\">We can see a clear difference between the same WordPress site running on PHP 5.6 and the one on PHP 7 here<\/p>\n<h3 style=\"text-align: center;\"><\/h3>\n<p style=\"text-align: center;\"><a href=\"https:\/\/www.wpoven.com\/blog\/wp-content\/uploads\/2016\/03\/loadstrom-php5-vs-php7.png\"><img decoding=\"async\" class=\"aligncenter wp-image-1477 size-full\" src=\"https:\/\/www.wpoven.com\/blog\/wp-content\/uploads\/2016\/03\/loadstrom-php5-vs-php7.png\" alt=\"loadstrom-php5-vs-php7\" width=\"674\" height=\"299\" title=\"\"><\/a><\/p>\n<p style=\"text-align: left;\">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.<\/p>\n<p style=\"text-align: left;\">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.<\/p>\n<h2 style=\"text-align: left;\"><span style=\"text-decoration: underline;\">TEST 2 : Webpagespeed test<\/span><\/h2>\n<p>In this \u00a0test we ran both the WordPress sites through the web page speed test tool at\u00a0<a title=\"Web page speed test\" href=\"http:\/\/www.webpagetest.org\/\" target=\"_blank\" rel=\"noopener\">http:\/\/www.webpagetest.org\/<\/a> multiple times through various global server locations.<\/p>\n<p>&nbsp;<\/p>\n<h3 style=\"text-align: center;\"><\/h3>\n<h3 style=\"text-align: center;\"><\/h3>\n<h3 style=\"text-align: center;\">PHP 5.6<\/h3>\n<p><a href=\"https:\/\/www.wpoven.com\/blog\/wp-content\/uploads\/2016\/03\/WebPagetest-php5-uizen.com-03-31-16-14-08-23.png\"><img decoding=\"async\" class=\"aligncenter wp-image-1433 size-full\" src=\"https:\/\/www.wpoven.com\/blog\/wp-content\/uploads\/2016\/03\/WebPagetest-php5-uizen.com-03-31-16-14-08-23.png\" alt=\"WebPagetest-php5-uizen.com 03 31 16 14 08 23\" width=\"882\" height=\"322\" title=\"\"><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3 style=\"text-align: center;\"><\/h3>\n<h3 style=\"text-align: center;\">PHP 7<\/h3>\n<p><a href=\"https:\/\/www.wpoven.com\/blog\/wp-content\/uploads\/2016\/03\/WebPagetest-Test-Result-php7-uizen.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-1432\" src=\"https:\/\/www.wpoven.com\/blog\/wp-content\/uploads\/2016\/03\/WebPagetest-Test-Result-php7-uizen.png\" alt=\"WebPagetest Test Result-php7-uizen\" title=\"\"><\/a><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: left;\">We can see here as well that the WordPress site on PHP 7 performed better than the same WordPress site on PHP 5.6<\/p>\n<h2 style=\"text-align: left;\"><span style=\"text-decoration: underline;\">TEST 3 : WP Performance Tester Plugin<\/span><\/h2>\n<p>For our 3rd test we use the Performance benchmark testing WordPress plugin &#8216;WP Performance tester&#8217;<\/p>\n<h3 style=\"text-align: center;\"><a href=\"https:\/\/www.wpoven.com\/blog\/wp-content\/uploads\/2016\/03\/WP-performance-test-php5-v-php7.png\"><img decoding=\"async\" class=\"aligncenter size-large wp-image-1490\" src=\"https:\/\/www.wpoven.com\/blog\/wp-content\/uploads\/2016\/03\/WP-performance-test-php5-v-php7-1024x819.png\" alt=\"WP-performance-test-php5-v-php7\" title=\"\"><\/a><\/h3>\n<p style=\"text-align: left;\">This test only cements the performance of PHP 7 over it&#8217;s predecessor. \u00a0We can see the much higher number of queries per second that PHP 7 handles which gives it a much better &#8216;Execution Time&#8217;. The &#8216;math&#8217; and &#8216;string manipulation&#8217; functions are almost 3-4 times faster on PHP 7, giving it the edge.<\/p>\n<h2 style=\"text-align: center;\">Why you shouldn&#8217;t be in a hurry to upgrade your WordPress site to PHP 7 just yet<\/h2>\n<p>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.<\/p>\n<p>If you do decide to take the plunge and upgrade to PHP 7, you should take the following precautions:<\/p>\n<ul>\n<li><span style=\"line-height: 13px;\">Backup everything. Your site, database, uploads.<\/span><\/li>\n<li>Upgrade all your Plugins and Themes to there respective latest versions.<\/li>\n<li>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.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p><img decoding=\"async\" class=\"aligncenter size-large wp-image-1501\" src=\"https:\/\/www.wpoven.com\/blog\/wp-content\/uploads\/2016\/03\/php7-v-php5w2-1024x581.jpg\" alt=\"php-7-v-php5w2\" title=\"\"\/><br \/>\nIn 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<br \/>\nHow to upgrade from PHP 5.6 to PHP 7 (with Nginx) on Ubuntu 14.04 \/ 16.04 server<br \/>\nStep 1 : You need to add a PPA for PHP 7<br \/>\nsudo add-apt-repository ppa:ondrej\/php<br \/>\nAfter running this command, if you see an error message like :<br \/>\nsudo: add-apt-repository: command not found<br \/>\nThis means that you need\u00a0to install the package python-software-properties, &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.wpoven.com\/blog\/php-5-6-vs-php-7-wordpress-sites-nginx\/\" class=\"more-link\">Read More <i class=\"fa fa-angle-double-right\" aria-hidden=\"true\"><\/i><span class=\"screen-reader-text\"> &#8220;php 5 vs php 7 &#8211; WordPress sites with Nginx&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ub_ctt_via":"","footnotes":""},"categories":[14,15,9,16,13],"acf":[],"featured_image_src":null,"author_info":{"display_name":"Vikrant Datta","author_link":"https:\/\/www.wpoven.com\/blog\/author\/vikrant\/"},"_links":{"self":[{"href":"https:\/\/www.wpoven.com\/blog\/wp-json\/wp\/v2\/posts\/1418"}],"collection":[{"href":"https:\/\/www.wpoven.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wpoven.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wpoven.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wpoven.com\/blog\/wp-json\/wp\/v2\/comments?post=1418"}],"version-history":[{"count":3,"href":"https:\/\/www.wpoven.com\/blog\/wp-json\/wp\/v2\/posts\/1418\/revisions"}],"predecessor-version":[{"id":25963,"href":"https:\/\/www.wpoven.com\/blog\/wp-json\/wp\/v2\/posts\/1418\/revisions\/25963"}],"wp:attachment":[{"href":"https:\/\/www.wpoven.com\/blog\/wp-json\/wp\/v2\/media?parent=1418"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wpoven.com\/blog\/wp-json\/wp\/v2\/categories?post=1418"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}