How To Use PHP 7 In WordPress

PHP7 has released with many great new features and it will help your site. Learn how to use PHP 7 in your WordPress to make it faster

By Claudio Pires
Updated on October 4, 2022
How To Use PHP 7 In WordPress

PHP 7 was finally released some time ago with many great new features – and it will also help you keep your WordPress website in tip-top shape. See now how to use PHP 7 in your WordPress to make it faster.

PHP 7 is one of the most significant updates in the history of a server-side software that powers more than 82% of the internet, and, in this guide, we’ll discuss the ins and outs of using it with WordPress.

We’ll look at PHP 7’s incredible advantages and help you to understand the importance of adhering to the recommended minimum version (5.6). You’ll also learn to check whether your WordPress site is ready for PHP 7 and measure the pros and cons of upgrading to this new version.

How To Use PHP 7 In WordPress
How To Use PHP 7 In WordPress

At the end of this guide, you’ll be equipped with a firm understanding of PHP and convinced enough to update to the recommended minimum — or maybe even take the next step to PHP 7!

Let’s get started…

A Guide to using PHP: What Is it?

PHP is a server-side scripting language designed to generate HTML pages upon request for those new to the topic.
Think of it as a simple three-step process:

  • Input: You enter a set of commands written in the form of a PHP script as the input to the PHP Engine.
  • Processing: The PHP Engine executes the script on the server.
  • Output: The output is an HTML page rendered by the web browser.

In the three-step process described above, we can identify a few components.

  1. The PHP script(s)
  2. PHP Engine
  3. Server
  4. Output HTML

Now, let’s see how they relate to a typical WordPress environment.

1) PHP Scripts: WordPress is essentially a vast, organized collection of code written in multiple scripting languages, such as PHP, JavaScript, and CSS, with the primary one being PHP. It’s what gives WordPress its dynamic nature.

2) PHP Engine: Think of it as the central component that executes the instructions laid down in the PHP script — doing so with the help of the server it’s running on. The PHP Engine is one of the most crucial components and affects a website’s speed, performance, and reliability. It’s also the central topic of our discussion!

3) Server: This is the remote computer, also known as the ‘web host’, where your WordPress site is hosted. If there were a web host without PHP installed, WordPress would not run on it.

4) Output HTML: The PHP engine is summoned every time a WordPress website is loaded. Scripts are executed by the PHP engine using the server, and the final (or output) HTML is exported to the visitor’s web browser. And that’s what completes the process.

What Is PHP 7?

Now that we’re clear on a PHP script let’s talk about the PHP Engine. For the remainder of the article, we’ll use the terms ‘PHP engine’ and ‘PHP’ synonymously.

PHP 7, a PHP engine launched in December 2016, carries many new features, performance improvements, and security enhancements. As with every good lesson, let’s start with a bit of history.

A Brief History Of Php

How To Use PHP7 logo colors
How To Use PHP 7 In WordPress

PHP was released in 1994 as a scripting language by Rasmus Lerdorf to create a tool that would make updating his homepage easy. *Little did he know that this side-project would evolve to power more than 82% of all websites — including biggies such as *Facebook and WordPress.

Over the years, PHP has had a couple of releases. The first one was in 1995, followed by version 2.0 in 1997. Version 3.0 was released in 1998, followed by version 4.0 in 2000.

Is it the anticipation that makes PHP 7 special?

This is where things started to get interesting. PHP version 5 was released four years later, in 2004. It had multiple iterations — so much so that the committee decided to skip version 6 and jump to version 7. To put things into perspective, the first iteration of PHP 5 was version 5.0, released in 2004. Its last iteration, PHP 5.6, was released ten years later in 2014.

Two years later, PHP 7 came along — the most promising release of PHP to date. In essence, the world had to wait 12 years to get its hands on PHP 7.

Performance Improvements in PHP 7

The wait did not go to waste. PHP 7 came with a truckload of performance and security improvements. Let’s dig into each performance improvement backed by solid benchmarks.

1. Massively Improved Bandwidth (Requests Per Second)

