So you’re thinking of migrating from PHP 7.4 to PHP 8. But if you’re a seasoned coding pro you’ll know that when it comes to scripts and code, making big changes can be risky. So before you do anything, there’s a few things you need to keep in mind if you want to minimise that risk. That’s why we’re here with our checklist of tips and best practices for migrating to PHP 8. Let’s get started!

What is PHP?

PHP (PHP: Hypertext Preprocessor) is an open source, general purpose scripting language used for web development. PHP can modify data in your database, send and receive cookies, encrypt data, generate dynamic page content, and create, open, read, write, close and delete files on servers

PHP is the most widely used server-side programming language on the web, with around 79% of websites relying on PHP to some degree. This popularity can be attributed to multiple factors, including the fact that PHP runs on multiple platforms (such as Windows, Linux and macOS), integrates easily with HTML, and is compatible with a very wide range of servers and databases. Plus, PHP is free to download and use.

Thanks to all of these features, PHP is now the go-to server-side programming language compared to older alternatives like Perl. PHP users can also benefit from frequent updates, which ensure optimal performance, security and support. Each release branch of PHP (e.g. 8.1, 8.2, 8.3) is supported for three years, during which time bugs and security issues are identified and fixed. After this, a branch reaches its end of life and no longer receives any updates or community support.

Should you migrate to PHP 8?

The short answer? Most likely. One of the biggest reasons is that community support for 7.4 ended in November 2022. This means that, while you can still use it, you’ll be reliant on third-party support, and you also won’t benefit from any new security updates. This means your site will be more vulnerable to malware and cyber attacks if you still use an outdated version of PHP. PHP 8 also has improved performance over older versions, and brings bags of benefits with it.

But as with anything like this, whether or not you should migrate to PHP 8 is down to your own project needs – if you were making use of features that are deprecated in one of the PHP 8 release branches then you might not want to move.

Benefits of moving to PHP 8

Each new release of PHP boasts new features, security patches and performance improvements, and PHP 8 is no different. The one thing to consider is which version of PHP 8 you’d go for because they each have their own set of perks. Here’s a snippet of what they each offer:

Features of PHP 8.0

  • Just-In-Time (JIT) compiler
  • Attributes
  • Names Arguments
  • Match expressions
  • Developer-friendly improvements

Features of PHP 8.1

  • Enums
  • New array functions
  • The ‘never’ type
  • Readonly properties

Features of PHP 8.2

  • Readonly classes
  • Deprecated dynamic properties
  • Disjunctive Normal Form (DNF) types
  • Null, false and true as standalone types
  • New ‘Random’ extension

Features of PHP 8.3

  • Deep-cloning of readonly properties
  • Explicit typing of class constants
  • New #[\Override] attribute
  • New json_validate() function
  • New Randomizer::getBytesFromString() method
  • Command line linter supports multiple files

And that’s just for starters!

Curious to know what else PHP 8 has to offer? We’ve got a whole blog about the benefits of moving to PHP 8.

PHP 8.3

The latest version of PHP is PHP 8.3, which was released in November 2023. As with all PHP releases, PHP 8.3 brought significant performance improvements and bug fixes, in addition to extra features like new attributes and functions (see above). Since this is currently the latest version of PHP, it’s likely that you’ll want to upgrade straight to this version, unless you’re relying on features that are deprecated in this latest release. Using the latest version of PHP means you can benefit from the best support, frequent updates and better compatibility with the latest versions of other software and platforms (such as WordPress).

Tips for migrating to PHP 8

If you know code, you know things can break easily, sometimes all you have to do is look at it. So when you’re migrating PHP versions, you can imagine that there’s a lot that could go wrong if you don’t plan, prepare and research before you do anything. It might sound like a lot of hassle, but in reality a few steps can make a huge difference to how long your migration takes and how successful it is. Here’s our checklist of tips and best practices for moving to PHP 8 – you can thank us later.

Before you migrate

When moving your house, you spend time beforehand planning and getting stuff ready before you even load a box into the van, right? It’s the same with migrating to a different PHP version. Here’s an array of things you’ll want to make sure you do (see what we did there…):

