How to Update PHP to the Recommended Version for WordPress
Using an outdated version of WordPress core, plugins or themes isn’t ideal. PHP is no different.
While WordPress technically works with PHP 5.6 and above, you’re sacrificing performance and compatibility, plus you’re open to security vulnerabilities by using older PHP versions. You should always aim to use the latest version of PHP.
In this post, you’ll learn everything you need to check what version of PHP you are running and how to update your PHP to the recommended version for WordPress.
What is PHP
PHP can do things like calculations, process conditional logic and pull information from the database so you can take a dynamic approach to build your webpages.
If you look in your WordPress site’s files, you’ll see a lot of PHP files. These are the instructions that your server uses to build not only the webpages your visitor sees but also the WordPress admin backend. PHP is a major part of WordPress. PHP is a major part of the whole web, actually. It powers 70% of all websites.
WordPress PHP Version
You may recall that somewhat recently there was a big push to get everyone to upgrade WordPress to PHP 7. While it may have felt recent, that was a while ago. PHP has to be updated on a regular basis, just like WordPress core, themes, and plugins.
With PHP, each version receives support for two years after its initial release, then there is a period of another year where critical security updates are released as they’re needed. After this three year period, that version of PHP is no longer updated.
As of June 2019, when I’m writing this post, the current recommended PHP version for WordPress is 7.3 or greater.
The majority of quality hosting providers will require you to use the latest version of PHP in order to use their servers and will help you modify your site to ensure that the latest version of PHP will not break your site.
WPMU DEV Hosting, for instance, has your back and uses the latest PHP version automatically.
Less reputable cheap hosts will not take the initiative to encourage you to upgrade your PHP because of the additional cost of support time and resources to help you transition. Since they don’t want to break your site by updating to the latest version of PHP automatically, they’ll often leave your site to use an outdated version of PHP and hope you don’t notice.
This practice is quite common and most WordPress sites aren’t using the most recent version of PHP as a result. Take a look at these WordPress statistics:
- 4.4% of WordPress sites are using PHP version 7.3
- 18.4% of WordPress sites are using PHP version 7.2
- 13.2% of WordPress sites are using PHP version 7.1
- 16.9% of WordPress sites are using PHP version 7.0
PHP 7.0 made it’s debut on December 2015 and using our three-year rule, then we know it reached the end of its lifecycle in December 2018. This means 64% of WordPress sites are running a version of PHP that is no longer being actively supported and that’s problematic for several reasons.
Why you need to update PHP
For one, there are tremendous performance benefits that come with using the latest version. PHP 7.3 requires less time and resources to deliver the same number of requests to site visitors. It can handle as much as 3x as many requests per second as PHP 5.6.
According to this infographic, PHP 5.6 executes one WordPress request in just under 100M CPU instructions, while PHP 7 does the same using 25M CPU instructions, and PHP 7.3 uses even fewer. That’s a huge improvement that also goes a long way toward reducing memory usage on your host as well.
Since using the latest version of PHP takes less time to serve the same number of requests, you can give your visitor’s a much better user experience.
Ensuring Compatibility is Costly
Maintaining code takes effort, and that effort is multiplied when you need to ensure backward compatibility for additional versions.
No wonder people (probably overworked theme and plugin developers) at WordCamp US 2018 cheered when Matt Mullenweg proposed a plan to make PHP 7.0 the minimum required version by “as early as” December 2019.
Sometimes new versions of PHP introduce new features, such as error handling or new operators, as was the case with PHP 7. Other times, functions are deprecated or changed.
Rather than spending time parsing through the code to ensure that any changes to PHP do not affect the code, developers can spend their time adding new features or improving security instead.
Just like plugins, themes and WordPress core get updates to fix security vulnerabilities, so does PHP. This is also why using a PHP version that is still getting updates is so important, as it protects you from vulnerabilities such as SQL injection, XSS and Dos attacks.
According to security vulnerability datasource CVE Details, there were 18 known vulnerabilities found in PHP in 2018. Compare this to the 43 vulnerabilities discovered in 2017 and the 107 found in 2016 and you can see why updating can help protect you from a lot known security exploits.
As a matter of fact, some hackers look to see what version of PHP you’re running in order to know what kind of attack would be effective.
How to Check PHP Version in WordPress
So how do you find out what version of PHP your site is using? Easy. You can see this information right within WordPress.
Go to Tools > Site Health
If your site is not using the latest version of PHP, then it will be shown as a recommended improvement.
If it is, then open the passed tests section to verify. You’ll see that is says PHP is up to date plus what version you’re running.
How to Update PHP with cPanel
cPanel, or some variation of the tool, is the most recognizable hosting management dashboard interface. You will find it on most shared hosts. Most managed hosting solutions and enterprise-level providers create custom dashboards that are designed to optimize their user’s experience.
That said, if you are needing to update PHP for yourself, you are probably on a shared hosting plan and this video will most likely do the trick. If your host doesn’t use cPanel you can jump to the next section.
How to Update PHP in WordPress
Once you check to see what version of PHP your hosting server is running, you’ll know if you need to upgrade to the latest version of PHP.
If you do, you’ll first need to see if your site will be compatible with the new version of PHP. You never want to test major changes like updating your PHP on your live site because if there are major incompatibilities, you’ll damage your site.
For this reason, you’ll need to create an alternate site to test your changes on first.
Step 1: Create a Copy of Your Site
You’ll first need to get a copy of your current site. You’ll need all of the files and a copy of the database. You can use SFTP for your files and export a copy of your database using MyPHP.
In some instances, you may be able to use your last backup, if your backups include both the files and the database.
Step 2: Create a Local or Staging Site
Once you have a copy of your site, you’ll need to set up a testing environment. You can either use a local environment or set up a staging environment if your host allows it.
See our post on how to set up XAMPP on your local computer if you need help setting up your local environment.
Once your testing environment is set up, you can add the files and database from the previous step to your testing environment, so you have an exact replica of your live site.
Then once you have a copy of your site in your testing environment set up, you’re ready to upgrade the PHP version of your testing site.
Check PHP Compatibility
Now comes the fun part, and by fun, I actually mean when the boring action happens.
You’ll need to go through your test site to make sure that nothing is broken. You’ll want to pay extra careful attention to the critical functionality of your site. Checkout processes, newsletter signups, web forms, navigation, and all of the other elements that contribute to the bottom line.
You want to catch these issues before they have a chance to wreak havoc on your live site and cause a bad user experience for your visitors.
Checking PHP Compatibility with Tools
There are some tools that can help you with this process.
PHP Compatibility Checker – This plugin is often recommended to help you scan your site for incompatibility issues. Unfortunately, it hasn’t been updated to be able to test PHP 7.3. It also is known to flag false positives, so be sure to double check incompatibilities manually.
Error Log Monitor – This plugin will display a list of PHP errors in your WordPress dashboard which will help you diagnose the issues if you’re a developer. If you’re not a developer then it will help you relay the issue to support.
WP_DEBUG – WP_DEBUG is a PHP constant (a permanent global variable) that can be used to trigger the “debug” mode throughout WordPress. To turn on debugging in WordPress, set the WP_DEBUG variable to true. You can find it in the wp-config.php file. Check out our other post on Debugging WordPress: How to Use WP_DEBUG.
If a plugin or your theme is causing issues, work out the issue on your test site. Find a suitable alternative that is compatible with the latest version of PHP. Once you’ve found a solution, be sure to also make the change to your live site.
When you’re looking for a suitable plugin in the WordPress repo, check to see what versions of PHP are supported.
How to Update PHP Version in WordPress
Once you’ve worked through all of the bugs and issues with compatibility, and have made the corresponding changes to your live site, then you can switch over your live site to the new version of PHP.
This process will vary from host to host, but will most likely involve changing a setting in your hosting cPanel. Ask your host for help on how to do this as some shared hosts will not let you access this setting.
Here’s a list with instructions to how to update the PHP version for 32 different hosts including popular hosts such as WP Engine, Pantheon, Kinsta, Pagely, Bluehost, Hostgator, GoDaddy and more.
If you never want to deal with having to update your PHP version, why not give WPMU DEV hosting a try and leave all the technical stuff to us.
Partnering with Your Host to Update PHP Version
Cheap shared hosting has convinced a lot of people that hosting websites is a simple and straightforward process, but the truth is, there is a lot that goes into maintaining your site files and database. Keeping all of your software up-to-date is one of the tasks that your host can and should help you with. If they’re unwilling to help you or hide your version to keep you in the dark, then that’s generally a sign that it’s time for you to switch hosts to something better.
At WPMU DEV, members get hosting for 3 free sites (even multisite) included with a monthly membership. Not only do we help you update your PHP version, we also backup your site daily, assist with caching configuration and monitor uptime. And if you ever need help fixing compatibility issues with your theme or plugins, our awesome support team is ready and willing to help. Sign up for a free 7-day membership to try everything out.
WIN a Share of $5K
Subscribe to our blog this #hostingmonth for a chance to win one of 5 prizes of $1,000 WPMU Dev credit! Learn More.