PHP 7 performed nearly twice as well as PHP 5.6, running WordPress 4.1.1.

In the chart above, we can see almost 2.18 times the number of requests per second at less than half the latency.

2. Lower Latency For Concurrent Users

Latency is the time elapsed between the first request and the first response between the server and client. The lower the latency, the better the service. Let’s check out how PHP 7 handles it.

We’ve taken three data points based on the number of concurrent users for each PHP engine.

  1. The orange bars represent the latency when ten people simultaneously use your site.
  2. The blue bars are for double (i.e., 20 concurrent users).
  3. The pink bars are for 40 simultaneous users.

In all cases, PHP 7 knocks its predecessors out of the park.

*All of this in the *exact same hardware! This means that if you upgrade to PHP 7 with all the necessary compatibility checks in place (more on this later), you should see a two-fold increase in performance.

3. WordPress 4.0+ Releases Are Optimized For PHP 7

WordPress 4.0 itself has been fine-tuned to leverage PHP 7’s latest features. According to Zend, it has almost double the performance on the same hardware compared with its predecessor, WordPress 3.6.

In the chart above, we see a two-fold performance improvement in a major WordPress update. This benchmark is irrespective of the version of PHP. Rather, it indicates that the WordPress community is continuously optimizing code for the upcoming versions of PHP.

4. 75% Fewer Instructions, Same Result

PHP 7 also has a killer instruction set. It’s outrageously optimized for executing the same task in fewer instructions. For example, one WordPress request on PHP 5.6 runs in 100 million CPU instructions. In PHP 7, the same request is executed in 25 million CPU instructions. That’s a 75% reduction in the number of commands required to do the same job!

5. Significant Performance Gains

Jason Cosper, the resident nerd at WP Engine, loves messing with the latest PHP engines to see which ones work best.

In one of his experiments, he found PHP 7 to be arguably 6.6 times faster than PHP 5.5 — running WordPress 4.3.1 and bbPress.

State of WordPress PHP in 2022

In the past, PHP was considered a straightforward and “lightweight” solution. This is due to the ease of deployment and fast cycle from development to release. Even for relatively inexperienced programmers, your projects can be completed quickly.

State of WordPress PHP in 2022

This remains one of the greatest strengths of PHP today. Nonetheless, since the PHP 7.4 version is much more potent than its predecessor (update: PHP 8 to be released at the end of 2020), the number and variety of possibilities have increased dramatically. Why and how does this happen? Some updates are not critical and will only introduce incremental changes. Others, on the other hand, can completely redesign the entire product.

This happened to PHP when most new frameworks enabled PHP to do bigger and bigger things. Symfony, Laravel, Lamina, Yii, Cake, Code Igniter, and more. We use and love Yii2. This is our favorite, and because we admire it so much, we recommend that you use this framework.

PHP version stats

The framework comes with packages and products like an admin panel, CRM, web socket server, analyzer, payment integration, and queue manager – just to name a few. They created a specific ecosystem to make working with PHP faster and easier. This is necessary for the rapid development of the web, with more interactive functions, complex designs, and more prosperous functions.

You can go beyond content management systems like WordPress and do just about anything, combining the library of your choice with the framework that best suits the task at hand.

Comparing PHP 5 and PHP 7/8, it’s worth noting a 2 or 3x increase in performance (speed). As a result, most arguments against PHP have become obsolete over time. This means that the developer community behind PHP sees criticism as constructive feedback and improves it.

State of WordPress PHP in Q1 2018

usage PHP7 benefits advantages
How To Use PHP 7 In WordPress

Now that we have a functional understanding of the benefits of PHP 7 let’s take a look at how many WordPress users are using it.

The Good: According to the official WordPress stats, 9% of the WordPress community has upgraded to PHP 7 as of 20 April 2017.

Okay: Around 40% of WordPress users are using PHP 5.6. This is relatively good news since PHP 5.6 gets security support until 31 December 2018.

