Local and PHP 8

Local Beta 5.9.7 was the first build of Local to include PHP 8 and now, the latest version of Local includes it too!

While most things should work with the latest version of WordPress, there are some edge-cases to be aware of. Keep reading for more details!

Why Should I Upgrade to PHP 8?

It’s a good question, and the process isn’t easy due to so many breaking changes. The main reason is the significant performance improvements related to the just-in-time compilation. Some benchmark tests show improvements of almost 3 times as fast!

Beyond the performance improvements, there are many changes to the language that make it easier to write fast, bug-free code.

One specific example is that many PHP notices will now be warnings. While you might initially think this is a bad thing – the benefit is that these warnings are more informative and allow developers to find and fix issues early in the process!

To get a better idea of all the PHP language changes viewed through a WordPress lens, look at the “Changes in PHP 8” section of the WordPress and PHP 8.0 post of the core make blog.

Does PHP 8 work with WordPress?

Yes! Sort of…

Because PHP 8 has several breaking changes, the WordPress core developers have introduced a concept of WordPress being “Beta Compatible” with PHP 8.

This means that the most recent WordPress versions (5.6 and later) are compatible, but given the large ecosystem of Plugins and Themes, “WordPress” isn’t 100% compatible.

Again the WordPress and PHP 8.0 post on the core make blog does a great job of highlighting what being “PHP 8 Compatible” means, so definitely take a look!

Local and PHP 8

Okay, so WordPress core’s compatibility with PHP 8 is in a pretty good state – how do I test my site to see if it works with this new version of PHP?

Since WordPress is only “Beta Compatible”, PHP 7 is still the default version used for Preferred environments.

That being said, the latest beta version of Local allows you to select PHP 8 for custom environments. You also can change the PHP version of existing sites from the site details page.

Screenshot showing how to select PHP 8 from the Custom Environment section of creating a new site.
Screenshot showing how to change to PHP 8 from the site overview page.

Don’t Forget (aka Limitations)

While testing a site under PHP 8, it’s important to remember a couple of things:

  1. Only the latest version of WordPress will work. This includes working with a site using wp-cli — you’ll need to have at least the 5.6 version of WordPress core.
  2. Just because WordPress Core works with PHP 8, doesn’t mean that all Plugins and Themes will. Many plugins and themes have new versions that support PHP 8, but not all of them. Be sure to update and test!
  3. No ImageMagick. WordPress core has some good fallbacks, so this shouldn’t stop you from uploading media to WordPress. However, if your plugin or theme has this requirement, you’ll need to wait until ImageMagick releases a PHP 8 compatible package. See this Github Issue for more info:

Basically, take a backup of your site, update everything to their latest version, and see if anything breaks!

This Sounds Like a lot of Work

You’re not wrong that a lot is going on and that PHP 8 breaks a number of things.

If you’re wanting to get a high-level look at what you’re getting into, one of the best case studies I’ve seen was published by Yoast, where they reviewed what it took to get yoast.com to be compatible with PHP 8:

So yeah, if you’re overwhelmed, you’re not alone – but updating to the latest version of PHP 8 doesn’t have to happen right now. If you’re not as technical and afraid of breaking things, you can wait a bit before diving in.

Users who are more technical or are maintaining plugins or themes, see the resources section for some tools that can help with this process!

Either way, when using Local, it’s easy to export your site to have a backup. Using that backup, you can import it into as many new PHP 8 environments as you like! Anything you break in these sandboxes can be deleted without breaking things on your live site!

Resources