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:
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:
- 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.
- 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.
- 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 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:
- 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.
- 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.
- 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?
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.