Security support for PHP 7.4 ends on 28 November 2022 – this is the PHP 7.4 EOL (end of life) date. After that, the PHP developers won’t release any more fixes for it, even if a serious, remotely exploitable bug is found in it. 7.4 is the last version of the 7 branch, and it is still very common in web hosting: many WordPress, Joomla and custom PHP sites run on it, because until now there was no compelling reason to switch.
Now is the time. In this article, we sum up which version is worth moving to, what tends to break, and how best to do the upgrade.
PHP version support in autumn 2022
Every PHP release gets two years of active support (bug fixes), then one more year of security fixes only.
| Version | End of active support | End of security support | Status now |
|---|---|---|---|
| 7.3 | 6 December 2020 | 6 December 2021 | Unsupported |
| 7.4 | 28 November 2021 | 28 November 2022 | Security fixes only, for two months |
| 8.0 | 26 November 2022 | 26 November 2023 | Active; security fixes only from November |
| 8.1 | 25 November 2023 | 25 November 2024 | Active |
| 8.2 | – | – | Release candidate (RC), expected at the end of the year |
The table shows that PHP 8.0 isn’t a good target either: it expires barely a year after 7.4. If you upgrade now, PHP 8.1 is the realistic choice, receiving fixes until November 2024. 8.2 is worth using in production once it has been released and your application and its extensions support it.
What does PHP 7.4 EOL mean in practice?
On 1 December, your site will work just as it did on 27 November. The risk grows slowly: every newly discovered PHP bug stays unfixed, and software vendors are also gradually phasing out support for 7.4. New versions of WordPress plugins, Composer packages and frameworks increasingly require at least PHP 8.0, so a site stuck on 7.4 can’t even install its own updates.
There is one important exception. Linux distributions backport security fixes into their own packages for the package’s full support period:
- The
php:7.4module of RHEL 8 (and so of AlmaLinux 8 and Rocky Linux 8) receives fixes for the full lifetime of RHEL 8, according to Red Hat’s Application Streams life cycle table. - Ubuntu 20.04 LTS and Debian 11 also ship PHP 7.4, with the distribution’s own security support.
- CloudLinux’s alt-php packages also provide security fixes for expired PHP versions.
So if your server uses the distribution’s own PHP 7.4, it will still receive security updates after 28 November. This only applies to the PHP interpreter, though: it doesn’t extend support for the applications and extensions built on it. If, on the other hand, you installed PHP from the php.net sources or from a third-party repository, no more fixes will come from there.
What can break when moving to PHP 8?
8.0 is a major version change, so some things are not backward compatible. The most common errors we come across in older code:
- Stricter error handling. Many former warnings have become exceptions. If an internal function receives a parameter of the wrong type, a
TypeErroris thrown, and the page stops with a white screen or a 500 error where previously only a line was written to the log. - Comparing numbers and strings works differently. In PHP 8,
0 == "something"is now false. This rarely causes a visible error, but in permission or validity checks it can be an unpleasant surprise. - Removed functions and syntax:
create_function(),each(), curly brace string offsets ($str{0}), therealtype name,money_format()and several other items long marked as deprecated. - Deprecation warnings in 8.1. Passing
nullto an internal function that expects a string (for examplestrlen(null)) is deprecated in 8.1. This isn’t an error yet, but it can produce a huge number of log entries.
Current versions of the popular content management systems (WordPress, Joomla, Drupal) run on PHP 8.1. The trouble is typically with old plugins, themes and custom-developed code.
How to upgrade, step by step
1. Inventory
First, find out which site runs on which PHP version. On a cPanel server, MultiPHP Manager in WHM shows this, and from the command line:
whmapi1 php_get_vhost_versions | grep -E 'vhost:|version:'
On other servers, look at the PHP-FPM pools and the web server configuration, as well as the versions installed on the machine:
php -v
ls /etc/php/ 2>/dev/null; ls /opt/remi/ 2>/dev/null
2. Update the CMS and the plugins
Most errors can already be fixed in the 7.4 environment: update the CMS core, the plugins and the theme to the latest version. Anything that hasn’t had an update for years should be replaced – it’s a risk anyway.
3. Test on a copy
Make a copy of the site (for example on a subdomain or a test server), and switch it to PHP 8.1 there. Turn on detailed error logging:
error_reporting = E_ALL
log_errors = On
display_errors = Off
Click through the site’s important functions – login, forms, cart, payment, admin interface – and go through the log. For custom-developed code, static analysers (such as PHPStan) and automated refactoring tools (such as Rector) also help a lot.
4. Switch over in production
On cPanel hosting, this can be set separately for each domain in MultiPHP Manager or in CloudLinux’s PHP Selector, so sites can switch one by one, with little risk. We wrote about this in more detail in our article multiple PHP versions on one cPanel account. After switching, watch the logs for a few days, and make sure you can roll back.
If a site can’t be upgraded
Sometimes an old, custom-developed system can’t be rewritten quickly. In that case:
- run it on a PHP 7.4 that still receives backported security fixes (a distribution package or CloudLinux alt-php),
- isolate it: its own user, its own PHP-FPM pool, and if possible its own server or container,
- restrict access (for example to the admin interface, by IP address),
- and set a deadline for replacing it. Isolation buys time, but it isn’t a solution.
If you combine the upgrade with a server replacement, bear in mind that AlmaLinux 9 ships PHP 8.0 by default, and older versions have to be installed from a separate repository. We summed up what’s new in AlmaLinux 9 on the blog of aWh, our hosting brand.
Checklist before 28 November
- Inventory: which site runs on which PHP version, and where the PHP comes from.
- Update the CMS, plugins and themes to the latest version.
- Test on PHP 8.1 on a copy, with detailed logging.
- Fix the custom code based on the log.
- Switch over in production, site by site, watching the log.
- Whatever stays on 7.4: isolation and a replacement deadline.
We help hosting providers run and upgrade cPanel, CloudLinux and PHP environments; you can read about this on the For hosting providers page.