How to upgrade your version of PHP
If you’re running websites with an out-of-date version of PHP, we recommend that you upgrade to PHP 8 or beyond. A newer version is more likely to be protected from security vulnerabilities and attacks because the PHP community releases regular security patches and updates to known bugs. As well as the security updates, PHP 8 comes with many new features and increased performance. For example, if you use WordPress hosting, it can run much faster, thanks to its Just-In-Time (JIT) script compiler – which can execute complex code much faster than PHP 7 and other predecessors.
As with every PHP upgrade, older versions eventually phase out community support, hence why it’s important to make the upgrade. In this guide, we’ll cover what you need to do before upgrading to PHP 8 or higher, a snapshot of why upgrading PHP is important and how to check your current PHP version.
Things to know before you upgrade your PHP version
Changes made in the new version can affect code written in an old version. For example, a site written in PHP 5.4 might break when upgraded to PHP 5.6 because of the difference between the versions. Some functions work differently in the two versions because there are new functions, and functions that have been removed, which could cause your website to break after the upgrade.
As well as functions, there are a range of backwards incompatible changes between a new version and an earlier version which could cause a breakage. These could include changes to parameters, scripts, methods and directives.
PHP 7
PHP 7 helps to tighten up a lot of code, making it easier and more secure to code efficiently. This means that some redundant functions were removed. Features like the new null coalescing operator were added to make code easier to manage and more robust.
With PHP 7 ext/mysql functions were removed, which changed the way MySQL API works, they also removed support for ASP and script tags <%, <%= and <script language=”php”>. Also, it is no longer possible to have two parameters with the same name within a function, and the JSON extension was replaced with JSOND which requires that numbers within JSON must not end in a decimal point.
These minor changes between versions could cause disruptions to a website, so it’s recommended that you look at what’s changed before you upgrade your version, to ensure that your website will still work on a newer version of PHP. We have produced guides that will help with the migration from PHP 5.2 to 5.6, and from PHP 5.4 to 5.6, as well as a guide to help with the upgrade to PHP 7.
Benefits of upgrading to PHP 8 and beyond
If you’re upgrading to PHP 8, 8.1, 8.2, 8.3 or 8.4 (when it’s released), you’ll enjoy benefits such as:
- “Enums” (or “Enumerated Types”)
- New array functions
- A new ‘never’ type (previously known as ‘noreturn’, which stops program flow
- JIT code compiler
- Attributes (also known as annotations)
- Named arguments
- Match expressions
- A nullsafe operator that checks if code can be executed without errors.
Besides these new and improved features, there are some serious benefits to updating your version of PHP in general.
- Security: Newer PHP versions fix vulnerabilities and security issues found in older releases. Plus, upgrading prevents hackers from exploiting any known bugs that may have been exploited previously.
- Improved performance: PHP developers are continuously optimising and improving performance with each release.
- Compatibility: Updating PHP ensures compatibility with newer libraries, frameworks, hosting environments, and the latest MariaDB or MySQL versions.
Step-by-step guide to upgrading your version of PHP
There are various best practices to follow when migrating to PHP 8 and beyond. Assuming you’re using WordPress, we recommend setting up a testing environment should your upgrade not go as planned. Once that’s done, just follow the steps below to upgrade your version of PHP.
1. Back up your website
Things go wrong at the worst of times. To prevent this, simply create a backup of your website in case you need to restore it. This is especially true if you utilise CMS platforms like WordPress, as themes and plugins are written in PHP. If there are even minor errors in the script, you’ll experience serious issues which could make your site unusable.
2. Update your plugins and themes
Before upgrading your version of PHP, you’ll need to ensure any plugins and custom themes you used are compatible with the new version too. On WordPress navigate to Dashboard, then Updates – where you’ll see a list of plugins and themes that require an update.
3. Use a PHP compatibility checker
WordPress has its own PHP compatibility checker, which lets you test your plugins and themes to see if they’re compatible with the latest version of PHP.
Install the PHP compatibility checker as you would with other plugins, select the latest version of PHP within the plugin, and make it scan all installed plugins. If there's a problem with compatibility, consider finding an alternative theme or plugin, or contacting the developer to see what can be done if the theme or plugin is critical for your site.
4. Upgrade your PHP
This can be done via the control panel (cPanel or Plesk for example) – simply navigate to the software section of your chosen control panel and you’ll see an option to pick the latest PHP version.
Ready to upgrade your PHP version?
If you are a Fasthosts web hosting customer you can upgrade your version of PHP with our guide. We recently wrote about how PHP powers WordPress, and how important it is to keep your software up-to-date. For help updating WordPress, read this article on our support site, and watch this video on our YouTube channel.