Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Security and hardening

Is my PHP application affected by PHP2Shell, and how do I mitigate it?

ErrorA scanner or advisory feed reports CVE-2026-109618 (RCE via OOM corruption) on your server

Short answer

You are exposed when the PHP serving web requests is older than 8.2.35, 8.3.36, 8.4.27 or 8.5.12 on its branch, or when a distribution package is older than its vendor's fixed build. Check the web process, not only the command line. Updating PHP and restarting every worker is the only complete fix. The advisories give stop-gap settings that are not enough alone.

  • Applies to PHP 8.2.35, PHP 8.3.36, PHP 8.4.27, PHP 8.5.12, Ubuntu 24.04, Debian 12
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Ask the web server itself which PHP it runs, because the command line can use a different PHP from the one that answers web requests. Put this one-line file in the web root, request it, and delete it at once. The output is the version followed by the SAPI name.

    <?php echo PHP_VERSION, ' ', PHP_SAPI;
    
    # then, from a shell
    curl -s https://example.com/which-php.php
  2. 2Match what you see, then jump to its fix

    1. 1The output shows a version below 8.2.35, 8.3.36, 8.4.27 or 8.5.12, for example 8.3.30 apache2handler, and PHP was not installed from a Debian or Ubuntu packageAn upstream PHP build is older than the patched release of its branchFix
    2. 2The web check prints an old-looking number such as 8.3.6, but the package may already carry the fixA Debian or Ubuntu package is older than the vendor's fixed buildFix
    3. 3The first-step output ends with apache2handlerApache mod_php, the case the advisory confirmsFix
    4. 4php -v or dpkg shows the fixed build while the web check still prints an old oneThe package is upgraded, but the web process still runs the old PHPFix
    5. 5The server runs an affected PHP and the update is blocked or scheduled for laterYou cannot update today, so you need the documented stop-gap settingsFix
    6. 6The server ran an affected build while reachable from the internetYou need to know whether the server was already hitFix

What does the error look like?

  • A scanner or advisory feed reports CVE-2026-109618 (RCE via OOM corruption) on your server
  • A scanner or advisory feed reports CVE-2026-109619 (RCE via stale global state) on your server
  • The web PHP version is below 8.2.35, 8.3.36, 8.4.27 or 8.5.12

Cause 1 of 6

An upstream PHP build is older than the patched release of its branch

1Check

Both advisories list every version below those four releases as affected and those four as patched. They name no patched upstream release for branches older than 8.2.

curl -s https://example.com/which-php.php

2Fix

Update to the patched release or newer on the same branch, from the source you installed from or by rebuilding your image. Then restart the workers. The advisories call updating the only complete mitigation.

sudo systemctl restart php8.3-fpm

3Verify

Request the which-php.php file again and read the version, then delete the file.

curl -s https://example.com/which-php.php

Confirmed by github.com

Did this fix it?

Cause 2 of 6

A Debian or Ubuntu package is older than the vendor's fixed build

1Check

Distributions ship the fix under their own package version, so the number PHP prints is not enough. Ubuntu lists php8.3 on 24.04 as fixed in 8.3.6-0ubuntu0.24.04.13, and Debian lists php8.2 on bookworm as fixed in 8.2.35-1~deb12u1 from the security archive. Compare the installed package version with the fixed version in your vendor's tracker.

dpkg -s php8.3-fpm | grep '^Version'
apt list --upgradable 2>/dev/null | grep -i php

2Fix

Install the update from the distribution, then restart the workers.

sudo apt update
sudo apt install --only-upgrade php8.3-fpm php8.3-cli
sudo systemctl restart php8.3-fpm

3Verify

dpkg now shows a version at or above the fixed one from the vendor's tracker.

dpkg -s php8.3-fpm | grep '^Version'

Confirmed by ubuntu.com

Did this fix it?

Cause 3 of 6

Apache mod_php, the case the advisory confirms

1Check

For CVE-2026-109618 the advisory confirmed the flaw on Apache mod_php, where shutdown runs even when startup fails, and validated remote code execution over HTTP with default limits. FPM looks susceptible from source analysis but no complete exploit is shown. FrankenPHP is described as likely susceptible, and LSAPI as likely susceptible but unvalidated.

curl -s https://example.com/which-php.php

2Fix

Patch whichever SAPI you run. On mod_php, restart Apache after the update so that every worker loads the new PHP.

sudo systemctl restart apache2

3Verify

Confirm the package version as in the previous cause, and read the web check again.

curl -s https://example.com/which-php.php

Confirmed by github.com

Did this fix it?

Cause 4 of 6

The package is upgraded, but the web process still runs the old PHP

1Check

The command line and the web server can use different PHP builds, and the advisories tell you to restart all workers after a configuration change, so treat an update the same way.

php -v
curl -s https://example.com/which-php.php

2Fix

Restart the service that runs your PHP workers, and check that no second PHP install is the one wired to the web server.

sudo systemctl restart php8.3-fpm
sudo systemctl restart apache2

3Verify

The web check shows the build you expect.

curl -s https://example.com/which-php.php

Confirmed by github.com

Did this fix it?

Cause 5 of 6

You cannot update today, so you need the documented stop-gap settings

1Check

The advisories name settings that lower the risk. They state that updating is the only complete fix, and that no generic configuration removes the risk of CVE-2026-109619. Save this as ini-check.php to see what the web process uses now.

<?php echo ini_get('memory_limit'), ' ', ini_get('session.upload_progress.enabled'), ' ', ini_get('post_max_size');

2Fix

Set these in the main PHP configuration, where the application cannot override them, then restart all workers. memory_limit=-1 is the primary configuration mitigation for CVE-2026-109618, and it also removes PHP's own memory ceiling, so keep it only until you patch. session.upload_progress.enabled=0 is for CVE-2026-109619. On PHP 8.5 also set fatal_error_backtraces=0. Keep post_max_size modest, lower max_input_nesting_level, and block multipart/form-data at the frontend if the application does not use it. Do not use RLIMIT_AS or RLIMIT_DATA, because they cause mmap failures that reach the vulnerable path.

; main php.ini, not .user.ini
memory_limit = -1
session.upload_progress.enabled = 0
; PHP 8.5 only
fatal_error_backtraces = 0

3Verify

Restart the workers and request ini-check.php again. Delete the file afterwards.

curl -s https://example.com/ini-check.php

Confirmed by github.com

Did this fix it?

Cause 6 of 6

You need to know whether the server was already hit

1Check

The impact in both advisories is unauthenticated code execution with the web worker's privileges. The advisory for CVE-2026-109619 warns that clean logs do not prove safety.

<?php echo ini_get('log_errors'), ' ', ini_get('error_log'), ' ', ini_get('error_reporting');

2Fix

Patch first, so the hole is closed while you look. Then treat everything the web worker account can read or write as in scope of your review. The advisory suggests error logging with error_reporting=E_ALL in an isolated environment for auditing.

; isolated test copy only
log_errors = On
error_reporting = E_ALL

3Verify

Save the check as log-check.php, request it, delete it, and confirm that logging is on and a log file is named. Then read that log for new entries.

curl -s https://example.com/log-check.php

Confirmed by github.com

Did this fix it?

How do I stop it coming back?

  • Watch the php-src security advisories and your distribution's security tracker for the branch you run, and keep PHP on a supported branch.
  • Keep a one-line way to read the real PHP version and SAPI of the web process, so an audit never relies on php -v alone.
  • Run workers under an account that can read only what the application needs, since the impact is code execution as that account.
  • Rebuild and redeploy images after each PHP security release instead of patching long-lived servers by hand.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.