logo-awesem-2023-colour
  • Home
  • About
  • Services
    • Hosting & Maintenance
    • Web Design & Development Projects
    • Support
    • Migrations
  • Case Studies
  • Blog
  • Contact
✕
  • Home
  • About
  • Services
    • Hosting & Maintenance
    • Web Design & Development Projects
    • Support
    • Migrations
  • Case Studies
  • Blog
  • Contact

How To Update Your WordPress Site To PHP 8

October 11, 2022
how to update php in wordpress

how to update php in wordpress

Here are AWESEM, we recently completed the upgrade of all our client sites to PHP 8. This is an important task. Having the latest and stable version of PHP keeps our client sites safe, secure and running efficiently.

The move from PHP 7.4 to PHP 8.0 has been one of the most complex so far due to the breaking changes introduced into PHP 8.0.

Any plugin or theme that contains incompatible code will cause a WordPress site to break.

In some cases, you might see an error like this on the front-end of your website:

critical error in WordPress

In other cases, problems won’t be apparent until you test the site more deeply.

Why update to PHP version 8?

There are three good reasons to always use the latest and most stable version of PHP:

  1. Security. Old versions of PHP that have reached their end of life phase are no longer supported. Security issues will not be patched. Any websites still using the old version will be vulnerable.
  2. Speed. Each new version of PHP comes with speed enhancements. Since PHP 5.6 there has been constant improvements and PHP 8 is no different. You will notice the boost in speed the most in your WordPress backend. If you have caching enabled on your site, the difference will be less apparent.
  3. Support. PHP 7.4 will cease to be supported from November 2022. Good web hosts will often force you to use PHP 8.0 because they must ensure that their own systems safe. If you are using shared hosting, they will also want to keep their other customers on the same server safe.

Which version of PHP do you currently have?

A quick way to find out what version of PHP you’re running is to pop over to your WordPress admin screen.

Here’s where to find it:

  • Open the WordPress admin dashboard
  • Go to Tools→Site Health
  • Click on the Info tab at the top
  • Expand the Server dropdown
  • You should see the PHP version further down the page
how to check php version in wordpress

How to check your WordPress site is compatible with PHP 8

Now you know which version of PHP you have running, how do you know it will be safe to upgrade?

Here’s how to find out:

  1. Create a staging site. The best way to check your WordPress site is fully compatible with PHP 8 is to create a staging site and then upgrade that site first.
  2. Run PHP in preview mode. At AWESEM, we recommend WPEngine hosting. WPEngine makes it very straightforward to test a site for different PHP versions using their preview tool. When you log into your WPEngine hosting account, you will see a Preview button which allows you to test your site in a different version of PHP. All other users will continue to view the site as usual. This gives you an opportunity to solve issues before you do the actual switch.
  3. Run a compatibility checker. Run your site through a PHP compatibility checker. Bear in mind that false positives may result due to plugin developers including old PHP code for backward compatibility.

How to upgrade your WordPress site to PHP 8

In many cases, the upgrade to PHP 8 will be straightforward.

If you have kept plugins to a minimum and have only current and well-supported plugins on your site, then most likely you can simply click the upgrade button and all will be well.

To make sure your migration is safe and doesn’t lead to downtime, here are the steps we recommend:

Step 1 – Backup your WordPress site

Before you do anything on your WordPress site, always run a backup. Depending on where you host your website, you may be able to do this easily in your host control panel.

Another option is to use a WordPress plugin such as Updraft Plus or BackupBuddy.

Step 2 – Update

Before you upgrade, make sure you have the latest version of all your plugins. theme and WordPress core.

Here’s a very useful article on how to do it the right way:

How to Update WordPress Safely – Complete Guide

Step 3 – Turn on PHP 8 preview mode (optional step)

Here are AWESEM, we are fans of WPEngine hosting. We love their Preview function, which gives us the ability to preview sites in different versions of PHP and reveal any issues without the danger of breaking anything.

This is done by simply clicking a button on the control panel and logging into the WordPress admin. In preview mode, you can use your website under your chosen PHP version. Normal users of the website will be unaffected.

Step 4 – Test test test!

If you have caching on your site, clear it, then open all the pages on your site and test all the functionality.

For example:

  • If you have a shop, create a test transaction.
  • If you have a contact form, check you receive the notification email.
  • If you have a booking site, create a test booking.

If your site breaks and shows a critical error message, here’s what to do.

Step 5 – Check the PHP error log

Your site may look fine, but the error log will reveal errors that might not be obvious.

You can usually find the PHP error log in your hosting account. When you open it up, look for any message that isn’t a warning or notice.

Step 6 – Switch

When you are sure all is well, it’s time to switch over to PHP 8. You can do this inside your hosting account. The exact method will vary depending on who your hosting provider is. Go to your hosting account admin area and should find it under as software or programming and then select PHP 8.

Going forward, keep an eye on the PHP error logs for any further issues.

Common PHP8 incompatibility issues

If you are a developer, this next bit is golden because we have documented the most common fixes we made across the many plugins and themes we have active on our client’s site.

Ideally, you should always contact the original developer of the theme or plugin. Sometimes this isn’t possible due to a plugin being unsupported or even abandoned.

Here is a summary of the most common issues we came across:

