Workik.

PHP2Shell Response Guide: Patch, Mitigate and Harden PHP

End-of-Life PHP: Backports or Upgrading to PHP 8.4

Compare distribution backports, source builds, and upgrades for end-of-life PHP 5.4 to 8.1, and check code compatibility for PHP 8.4 or 8.5.

Running end-of-life (EOL) PHP during the PHP2Shell response puts you in a tight spot. While actively supported versions received official releases for CVE-2026-109618 and CVE-2026-109619 on 21 October 2026, older systems require a different strategy. At Brightline Logistics, the internal brightline-invoicing application runs on PHP 7.4 on Red Hat Enterprise Linux (RHEL) 8, while brightline-www runs on PHP 8.1 on Ubuntu 22.04. Both PHP 7.4 and 8.1 are end-of-life upstream, yet your team must secure both without breaking production.

Previous lesson: Detect PHP2Shell Exploitation Attempts in Your Logs | Next lesson: Harden PHP and PHP-FPM Configuration


Upstream PHP Status for 5.4 Through 8.1

Researchers traced the vulnerable code behind PHP2Shell back to PHP 5.4.0. However, the PHP project only publishes full packaged releases for actively supported branches.

Here is how upstream PHP handled older versions during the October 2026 release:

  • PHP 5.4 to 7.3: End-of-life. There is no fix and no source patch from the PHP project.
  • PHP 7.4, 8.0, and 8.1: End-of-life. There are no official new release packages, but the PHP security team published minimal source backports for teams that build PHP from source.
  • PHP 8.2 to 8.5: Supported. Official patched releases are available, and the newest are 8.2.36, 8.3.37, 8.4.28, and 8.5.13.

If your server runs PHP 8.1 or older, you cannot simply pull a new official release tarball or official Docker tag from the PHP project. You have to choose between three survival paths.


Three Paths for End-of-Life PHP: Distro Patches, Source Backports, or Upgrading

When an upstream PHP version reaches end-of-life, your options depend on how you installed PHP and whether your operating system (OS) is still under long-term support (LTS).

ApproachHow It WorksBest ForKey Drawback
Distro or LTS Vendor PatchYour OS vendor backports the fix into their existing PHP packageSupported OS releases like Ubuntu 22.04 (brightline-www)Only works if you use the OS vendor's default packages
Source BackportYou compile PHP yourself using the PHP security team's minimal patchCustom builds on PHP 7.4, 8.0, or 8.1 where you cannot upgradeYou now own all future compilation and security patching
Upgrade to PHP 8.4 or 8.5You migrate the application to a modern, supported PHP branchLong-term safety for legacy apps like brightline-invoicingRequires code and dependency compatibility testing

Path 1: Distribution and LTS Vendor Patches

Linux distributions and commercial LTS vendors received the PHP2Shell patches in advance of the 21 October disclosure. If your OS release is still supported, the vendor often backports the security fix into the older PHP version they ship.

For example, Ubuntu 22.04 ships PHP 8.1. Even though PHP 8.1 is end-of-life at the PHP project, Canonical maintains the Ubuntu 22.04 package and issues security notices for it. This is the route brightline-www follows in Lesson 3.

Common Mistake: Assuming a third-party repository on a supported OS behaves like an official OS repository. If you installed PHP 7.4 on RHEL 8 using an unsupported third-party repository or a custom container image, Red Hat's patches will not cover it. Always check your vendor's current security notice to confirm coverage.

Path 2: Building from Source with Minimal Backports

For PHP 7.4, 8.0, and 8.1 installations that do not receive vendor patches, the PHP security team provided minimal source backports. To use these, you must download the PHP source code for your version, apply the diff file for CVE-2026-109618 and CVE-2026-109619, and compile the binaries with your exact configuration flags.

Think of compiling from a source backport like machining a spare part for a discontinued truck engine. It gets the vehicle moving today, but you become the factory responsible for making every part that breaks tomorrow.

Only choose this path as a short bridge if an application is too fragile to upgrade immediately and has no vendor package fix.

Path 3: Upgrading to a Supported PHP Branch