1. Nail your timing

Plan, plan, and plan some more. You want to plan the migration for a time that won’t have a big impact on your project. For example, if you have sites reliant on PHP, you’re not going to want to be messing around with updates when your site is at its busiest. Aim for a quieter time, but also make sure either you're free or someone else is on hand in case something does go wrong.

2. Do some testing

If you're making changes yourself, or relying on an upstream application to do the heavy-lifting of migrating to PHP 8 for you, you’ll want to test your application. Focus on common and heavily-used functions first – but also don’t leave those rarely used scripts behind either (think about things that perhaps only run at a certain time of the year or are done occasionally). The trick with testing is to run your script on a representative platform, with real data (if possible) – making your tests as true-to-live as you can will give you a better idea if things will run correctly.

3. Back everything up

Now you know when you want to migrate to a newer PHP version, you need to make sure you back up your website or projects. If the newer version of PHP 8 clashes with your scripts and breaks something, you’re going to want a copy of your files that you can restore – we’re sure you don’t want to end up sitting there unpicking your scripts.

4. Update your software

Before you migrate to PHP 8, you need to make sure your software is up to date, like your CMS (WordPress, Joomla, etc.). That’s because if, for example, you’re using an older release of WordPress that doesn’t support PHP 8, and you decide to switch to PHP 8… well, let’s just say things could go bang (figuratively, of course!).

What we’re trying to say is that you’ll want to update anything that uses your PHP scripts to make sure that they can support the release you’re making the move to. If your software can’t support your PHP, then some stuff just won’t work.

5. Backward incompatible changes

We talked about some features that have been added in PHP 8 releases, but new releases don’t just have new features added to them, they also have older features removed and even some changed. So for instance, if you’re migrating from PHP 7.4 to 8.0, there are new reserved keywords, each() has been removed and the ability to use array_key_exists() has been removed and that barely touches the surface.

Thankfully PHP makes dev life a little easier by releasing an outline of backward incompatible features and deprecations when migrating from both 7.4 to 8.0 and 8.0 to 8.1.

After you migrate

You’ve done your checks, you’ve backed up your files and finally migrated to PHP 8 (mini celebration), now you need to make sure it all went to plan.

1. Checking scripts still work

We mentioned backward incompatible features and deprecations and you may think you’ve got that covered, but no matter how confident you are that you looked over everything, you should still check your scripts. We don’t need to tell you that if you’ve missed something and your code isn’t working, it’s not good. It could be something small, but if it isn’t you’ll thankfully have that backup we told you to create in case you need to revert back.

2. Checking site content still displays properly

Even if your code is working and is error-free, it’s a good idea to cast an eye over your web pages and make sure your site content is displaying as it should. If you find that there’s content missing, then something has gone wrong – an error message should explain what’s caused the issue.

3. Test everything (again)

Now you’ve checked your scripts in the backend and you’ve seen how it looks on the frontend, it might feel like you’re home safe. But – and it’s a big but – it’s still good practice to test everything again. Make sure your links are working, any functionalities are working as they should and check your plugins and site navigation. A good way of doing it is to use your site as you expect a visitor to, by clicking CTAs, scrolling and interacting with features.

How do you migrate to PHP 8?

If the techie stuff is a bit out of your comfort zone, don’t worry just yet. Migrating your PHP version doesn’t have to be complicated and thankfully, a lot of hosting providers have their own help guides to take you through it step by step – like us! And even if you’re a coding pro, you probably have a lot on your plate, without having to spend ages figuring out how to update your PHP.

If you’re a Fasthosts customer, you can find several guides in our knowledgebase that cover how to change your PHP version for your Web Hosting, WordPress Go, Plus and Advance packages as well as other WordPress Hosting packages.

If you need any extra help migrating to PHP 8, we have a whole Partner Network full of pros that can lend a helping hand.And don’t forget that we have our own team of experts here to help you 24/7 with your Fasthosts products. From your WordPress Hosting to your Dedicated Servers, we’re here to answer your questions.