The Ugly: However, the terrible news is more than 50% of the active WordPress sites use a version of PHP older than 5.6, which exposes all these sites to severe vulnerability issues.

  • PHP 5.4 has not been patched since 2015.
  • And PHP 5.5 has not been patched since 2016.
  • If you’re using a version older than 5.6 (more on how to check your PHP version later), please update your PHP version immediately.

A Beacon Of Hope

Joost de Valk, founder of Yoast SEO — a WordPress SEO plugin with over 3 million active installations — decided to do something about this. To quote from the original article:

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.

WordPress And Outdated Versions Of PHP

At this point, it’s important to point out that WordPress will continue to support older versions of PHP. This does not mean you can sit back and relax. It’s best to upgrade to 5.6 — if not PHP 7.

If you’re on PHP 5.6, there are a couple of things coming your way soon:

  1. According to the official PHP support timeline, PHP 5.6 would get official support until 17 Jan 2017. That’s ended.
  2. In better news, PHP 5.6 would get security support until 31 December 2018.
  3. Of course, you’ll still be missing out on all the performance enhancements you could get for absolutely zero investment.

Switching to PHP 7: Is It Worth It?

Now that we have a firm understanding of the various advantages of PHP 7, let’s address the crucial question: Should you switch to PHP 7?

The method for arriving at any decision should be based on logic. We’ll look at tackling these three basic questions:

1. What Are The Advantages Of Switching To PHP 7?

We’ve covered five points backed by benchmarks from around the web. All of them point to a host of benefits and a resounding yes when it decides to switch.

2. Are Your WordPress Theme And Plugins Compatible With PHP 7?

Just because WordPress is compatible with PHP 7 (and has backward compatibility with PHP 5.6), does not mean all its themes and plugins are. You may use a custom-built theme or plugin with deprecated features in PHP 7. You may also use a plugin from the WordPress repository that’s not been updated for a while. What’s the solution?

3. How Can You Check If Your WordPress Site Is Ready For PHP 7?

Luckily, the generous developers at WP Engine have created a rather awesome plugin that solves this problem.

Introducing the PHP Compatibility Checker: A plugin that scans your WordPress codebase and active theme plugins looking for known compatibility issues.

Supported PHP versions of the PHP Compatibility Checker Plugin

You can check for compatibility issues for five distinct versions of PHP, ranging from 5.3 to 7.0.

The compatibility issues (if found) are categorized into errors and warnings. The plugin will list the file and line number of the offending code, along with information as to why that code is incompatible with the chosen version of PHP.

However, there are a few limitations:

  1. The plugin cannot detect runtime compatibility issues since it doesn’t execute existing themes and plugins.
  2. It relies on WP-Cron to scan files in the background, so WP-Cron must be enabled and working on the server.
  3. Occasionally, false positives are reported since the plugin cannot detect unused code paths that may be used for backward compatibility.

The sample list of plugins supported by PHP Compatibility Checker.

All in all, it’s a pretty neat plugin that can tell you whether or not your WordPress stack is prepared for the upgrade!

4. What Are The Dangers Of Not Switching To Use PHP 7?

The following three points explain the disadvantages of not upgrading to the recommended PHP 7. They also highlight some of the possible dangers of not upgrading to the required minimum version, PHP 5.6.

*4.1 Performance Drop:* First off, you’d miss out on at least a two-fold increase in performance without investing a single dime. And guess what? If you’re on PHP 5.2, it’s reported to be 400% slower than PHP 7!

4.2 Security Issues: PHP 5. x had many vulnerabilities duly patched with the newer versions. 2016 was a record year for PHP security vulnerabilities, with more than 100 issues reported, ranging from Denial of Service (DoS) to memory corruption, malicious code execution, and so on.

To give you an idea of how bad the situation is, PHP 5.4 hasn’t been patched since 2015, and it’s no longer supported. And yet 21% of WordPress users still use PHP 5.4! If you’re a part of that group, please update to 5.6 today.

4.3 Broken Plugins: An older, unsupported PHP version creates plugin conflicts. One of the most prominent errors is the ‘unexpected T_Function, ‘as seen below.

Screenshot of support thread of the Content Locker plugin

