How To Test PHP 7 Compatibility With WordPress

 In Hosting, WordPress

In the course of helping people with their WordPress websites, I continually get one question: why should I be using PHP 7? For most small businesses who hire me to help them with WordPress, PHP doesn’t mean much. Yet it’s something they have heard of and wonder about. Below I’ll try to explain why you should be using PHP 7 on all of your WordPress sites, and how you can check for PHP 7 compatibility beforehand.

What is PHP?

PHP is one of those fun recursive acronyms. It stands for PHP: Hypertext Processor. It’s a server side programming language that is a favorite of web developers because of its efficiency, power, and ease of use. All of WordPress, from the core code to themes and plugins, is written in PHP. Whenever you’re writing a blog post, viewing a page, placing an order, or anything else with a WordPress site, you’re inevitably executing some PHP code on the server. Sure, there is JavaScript involved once a page is sent back to a visitor or when you’re working in the admin area. But by and large, the bulk of the system is written in PHP.

Keep in mind PHP is just a part of the total WordPress stack. Equally important are Apache, which handles the actual requests from your web browser, and MySQL, where all the raw content for your pages, posts, products, and more are permanently stored. Apache is the first in the chain, handling all of the requests for all of your pages. It is responsible for routing the request to the proper PHP file, which in turn may invoke even more PHP files. In fact a single request may execute dozens or even hundreds of PHP files. MySQL is used for both reading and writing data during the execution of PHP code. It’s the permanent resting place for all of the text across your entire WordPress site.

Note: Apache and MySQL are the normal applications in the WordPress stack, but in fact both of these can be replaced with other applications. Nginx is a nice replacement for Apache, while MariaDB is an alternative to MySQL that you will see used a lot with WordPress.

Why You Should Be Using PHP 7

Even though Apache and MySQL (or their respective alternatives mentioned above) are critical to WordPress performance, a typical request in a WordPress site will spend most of its time executing PHP code. Therefore, the choice of PHP version is important.

Before we dive in, you should understand that there many PHP versions to choose from:

  • 5.2
  • 5.3
  • 5.4
  • 5.5
  • 5.6
  • 7.0

Note there is a version 7.1 but for the sake of this discussion we’ll only focus on PHP 7.

Wait, what happened to PHP 6? This is a great question, and this article sums it up best. Basically, one of the main objectives of PHP 6 was to add native support for Unicode. It turns out, this was a lot harder than the developers expected, and not a lot of people on the core team understood the issues and how to fix them. As the release of PHP 6 slipped over and over, the other new features were back ported to PHP 5 versions. Eventually the decision was made to scrap PHP 6 and let the different versions of PHP 5 live longer. And eventually, around 2015, PHP 7 was born.

So now that we know why they skipped a number, what is so great about PHP 7? First, all of the 5.x versions are old. Like, really old. It doesn’t make sense for the PHP community to continue to support all of these versions when everyone knows PHP 7 is the future. To that end, you should be using PHP 7 because eventually all of those 5.x versions will stop getting new features from the PHP team. And eventually after that, they’ll stop get security patches. In fact, all versions of PHP up to 5.6 have already reached what’s known as end-of-life in the software world. The PHP team will not be releasing any new code for those versions, no matter how bad of a security flaw they may find. You wouldn’t run your business on Windows 95, so why would you run your business website on an unsupported version of PHP?

Second, PHP 7 is lightning fast compared to the 5.x versions. Some estimates show that PHP 7 executes twice as fast as its predecessors in some cases. This means your pages and posts can be loaded faster, which means a better user experience. And we all know how much I care about WordPress performance. It also means working in the admin area of WordPress will be much faster for you and your developer.

Finally, PHP 7 adds a lot of new language features that WordPress theme and plugin developers can use. This won’t mean a lot to you as an end user. But under the hood it helps developers be more efficient and write better code. This helps with performance and code maintenance, which hopefully lends to a better experience for you, the non technical person who just wants their site to work.

Testing PHP 7 Compatibility

Ok, so you’re hopefully convinced that PHP 7 is awesome and something you want on your site. But should you upgrade? As mentioned above, PHP 7 removed a lot of old code and changed the way some things work. The core WordPress system has been vetted in terms of PHP 7 compatibility, and in fact will soon move to recommend PHP 7. But that doesn’t mean your theme and plugins have done the same.

Before you or your developer do anything, you need to be absolutely sure of your site’s PHP 7 compatibility. And it turns out, the nice folks at WPEngine have made this very easy. They released a free PHP 7 compatibility checker plugin which will scan all of the theme and plugin code on your site and highlight areas where the code may not be PHP 7 compatible.

Installing it is easy, and running the scan is just a few clicks. Once installed, you can find it under Tools -> PHP Compatibility. The start screen looks like this:

PHP 7 Compatibility Plugin Report

The plugin auto detects your available PHP versions. Select PHP 7.0 (or PHP 7.1 if you’re feeling really bold) and choose whether or not to scan inactive plugins (this will save time, but only choose it if your inactive plugins will remain inactive or be removed later). Then sit back and wait. The scan can take awhile, but rest assured your site is still available to visitors. In the end, you’ll get a report like this:
PHP 7 Compatibility Plugin Scan

Note that each plugin is given a color code: green, yellow, and red. These should be pretty self-explanatory, but green is good, yellow should make you slow down, and red should make you stop. The results can be any number of issues, far too many to enumerate here. Your developer or system support can help you dissect the results and tell you if you really need to be worried or if it’s worthwhile to proceed.

Keep in mind the PHP 7 compatibility checker does have some short-comings. First, it doesn’t execute any code, it simply does what’s called a static analysis. So it won’t detect 100% of issues that may arise, but it will catch most. And because it doesn’t execute code it can also identify false positives, or things that it thinks will not be compatible but probably are. They have a whitelist of plugins that are known to cause some false positives. Again, your developer or system support can help you understand the risk level based on what the report shows. In the case above, even though the plugin says Jupiter theme and Visual Composer are not compatible, I successfully migrated that particular site to PHP 7 without any issues.

What If The Plugin Finds Issues?

Even if the PHP 7 compatibility plugin finds issues, don’t fret. It might be a false positive, or it might be the developer of the theme or plugin in question has some nifty work around in the code that the plugin cannot detect. Either way, if you only see one or two issues, I recommend trying to migrate to PHP 7. In fact, if your host supports it, I would suggest moving to PHP 7.1. It’s compatible with PHP 7, and will reach end-of-life a lot later than 7.0. And really, most hosting providers make switching PHP versions very simple through cPanel. When in doubt contact your developer or support for precise instructions.

The important thing is that after you switch, make sure every aspect of your site works. If you run a WooCommerce shop, make sure you view some products and do a test order! If you blog, spot check a handful of articles and pages to make sure they look fine. If you have a contact form, make sure it works. If you have popups or ads, check them. Your developer can help you identify all the edge cases you should test based on the theme and plugins you have active. And I usually recommend doing this type of change during off hours when you get the least amount of traffic, just in case something goes wrong.

If you migrate to PHP 7 and find issues, you can always go back to the previous version without losing any data (you might lose a few visitors during the change if your site is not working, but you didn’t need them anyway). Again, this is usually a button click with most hosting providers, but make sure you understand how to fallback to the original version of PHP before you update to PHP 7. And it’s never a bad idea to take a backup of your site, just in case.

Recent Posts
New Website Feb 2017Pressable vs WPEngine
Verified by ExactMetrics