In this post, I will discuss how to update and why WordPress site to use PHP 7. PHP 7 is the latest version of the popular programming language PHP and offers faster performance for websites and online applications.
Every time a WordPress website is loaded, the PHP engine is summoned. Scripts are executed by the PHP engine using the server, and the final HTML is delivered to the visitor’s web browser.
Nearly 83% of websites use PHP. Which means that most of the Web relies on the language to at least some extent. It is estimated that PHP 7 offers a 100% improvement in performance speed over PHP 5.6.
This significant increase in speed allows web developers to create amazing websites that provide engaging features and still respond to user input quickly.
WordPress 4.0 itself has been fine-tuned to leverage PHP 7 latest features, and we are now in WordPress version 4.8 and counting.
Why Should You Update WordPress Site to PHP 7?
PHP 7 is optimized for executing the same task in fewer instructions. For example, one WordPress request on PHP 5.6 runs in 100 million CPU instructions. While in PHP 7, the same request is executed in 25 million CPU instructions.
That is a 75% reduction in the number of commands required to do the same job. According to the official WordPress stats, 11% of the WordPress community has upgraded to PHP 7 as of 8 August 2017.
Around 40% of WordPress users are still using PHP 5.6. This is good news since PHP 5.6 will still get security support until 31 December 2018.
The bad news is that about 45% of the active WordPress sites use a version of PHP older than 5.6. This exposes all those sites to vulnerability issues.
Yoost de Valk, founder of Yoast SEO, decided to do something about this. He started showing in his plugin notice to website owners that they should upgrade their PHP version.
As of Yoast SEO 4.5, we’ll start showing a notice on the WordPress dashboard to administrators of sites running on PHP 5.2. This notice will be big, ugly, and non-dismissible.
In this notice, we will explain why the administrator should upgrade the PHP version of the site.
BENEFITS OF PHP 7
Here are some advantages of using PHP 7 version:
- PHP 7 can handle uncached hits 2-3x faster
- Improvements in memory consumption
- Can serve up to 3x as many requests per second and handle more traffic with the same number of resources
- You can now specify return type variables with PHP 7
- Many fatal errors have been replaced with object-oriented exceptions to make it easier to find and address bugs
- Bug fixes, security patches, and maintenance updates for years to come
- New Zend Engine
- Abstract Syntax Tree
- Consistent 64bit support
- Compatibility with OpenSSL 1.0.2e onwards.
NOTE: Actual performance improvements will vary based on your theme, plugins, site load, and cacheability.
What Does All This Mean?
If you think what the heck does all above mean, let me summarize. PHP 7 is faster and more lightweight. Runs with less memory usage, executes twice the amount of code at any given time than PHP 5.x and it handles errors in a much cleaner way.
This all translates into a faster website, better coding and a much better user experience. If you care about your site performance, then you should switch to PHP 7 or find a hosting provider who uses it (if your doesn’t support).
Most popular hosting companies offer PHP 7 for all of their plans (or they offer the upgrade).
Are Your Plugins and Theme Compatible With PHP 7?
Just because WordPress is compatible with PHP 7 (and has backward compatibility with PHP 5.6), does not mean all themes and plugins are also compatible.
You may use a custom-built theme or plugin that uses deprecated features in PHP 7. You may also use a plugin from the WordPress repository that was not updated for a while.
Developers over at WP Engine have created a plugin that checks compatibility issues.
The plugin helps WordPress website owners check their site readiness to update to PHP 7 by telling them helpful information about why a particular plugin or theme is not compatible with PHP 7.
The plugin is called PHP Compatibility Checker. WP Engine PHP Compatibility Checker can be used by any WordPress website on any web host.
Plugin scans your WordPress code base and active theme and plugins looking for known compatibility issues.
You can check for compatibility issues for five distinct versions of PHP, ranging from 5.3 to 7.0.
Compatibility issues are categorized into errors and warnings and will list the file and line number of the offending code, as well as the info about why that line of code is incompatible with the chosen version of PHP.
However, there are a few limitations:
- The plugin cannot detect runtime compatibility issues since it doesn’t execute any of the existing themes and plugins.
- It relies on WP-Cron to scan files in the background, so WP-Cron must be enabled and working on the server.
- Occasionally, false positives are reported since the plugin cannot detect unused code paths that may be used for backward compatibility.
What if I Don’t Update WordPress to PHP 7?
Well, in that case, your site will break, and you will lose all your posts, customers and everything you worked hard for.
Just kidding. While you can still safely continue to use older versions, at some point in future, you will probably need to update. Try to use PHP 5.6 version at least.
Disadvantages of not upgrading to the recommended PHP 7 and possible dangers of not upgrading to the required minimum version, PHP 5.6:
1. Performance drop: You will miss out on the increase in performance. If you’re on PHP 5.2, it’s reported to be 400% slower than PHP 7.
2. Security issues: PHP 5.x has many vulnerabilities that are patched in the newer versions.
PHP 5.4 hasn’t been patched since 2015, and it’s no longer supported. And yet 21% of WordPress users still use that PHP version.
3. Broken plugins: Using an older, unsupported version of PHP creates plugin conflicts.
What are Possible Problems With PHP 7 in WordPress?
Despite the fact that WordPress core development team is always making the CMS ready for PHP7, the latest version of PHP can break your site.
The reason is the incompatibility of themes and plugins with PHP 7.
Even though WordPress community suggests theme and plugin authors to get familiarize with all backward incompatible changes and update things accordingly, most of the themes and plugins are not yet ready for the PHP 7.
Since WordPress has started fixing every possible issue related to PHP 7, more and more people are now taking necessary steps toward making their themes and plugins compatible with PHP 7.
Consider upgrading your site to PHP 7 only when you are sure your hosting server, themes, and plugins are compatible with version 7.
How to Switch to PHP 7 in WordPress?
Ensure that your current WordPress theme and plugins are compatible with PHP 7 using the PHP Compatibility Checker plugin. Once the plugin gives you the green light, proceed with the upgrade.
Even if you are using shared WordPress hosting, almost all shared WordPress hosting providers come with a cPanel or a custom access panel where you can change the version of PHP.
If you’re using a managed WordPress hosting, such as WP Engine, reach out to their support, and they will do it for you.
1. UPGRADE WORDPRESS SITE TO PHP 7 VIA SSH
Since the SSH commands for upgrading or installing other versions of PHP are different depending on the type of server you have, one set of commands can not be applied universally.
Click on one of the resources below to view details based on your server type:
Keep in mind that if you use the commands provided in these links, you also need to remove the old PHP package from your server that you no longer need.
Since the commands for removing older versions are also going to vary depending on your server type, check your server documentation for the correct commands.
2. SWITCH PHP VERSION USING CPANEL
Probably the easiest way to upgrade PHP7 version (except via support section) is by logging into your cPanel account.
It may not be possible with all types of hosting, but if you see a PHP Version Manager or PHP Configuration button in the control panel, you’re free to make the switch when you’re ready.
I will show on example of InMotion hosting shared hosting plan. It may be in different locations depending on your hosting.
#2.1. In the case of InMotion hosting, you will find the option to upgrade PHP version under Software – > PHP Configuration.
Then just pick PHP version you want to use and click Update. Be noted that all your sites hosted on that server will be affected.
#2.2. In the case of Half Dollar Hosting your process via cPanel is similar. You can find the option to update PHP version under Software -> Select PHP Version.
#2.3. With SiteGround hosting, you have two ways to move your WordPress site to PHP 7.0 or +.
- Using SG Optimizer WordPress plugin
- From SiteGround cPanel using PHP Manager
Using SG Optimizer WordPress plugin, you don’t need to worry if your existing plugins and themes are compatible with PHP 7 or not as the plugin has an inbuilt feature to check compatibility.
3. CONTACT HOSTING SUPPORT FOR SWITCHING PHP VERSION
If you don’t want to use methods above or you are not able, there is always option to contact hosting support and ask them to update PHP version for you.
Most hosting providers will oblige with your request.
Updating WordPress to PHP 7 Final Words
WordPress will continue to support older versions of PHP. But this does not mean you can sit back and relax. It’s in your best interest to upgrade to at least 5.6.
If you’re on PHP 5.6, there are a couple of things coming your way:
- According to the official PHP support timeline, PHP 5.6 will get official support until 17 Jan 2017. That’s ended.
- PHP 5.6 would get security support until 31 December 2018.
- You are missing out on all the performance enhancements you could get from latest versions.
The WordPress benchmarks show that speed and performance increases are significant. I really see no point of using older versions of PHP or keeping plugins which still don’t support or keep pace with latest releases.
All that said, the road to full adoption will be a slow and cautious as there is plenty of work remaining for hosting companies and developers to make sure their products and services are compatible.
Are you considering making the switch to PHP7 or you already did it? Let me know in comments below!
DISCLOSURE: My posts may contain affiliate links. If you buy something through one of those links, I might get a small commission, without any extra cost to you. Read more about it here.