The above screenshot is a support query for the Content Locker plugin. The author mentions that the minimum version of PHP required for the plugin to work is 5.4.

5. Success Stories

Seeing how various global organizations benefit from the upgrade is always encouraging.

5.1. A Fortune Saved For Badoo

Our first example is the dating app Badoo, which has managed to save over $1 million by upgrading to PHP 7. How? Simple! PHP 7 reduced the computing power required to accomplish the same task. Thus, fewer servers were needed to do the same job, freeing up 300!

5.2. Major Performance Boost For Clinton Electronics

Our second success story comes from a WP Engine client, Clinton Electronics. In a nutshell, they wanted a dynamic e-commerce store with fast load times. The chosen stack was WordPress, along with WooCommerce. The agency they were working with chose a managed WordPress hosting provider, which, in turn, recommended PHP 7. This upgrade ultimately reduced the website’s load time by as much as 60%!

How to Switch to use PHP 7 with WordPress?

First, ensure your current WordPress stack is compatible with PHP 7 using the PHP Compatibility Checker plugin. Once the plugin gives you the green light, proceed with the upgrade.

  • Using shared WordPress hosting, such as Bluehost, you can update your PHP version in four simple steps. Almost all shared WordPress hosting providers come with a cPanel or a custom access panel wherein you can change the version of PHP.
  • If you’re using a managed WordPress hosting provider, such as WP Engine, switching to PHP 7 is a piece of cake — reach out to their support, and they’ll have it done in a jiffy.

The good news for WP Engine users is that the minimum allowed version of PHP is 5.6, according to their FAQ page.

Why WP Engine? There are a host of benefits that make WP Engine even more attractive:

  1. Innovative WordPress technology.
  2. Blazing fast servers capable of handling hundreds of millions of requests per day.
  3. Hardcore security with advanced DDoS protection.
  4. Superior support.

They’ve been in the business for a couple of years now and have won over top brands, such as National Geographic and AMD. What I like most about WP Engine is their culture of giving back to the community — be it sponsoring WordCamps, hosting events, or building awesome free plugins such as the PHP Compatibility Checker.

If you’re considering an upgrade or looking to change your current hosting provider, we would highly recommend WP Engine as your managed WordPress hosting provider, with plans starting at $29 a month.

Video Tutorials To Upgrade PHP Version in Different Hostings

Update PHP to 7 + Version in BlueHost
Update PHP to 7 + Version in HostGator
Update PHP to 7 + Version in JustHost
Update PHP to 7 + Version in SiteGround

Wrapping Up

Let’s quickly recap all that we’ve learned so far:

  1. PHP powers 82% of the internet, powering sites such as Facebook and WordPress.
  2. The recommended minimum version of PHP is 5.6 — anything below that is a big no-no!
  3. PHP 7 significantly improves performance, security, and features — it quickly increases WordPress’ performance by 2x with zero additional hardware.
  4. Switching WordPress to PHP 7 brings home many benefits without any investment.
  5. However, before switching, you must ensure your WordPress setup is ready to upgrade to PHP 7 using the PHP Compatibility Checker plugin.
  6. Shared hosts such as Bluehost support PHP 7, but it needs to be enabled manually.
  7. Managed WordPress hosts such as WP Engine have rock-solid compatibility with PHP 7.

At the end of the day, PHP improves with every release. If you’re using WordPress and only the popular plugins, you could gain a lot by upgrading to PHP 7. However, if you’re using a lot of custom or infrequently updated plugins, it’s best to hold on for a few more months before upgrading. However, you must use PHP 5.6 and nothing below that!

Already using PHP7 with WordPress? Thoughts?

Claudio Pires

Claudio Pires is the co-founder of Visualmodo, a renowned company in web development and design. With over 15 years of experience, Claudio has honed his skills in content creation, web development support, and senior web designer. A trilingual expert fluent in English, Portuguese, and Spanish, he brings a global perspective to his work. Beyond his professional endeavors, Claudio is an active YouTuber, sharing his insights and expertise with a broader audience. Based in Brazil, Claudio continues to push the boundaries of web design and digital content, making him a pivotal figure in the industry.