1. Call to undefined function create_function()

Create_function has been removed in PHP 8 and should be replaced with an anonymous function like this:

function() {}

2. Strings without quotes

Before PHP 8 unquoted strings would be assumed to be a string:

'order' => DESC

Now quotes are required:

'order' => 'DESC'

3. Implode parameter order

Before PHP 8 the parameters in the implode function could be in either order. In PHP 8 the $glue parameter must be first.

So this:

$where_str = implode( $where, ' AND ' );

should now be:

$where_str = implode( ' AND ', $where);

4. Type errors

In prior versions of PHP, strings containing valid numbers could be used as numbers implicitly. Strings should now be cast.

For example, before PHP 8 this would work:

$days = '2';

$price = 12.99;

$summ = $cost = $price / $days;

The string must now be properly cast:

$days = '2';

$price = 12.99;

$summ = $cost = $price / (int)$days;

See here for the full list of breaking changes

How to fix a WordPress critical error

If after upgrading to PHP 8, you see a critical error on your screen like the one below, and your site appears to be broken, what should you do?

critical error

Here’s our advice:

1. Downgrade to PHP 7.4

Yes, you can downgrade to earlier versions of PHP. Go back to your hosting account control panel and switch the PHP version back to the previous settings, e.g. PHP 7.4. If you don’t find the option, your host should help.

2. Check the PHP error log

The error log will tell you what caused the error, either your theme or a plugin. You should find the PHP error log available from your host control panel.

When you have the error log open, do a quick search for the words PHP Fatal.

Here’s an example error:

PHP Fatal error: Uncaught TypeError: implode(): Argument #2 ($array) must be of type ?array, string given in /wp-content/plugins/google-map-wp/includes/class-hugeit-maps-query.php:85

We can tell from this error that it is the plugin with the slug google-map-wp that is causing the issue.

Pop over to the plugin tab in your WordPress admin screen and click the View Details link next to the plugin name, and that should lead you to the plugin page at wordpress.org, or the developer’s own website.

3. Contact the developer

If the plugin is actively supported, then your best option is to contact the developer to let them know the error. They should fix the problem and issue an update, at which point you can then upgrade to PHP 8 safely.

If the plugin hasn’t been updated for a while or looks to be abandoned, the safest option going forward is to remove it, and find a replacement.

How to make upgrading to PHP easier next time

The best way to future-proof your WordPress website is to always select trusted and well-supported plugins and themes.

Other things you can do are:

  • Keep the number of plugins you have activated on your site to a minimum.
  • Keep an eye on the latest PHP versions and make a note of when they will reach end of life.
  • Start the upgrade process as early as you can so that plugin developers have time to resolve issues.

Need more help?

We appreciate that looking after your WordPress site can take a lot of time and effort.

Sign up to AWESEM’s site care plan so that you can focus on growing your business instead.

Frequently asked questions

Can I go back to PHP 7.4 if I find problems?

It depends on your host, but often it is possible to revert to an older version of PHP should you find issues that cause your site to break.

How long is PHP 7.4 supported?

PHP 7.4 was released on 28th Nov 2019. After the release date, it was actively supported for two years. In the third year after release, PHP versions are supported only for security issues. For PHP 7.4 that period is due to end on 28th November 2022. Any issues discovered after that date, will not be fixed.

Is WordPress compatible with PHP 8?

The latest release of WordPress core is compatible with PHP 8. Before you upgrade, make sure you have the most recent version of WordPress.

Is Woocommerce compatible with PHP 8?

The latest release of Woocommerce is compatible with PHP 8. Before you upgrade, make sure you have the most recent version of the plugin. Note that any plugins that extend Woocommerce functionality may not be compatible with PHP 8.

Share

Related posts

December 9, 2022

Why Your WordPress Website Needs a Maintenance Plan

October 9, 2022

Survive Black Friday Traffic Surges with a WordPress Maintenance Service

August 9, 2022

Why You Need PHP 7.4 Installed On Your WordPress Site

Ready to talk with us?

Get in touch with our team of WordPress experts today to discuss your upcoming project.
Whether you’re in the planning stages or ready to get started right away, we’re on hand to help.

hello@awesem.co.uk

+44 (0) 20 7193 1411

AWESEM Ltd
52 Grosvenor Gardens
London, SW1W 0AU, UK

Facebook

Twitter

LinkedIn

© 2023 AWESEM | All Rights Reserved | Powered by WordPress and WP Engine

Privacy Policy | Newsletter

    ✕
    • Home
    • About
    • Services
      • Hosting & Maintenance
      • Web Design & Development Projects
      • Support
      • Migrations
    • Case Studies
    • Blog
    • Contact

    We are using cookies to give you the best experience on our website.

    You can find out more about which cookies we are using or switch them off in .

    Privacy Overview

    This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

    Strictly Necessary Cookies

    Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.

    If you disable this cookie, we will not be able to save your preferences. This means that every time you visit this website you will need to enable or disable cookies again.

    3rd Party Cookies

    This website uses Google Analytics to collect anonymous information such as the number of visitors to the site, and the most popular pages.

    Keeping this cookie enabled helps us to improve our website.

    Please enable Strictly Necessary Cookies first so that we can save your preferences!