PHP7 has many performance advantages, and in this post, I’ve performed a test to find out the WordPress performance on PHP 5.6 and 7. You will also learn how to switch WordPress to use from PHP 5 to 7 on Shared Hosting, VPS/Cloud.
PHP7 was released in 2015 with many performance improvements but looks like the industry is yet to adopt the new version of PHP.
As you can see PHP7 got just above 3% of market share despite providing better features. Does it lack awareness?
I read a lot of articles on PHP7 vs. PHP5 so thought myself to give a try and see how fast is PHP7 with the WordPress website.
Before jumping to the results, some worth mentioning features of PHP7 are:
- Reduced memory usage
- Consistent 64-bit support
- New version of Zend engine
- New engine exception for better error handling
- Adds anonymous classes
- Faster loading website (of course)
The latest version of WordPress officially supports PHP7. Let’s find out how they perform with PHP7.
A little bit on platform and testing procedure to give you a clear picture.
- I provisioned Linode $10 plan and did the following.
- Installed WordPress 4.7 on Ubuntu 16.04 LTS through EasyEngine
- Installed Blogging Theme by MyThemeShop
- Didn’t use any caching plugin or CDN
- Used Loader to perform a load test with 50-200 clients for one minute.
WordPress performance on PHP-FPM 5.6
By default, EasyEngine installs PHP-FPM 5.6, so I didn’t have to do any configuration except setting up WordPress, installing theme & pointing my test domain to Linode VM IP.
I went to Loader to perform the test and here is the result:
- Average response time: 11.96s
- Minimum response time: 0.6s
- Maximum response time: 19s
WordPress performance on PHP-FPM 7.0
I switched to PHP 7 through Easy engine and results are:
Amazing! You see PHP7 is two times faster. PHP7 performed well in all the aspects.
- Average time is 5.1 seconds compare to 11.96s with PHP 5.6
- Minimum response time is 0.4 seconds compare to 0.6s
- Maximum response time is 8.2 seconds compare to 19s
Just by switching WordPress from PHP 5.6 to PHP 7 decreased the website load time by 50%.
I believe it’s quick win for any WordPress website and if you are still not using the latest PHP version, then this test result should encourage you to upgrade.
You may want to check your theme and plugin to ensure they are compatible with PHP 7 so it doesn’t break post update.
How to Switch from PHP 5 to 7?
There are multiple ways to achieve this based on the platform you use.
If using EasyEngine
Probably one of the quickest ways to switch stack version is using EasyEngine.
Login to your VPS/Cloud where EasyEngine is installed
ee site update yourwebsite.com --php7
[email protected]:~# ee site update chandan.io --php7 PHP7.0 is experimental feature and it may not work with all plugins of your site. You can disable it by passing --php7=off later. Do you wish to enable PHP now for chandan.io? Type "y" to continue [n]:y Running pre-update checks, please wait... Backup location : /var/www/chandan.io/backup/25Feb2017093100 Backing up database [Done] Setting up NGINX configuration [Done] Setting up webroot [Done] Reload : nginx [OK] Successfully updated site http://chandan.io [email protected]:~#
You can use ps command to verify PHP 7 is running.
[email protected]:~# ps -ef|grep php root 17274 1 0 Feb24 ? 00:00:04 php-fpm: master process (/etc/php/7.0/fpm/php-fpm.conf) root 26674 26541 0 09:31 pts/0 00:00:00 grep --color=auto php [email protected]:~#
Note: if you notice PHP 5 and 7 both are running then you can stop the PHP 5 and remove from the auto start-up.
If you are on shared hosting which provides cPanel, then you can change the PHP version by yourself as the following.
However, if you don’t have cPanel, then you may need to speak to your hosting provider.
The following screenshot is taken from SiteGround.
- Login to your cPanel
- Click “PHP Version Manager” under 1H Software
- Select the site to change the PHP version
- Change the version and click Save
You will get a confirmation that new version is applied to your site home.
Well done! You just made your WordPress site faster on shared hosting.
If hosting on Cloud/VPS
If you are hosting your WordPress on Cloud or VPS like Google Cloud, AWS, Linode, DO, etc. and have installed everything manually by your own then you can do the following (example for CentOS 6.x )to upgrade PHP.
- Login to your CentOS VM
- Take a backup of VM before upgrade so you can rollback in-case thing goes wrong
- Remove existing PHP version
yum remove php-fpm php-cli php-common
- Install the following repository
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm
- Install PHP-FPM 7 and its required module
yum install php70w-fpm-nginx php70w-cli php70w-mysqlnd php70w-fpm
Restart Nginx, MySQL & PHP-FPM to ensure it’s loaded with the latest version. You may also access WordPress website to ensure its functional.
Congratulation! You have successfully installed PHP-FPM 7.
You may do the following if you want to verify the version.
[[email protected] init.d]# /usr/sbin/php-fpm -version PHP 7.0.16 (fpm-fcgi) (built: Feb 18 2017 10:46:38) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies [[email protected] init.d]#
I hope above given you an idea how to implement PHP-FPM 7 for WordPress and its performance advantages.
So go ahead and give a try to PHP-FPM 7 to experience the fast loading WordPress website.