Upgrading to an actively supported PHP version is the only permanent solution. Before you start an upgrade for brightline-invoicing, take the immediate precaution recommended by the Computer Emergency Response Team for the European Union (CERT-EU): isolate the application from public networks. Since brightline-invoicing is an internal tool on PHP 7.4, restrict access to your internal virtual private network (VPN) and apply the configuration mitigations from Lesson 4 while you prepare the upgrade.


Choosing Your Target PHP Version

Do not spend days upgrading a legacy app from PHP 7.4 to PHP 8.2 just because 8.2 looks closer. Look at the official PHP security support end dates per the PHP release cycle:

  • PHP 8.2: Security support ends 31 December 2026.
  • PHP 8.3: Security support ends 31 December 2027.
  • PHP 8.4: Security support ends 31 December 2028.
  • PHP 8.5: Security support ends 31 December 2029.
  • PHP 8.6: Released 19 November 2026. Under PHP's four-year support policy, it is expected to receive security fixes until the end of 2030.

PHP 8.2 loses security support on 31 December 2026, so upgrading to it now leaves you back in an end-of-life state within weeks.

Target PHP 8.4 or PHP 8.5 for any upgrade project. PHP 8.4 has wide library support across the ecosystem and gives you protection until the end of 2028. PHP 8.6 is the newest release, but give frameworks and libraries a few months to add support before you move a legacy app straight to it.


Checking Code Compatibility with PHPCompatibility and Composer

Jumping from PHP 7.4 to PHP 8.4 introduces breaking changes, such as stricter type checks, removed functions, and the deprecation of dynamic class properties. You do not need to guess what will break in brightline-invoicing. You can scan the codebase and dependencies in minutes.

Step 1: Check Composer Dependencies

Before changing your application code, check if your third-party packages support PHP 8.4. Run Composer's why-not command in your project root:

bash
Copy

This command outputs a list of packages in your composer.lock file that require an older PHP version. You can then test upgrading those specific packages in a separate git branch.

Step 2: Scan Application Code with PHPCompatibility

PHPCompatibility is a standard for PHP_CodeSniffer that detects deprecated or removed PHP features in your code. You can install it as a development dependency or run it from a separate tool directory so it does not conflict with your older project dependencies:

bash
Copy

At the time of writing, the latest stable PHPCompatibility release (9.3.5) was published before PHP 8 and does not check PHP 8 changes. That is why the command above installs the 10.x pre-release, which does.

The scanner prints exact file names and line numbers that will fail on PHP 8.4.

Pro Tip: Use the --report=summary flag first on large legacy codebases. It gives you a quick count of errors and warnings by category so you can estimate how many hours the upgrade will take.


Automating the Upgrade with Rector

Once you know what needs to change, you do not have to edit hundreds of files by hand. Rector is a static analysis tool that automatically refactors PHP code to match newer language versions.

Install Rector as a development dependency of brightline-invoicing, then create a rector.php configuration file in the project root:

bash
Copy
php
Copy

Always run Rector in dry-run mode first to preview the diff without modifying files:

bash
Copy

Here is one change you will meet when moving from PHP 7.4 to PHP 8.4. Since PHP 8.0, declaring an optional parameter before a required one is deprecated, and PHP treats the optional parameter as required anyway. PHPCompatibility flags it, and you fix it by removing the misleading default value.

Before:

php
Copy

After:

php
Copy

After Rector applies its changes and you update your Composer dependencies, run your automated test suite against PHP 8.4.28 or later in your continuous integration (CI) pipeline before deploying to production.


Try It Yourself

Run an upgrade readiness check on one of your own PHP repositories (or a test project) without altering any production files:

  1. Open a terminal in your project root and run composer why-not php 8.4 to identify any third-party packages that block a PHP 8.4 upgrade.
  2. Set up the temporary /tmp/phpcs-audit directory shown earlier and run phpcs with --standard=PHPCompatibility and --runtime-set testVersion 8.4 against your src or app directory.
  3. Review the output and list the top three compatibility issues that block your codebase from running on PHP 8.4.

In the next lesson, Harden PHP and PHP-FPM Configuration, you will lock down your php.ini baseline, isolate PHP-FPM pools, and tighten web server rules to limit the impact of future vulnerabilities.

Was this lesson helpful?