
Getting stuck PHP code onto a patched runtime after PHP2Shell
Use AWS Transform to upgrade PHP that cannot take the fixed release, and verify the result on a patched interpreter before it ships. The numbers come from one small synthetic application, not a benchmark.
The only fix for PHP2Shell is a patched PHP runtime with every worker (each PHP-FPM or mod_php process that serves requests) restarted. Teams whose code was written for PHP 7.4 or 8.0 often cannot take it yet, because that code breaks on a supported version. This walkthrough uses AWS Transform to find that code, upgrade it on a branch you review, and check the result on a patched PHP before it ships.
Useful links before starting:
- AWS Security Bulletin 2026-143-AWS : affected versions and AWS service status
- Getting started with AWS Transform continuous modernization : install, prerequisites and quick start
- AWS Transform continuous modernization : analysis and remediation across repositories
- php2shell-patch-and-verify in aws-samples/aws-transform-custom-samples : the guide, the verify transformation, the sample application and the measured results used here
Scope note. This post is about getting code onto a patched runtime, not about detection or mitigation. Those are well covered in the AWS WAF post and the community checklist Find It, Patch It, Watch It . It also does not find compromise: if a system was exposed unpatched, investigate separately.
What happened
On 2026-10-21 the PHP project released fixes for CVE-2026-109618 and CVE-2026-109619, two flaws in PHP rated CVSS v4.0 9.2 in the GHSA-w8hw-w9fx-j79w and GHSA-6wmf-4rv5-p3rp advisories. Both can let an unauthenticated attacker run code on a server that handles PHP requests. AWS services are not affected, but workloads you run on them can be.
PHP branch | Affected | First fixed |
|---|---|---|
8.5 | 8.5.0 to 8.5.11 | 8.5.12 |
8.4 | 8.4.0 to 8.4.26 | 8.4.27 |
8.3 | 8.3.0 to 8.3.35 | 8.3.36 |
8.2 | 8.2.0 to 8.2.34 | 8.2.35 |
5.4 to 8.1 | all | No release fixes these branches. Migrate to 8.4 or 8.5 |
Source: the AWS bulletin above. The bulletin says to migrate to a supported branch; choosing 8.4 or 8.5 is this post's recommendation, based on their support dates at php.net . Amazon Threat Intelligence identified an exploitation attempt on 2026-10-17, four days before the fixes, and reports broad exploitation attempts since ( Amazon Threat Intelligence ). The same post advises not to assume the disclosure date is the earliest date of exploitation, and to investigate from at least 2026-10-17. Treat this as urgent.
Which of these are you?
You run | What to do |
|---|---|
PHP 8.2, 8.3, 8.4 or 8.5 | Still vulnerable until you patch to 8.2.35, 8.3.36, 8.4.27 or 8.5.12. Your code does not need to change: patch the runtime and restart every worker |
PHP 8.1 or older | No release fixes these branches (PHP published minimal source backports for 7.4 to 8.1, a stopgap for people who build from source). Check your distribution or LTS vendor first: some ship backported fixes. Otherwise migrate to 8.4 or 8.5 (8.2 reaches end of life on 2026-12-31 and 8.3 on 2027-12-31); until then, apply the interim controls in the bulletin and the AWS WAF post. Your code may need changes first, which is what the rest of this post covers |
PHP you cannot find | Build the inventory first (Amazon Inspector, Systems Manager Inventory, container registries) |
For the second row, the blocker is that the application breaks on a supported PHP version. Upgrading the code does not fix the CVEs. It removes that blocker so the runtime can be updated.
The application
The sample is a deliberately legacy PHP 7.4 application: five small classes and seven PHPUnit tests, with breakages of the three kinds you meet in real code.
Kind | Example in the sample | What PHP 8 does |
|---|---|---|
Removed or stricter, fails to parse or run | $text{0} , create_function() , each() , count(null) | Parse error, fatal error or TypeError |
Silent behavior change | 0 == "abc" in Matcher::isZeroLike | No error, a different answer. Only a test notices |
Deprecated | Implicit nullable parameter, dynamic properties, "${var}" | Deprecation notices on 8.2 to 8.4 |
The silent ones are the dangerous ones: the code runs and returns a different answer.
Before you start
You need the AWS Transform CLI 3.20.0 or later (
atx --version ; older versions lack --wait and --category ), Node.js 22 or later, Git, jq (step 2), Docker, and AWS credentials with the AWSTransformCustomFullAccess managed policy. Work on throwaway clones of your repositories. The verify transformation lives in the sample folder, so clone it once:git clone https://github.com/aws-samples/aws-transform-custom-samplesexport GUIDE="$PWD/aws-transform-custom-samples/community-sourced-transformations/php2shell-patch-and-verify"export TARGET=8.5 # the sample used 8.5; 8.4 works the same way (see the constraint table after step 2)The machine that runs step 2 also needs a patched PHP and Composer, because the upgrade runs your tests with whatever PHP it finds (without PHP, one run spent 28 agent minutes and failed). On Amazon Linux 2023:
sudo dnf install -y --releasever=2023.12.20261021 php$TARGET-cli php$TARGET-xml php$TARGET-mbstring composerphp -v # 8.5.12 or later (8.4.27 or later for 8.4)Step 1. Analyze with continuous modernization
atx ct is the continuous modernization command group.Start with the quick scan (
rapid-techdebt-analysis ), then run the comprehensive analysis: the quick scan reads only manifests, and the code-level breakages show up in the comprehensive one.atx ct source add --name my-php --provider local --path ~/reposatx ct discovery scan --source my-phpatx ct analysis run --type rapid-techdebt-analysis --source my-php --wait # 1 to 2 minutesatx ct analysis run --type tech-debt-comprehensive --source my-php --wait # about 7 minutesatx ct findings list --source my-php --status open --jsonOn a local source, the analysis writes an
ATXDocumentation/ folder and a branch into each repository. Switch back to your branch and delete that folder before step 2: the upgrade refuses a repository with uncommitted changes.The rapid scan reads
composer.json and returned one high finding, "PHP Version Upgrade", whose fix is AWS/php-version-upgrade . The comprehensive analysis reads the code and returned 6 to 11 findings (the number and the titles vary between runs). Four of them, from one run, show why it is worth the extra minutes:Severity | Finding, as titled by the tool |
|---|---|
High | Removed PHP constructs: $text{0} , create_function() , each() |
High | Silent PHP 8 behavior changes in Matcher::isZeroLike and Inventory::lineCount |
High | EOL PHP runtime constraint php >=7.4 in composer.json |
Medium | PHP 8.2/8.4 deprecations in src/Notes.php |
Each of these four names
AWS/php-version-upgrade as the fix. (The tool groups Inventory::lineCount with the silent changes; its count(null) actually raises a TypeError on PHP 8.)Step 2. Upgrade from the findings with a continuous modernization remediation
AWS/php-version-upgrade migrates PHP code to PHP 8.5 unless told otherwise. The AWS-Managed Transformations catalog lists it as Early access. Check that it shows in your account first:atx custom def list | grep -i php # must show AWS/php-version-upgradeStart the upgrade from the step 1 findings whose fix is
AWS/php-version-upgrade . The remediation passes those findings to the transformation, so the run plans around them (PHP version, removed constructs, silent changes, PHPUnit) instead of only the version:IDS=$(atx ct findings list --source my-php --status open --fix-transform AWS/php-version-upgrade --json | jq -r '[.[].id] | join(",")')echo "$IDS" # must not be emptyatx ct remediation create --ids "$IDS" --name php-upgrade \ --transformation-name AWS/php-version-upgrade \ -g "{\"additionalPlanContext\":\"The target PHP version is $TARGET\"}"atx ct remediation status --id <remediation-id> # the id is printed above; done = repo status pr_open, findings change_ready- The command returns when the run ends (4 to 5 minutes on the sample). Do not interrupt it: an interrupted run stayed
runningeven though its branch was written, and I had to remove it withatx ct remediation cancel --id <remediation-id>.
-
-gis accepted only together with--transformation-name, which is why both are there. Without them,--idsalone migrates to PHP 8.5.
- On a
localsource the job runs on your machine. The CLI prints "remote mode", but the run used the local checkout, the local PHP and the local tools, trusting every tool without a prompt (one run installed Composer system-wide withsudo). Use a disposable machine with no production credentials and the patched PHP from "Before you start". I did not test remediation on a GitHub or GitLab source.
- No cost cap and no
-d.remediation createhas no--limitand no opt-out of knowledge-item extraction. To cap the cost or keep proprietary code out of knowledge items, run the transformation directly instead. This direct run does not read the findings:
atx custom def exec -n AWS/php-version-upgrade -p ~/repos/svc -x -t -d --limit 100 \ -g "{\"additionalPlanContext\":\"The target PHP version is $TARGET\"}"-x -t run it unattended with every tool trusted, -d opts out of knowledge-item extraction, and --limit 100 caps it at 100 agent minutes; at the cap the CLI exits with code 2, and the same command with a higher limit resumes.The result is a new branch for you to review (
atx/php-version-upgrade-<timestamp> , or atx-result-staging-<timestamp> for a direct run). Two of its edits: class Initials { public function first($text) {- return $text{0};+ return $text[0]; } } public function isZeroLike($value) {+ if (is_string($value) && !is_numeric($value)) {+ return (int) $value === 0;+ } return $value == 0; }The first is mechanical. The second is a decision, and the runs did not agree: in 4 of the 6 runs I saw, the tool kept the PHP 7 answer for
0 == "abc" and kept the test that asserts it; one run that switched to the PHP 8 answer still treated "0.5" as zero. Preserving behavior can preserve insecure behavior: PHP 8 changed loose comparisons on purpose, and that class of bug is behind loose-comparison authentication bypasses. Review every == , switch and non-strict in_array on user input, and prefer the PHP 8 result unless you have a reason. The secure version of the sample keeps the original return $value == 0; and flips the test to assertFalse($m->isZeroLike("abc")) ; it passes 7 of 7 tests.The part I did not expect
The managed transformation checks its own work by running the project's tests. On my test machine that meant PHP 8.5.3, which is vulnerable: it is lower than 8.5.12. A direct run that targeted 8.4 validated on 8.4.26, also vulnerable, and a remediation that targeted 8.4 validated on 8.5.3, another branch. Amazon Linux 2023 repositories stay on the release the host was launched with. A host launched from an image older than release
2023.12.20261021 kept offering the pre-patch PHP even after AWS published the fixed packages (ALAS2023-2026-3301 to -3304), unless you name that release. Hosts launched from 2023.12.20261021 or later get the patched PHP.The tests passed on a vulnerable PHP. That is fine for "does the code still work on PHP 8.5", and not enough for "is this safe to ship on the patched runtime". A migration can look green and have been checked on the wrong interpreter.
The second surprise was in
composer.json . The transformation wrote "php": ">=8.5" or "^8.5" , and ">=8.4" when it targeted 8.4 (once also a config.platform.php of "8.4" ). All of them allow the unpatched releases, so nothing stops the upgraded application from being installed on PHP 8.5.3. The obvious fix is wrong too. Checked with Composer's own version library:require.php | Allows an unpatched release? |
|---|---|
>=8.4 , >=8.5 , ^8.5 , 8.4.*
| Yes |
>=8.4.27 , ^8.4.27 | Yes: they also allow 8.5.0 to 8.5.11 |
~8.4.27 || ^8.5.12 | No |
^8.5.12 | No |
Set
require.php to ^8.5.12 for target 8.5, or to ~8.4.27 || ^8.5.12 for target 8.4. If composer.json sets config.platform.php , set it to 8.5.12 (or 8.4.27 ). Then run composer update --lock . Composer's generated platform_check.php checks only the lowest version in require.php : with ^8.5.12 the application refused to start on 8.5.11 and on 8.4.27; with ~8.4.27 || ^8.5.12 it refused 8.4.26 but still started on 8.5.11. Either way, the manifest prevents an install on old PHP; it does not replace the runtime patch.Step 3. Verify on a patched runtime
The gap is closed by a small custom transformation,
php-upgrade-secure-verify : a gate that only checks, passes or fails the upgrade, and never edits your code. It runs the repository in a container with no network, a read-only file system, no capabilities and an unprivileged user, on the official image of a patched PHP release (by default), and checks:- the PHP in the container is at or above the patched release and on the branch you asked for;
-
composer.jsonallows a patched release of the target branch and no unpatched or end-of-life PHP (with Composer's own version library);
- every PHP source file parses (
.php,.phtml,.incand similar, plus scripts such asbin/console),vendor/included, and the container checked every file the host found;
- your tests pass, with at least one test actually executed (skipped, incomplete and risky tests do not count).
# Once: register it in your account (an analysis-type transformation)cd "$GUIDE"atx custom def publish -n php-upgrade-secure-verify --sd php-upgrade-secure-verify --category analysis \ --description "Verify-only gate: runs migrated PHP on an official patched PHP image and writes a PASS/FAIL/INCONCLUSIVE/BLOCKED verdict"
# On the upgraded branch of your repository: install dependencies first. The gate has no network, and without vendor/ no test can runcd ~/repos/svcdocker run --rm --user "$(id -u):$(id -g)" -e COMPOSER_HOME=/tmp/c -v "$PWD":/app -w /app composer:2 install --no-scripts --no-plugins
# Then run it, with the same target as step 2atx ct analysis run --type custom --transformation-name php-upgrade-secure-verify \ -g "additionalPlanContext=target=$TARGET" --repo my-php::svc --wait
# Or run the gate script alone: no agent, no costbash "$GUIDE/php-upgrade-secure-verify/scripts/verify.sh" ~/repos/svc "$TARGET"The script
scripts/verify.sh does the work and writes verify-verdict.json . The verdict comes from the script's exit code, not from the agent's narrative. A run where no test executes is INCONCLUSIVE (exit 5), never a pass, because php -l finds parse errors only: removed functions such as each() and changed behavior show up only in tests. Results on the sample:Code | Runtime | Verdict | Why |
|---|---|---|---|
Legacy | PHP 8.5.12 | FAIL (exit 2) | "php": ">=7.4" , and src/Initials.php does not parse |
Upgraded, as the transformation left it | PHP 8.5.12 | FAIL (exit 2) | "php": ">=8.5" allows 8.5.0 to 8.5.11, although 7 of 7 tests passed |
Upgraded, with "php": "^8.5.12" | PHP 8.5.12 | PASS (exit 0) | 7 of 7 tests executed, about 1,550 files parse (the sample plus its vendor/ ) |
Same | PHP 8.5.11 | FAIL (exit 2) | The runtime is below the patched release |
The verdict for the fixed code (abridged):
{ "verdict": "PASS", "target_branch": "8.5", "patched_floor": "8.5.12", "php_version": "8.5.12", "version_gate": "PASS", "manifest_gate": "PASS", "manifest_require_php": "^8.5.12", "lint_gate": "PASS", "lint_files": 1545, "test_gate": "PASS", "tests_ran": 7, "patched_runtime_cves": ["CVE-2026-109618", "CVE-2026-109619"], "gate_exit_code": 0}Run as a continuous modernization custom analysis, a failed check becomes a finding:
Code | Severity | Finding | Recommendation |
|---|---|---|---|
Legacy | High | require.php ">=7.4" allows unpatched and end-of-life PHP | Set require.php to the safe constraint |
Legacy | High | src/Initials.php fails php -l : curly-brace string offset | AWS/php-version-upgrade |
Legacy | Medium | No tests executed on the patched runtime | Install dependencies, then verify again |
Upgraded, as left | High | require.php ">=8.5" allows unpatched PHP | Set require.php to ^8.5.12 . If composer.json sets config.platform.php , set it to 8.5.12 . Then run composer update --lock . |
Upgraded, require.php set to ^8.5.12 and composer update --lock run | None | No findings | N/A |
Skip
composer update --lock and the verdict still passes, with the warning composer.lock does not match require.php ; the custom analysis reported it as a low finding.The recommendation text for the manifest is fixed in the transformation's instructions. In an earlier run the agent wrote its own comparison of constraints and got one wrong, which is exactly the kind of detail an agent should not improvise.
Step 4. Patch the runtime
Nothing above closes the vulnerabilities. This does.
Where PHP runs | Action |
|---|---|
Amazon Linux 2023 | Upgrade every PHP package of your branch to the release in the advisory (command below) |
Containers | Rebuild on a base image with a fixed release (for example php:8.4.27-fpm ) and redeploy |
AWS Elastic Beanstalk | Updated PHP platform versions exist for 8.2 to 8.5. Managed Platform Updates applies them in the next maintenance window; otherwise update the platform version yourself |
Amazon Lightsail | No in-place update: create new instances from the updated blueprint and migrate |
AWS Lambda | No managed PHP runtime; if you run your own, rebuild and redeploy |
Debian, Ubuntu, RHEL, LTS builds | Use your vendor's package. The version string may not change: trust the vendor advisory |
On Amazon Linux 2023, use the wildcard for your branch:
php8.2* , php8.3* , php8.4* or php8.5* . dnf upgrade only upgrades packages that are installed, so the wrong branch upgrades nothing. Keep the wildcard quoted: dnf update php8.4 targets only the php8.4 metapackage, and if you installed php8.4-fpm without it, dnf prints No match for argument , exits 1, updates nothing, and a script that ignores the exit code moves on unpatched.Branch | Packages | Advisory |
|---|---|---|
8.2 | 'php8.2*' | ALAS2023-2026-3301 |
8.3 | 'php8.3*' | ALAS2023-2026-3302 |
8.4 | 'php8.4*' | ALAS2023-2026-3303 |
8.5 | 'php8.5*' | ALAS2023-2026-3304 |
B=8.5; A=ALAS2023-2026-3304 # 8.5 shown; use your row of the table. Keep this shell open: the checks below reuse $Asudo dnf upgrade -y --releasever=2023.12.20261021 "php$B*"Set
session.upload_progress.enabled=0 and leave it after patching: a separate flaw (CVE-2026-115560, still unpatched on 2026-10-26; PHP says to keep the setting until its next regular release) affects session upload progress in an uncommon configuration, and the setting is on by default. The paths below are Amazon Linux ones; php --ini shows yours under Scan for additional .ini files . A pool setting overrides php.ini , so check the pools too:echo 'session.upload_progress.enabled=0' | sudo tee /etc/php.d/99-php2shell.inigrep -rn 'upload_progress' /etc/php-fpm.d/ /etc/php-fpm.conf # remove any line that turns it back onThen restart every PHP-FPM service and web server that loads PHP, and confirm. On Amazon Linux 2023 the package changelog does not list the CVE ids, so check the advisory instead:
sudo systemctl restart php-fpm httpd # use your web server's unit (nginx, for example) instead of httpd/usr/sbin/php-fpm -v # the binary that serves requests[ -n "$A" ] && dnf updateinfo list --installed | grep "$A" # the advisory for your branch is installedrpm -qf --qf '%{NAME}-%{VERSION} installed %{INSTALLTIME:date}\n' /usr/sbin/php-fpmps -o lstart= -p "$(pgrep -o -f 'php-fpm: master')" # must be later than the install time above/usr/sbin/php-fpm -i | grep session.upload_progress.enabled # OffI ran these steps in Amazon Linux 2023 containers that started on
php8.4-fpm 8.4.26 ( B=8.4 ) and on php8.5-fpm 8.5.11 ( B=8.5 ). Containers have no systemd, so the restart was done by starting php-fpm again directly. The workers came back on 8.4.27 and 8.5.12, with the matching advisory installed and upload progress Off .Clean up
When you finish, remove what this walkthrough created:
# The verify transformation registered in step 3 (skip this if you will run it across more repositories)atx custom def delete -n php-upgrade-secure-verify
# The branch that the step 1 analysis wrote into each repositorycd ~/repos/svc && git branch # find the analysis branch, then: git branch -D <branch>
# Container images pulled in step 3docker image ls | grep -E '^(php|composer) ' # then: docker image rm <image>If you no longer need the
my-php source in continuous modernization, atx ct source --help shows how to remove it. Delete the throwaway clones, and terminate the disposable machine from step 2: it ran an agent with -t , trusting its tools. Keep the upgraded branch until it has been reviewed and merged.What it cost
Run | Agent minutes | Approx. cost |
|---|---|---|
Rapid analysis | not measured (1 to 2 minutes wall-clock) | not measured |
Comprehensive analysis | not measured (about 7 minutes wall-clock) | not measured |
Upgrade from the findings, atx ct remediation create (3 runs on the 13-file sample) | 20.9 to 38.1 | $0.73 to $1.33 |
Upgrade as a direct run, atx custom def exec (3 runs, minutes measured on 2) | 21.0 to 35.6 | $0.74 to $1.25 |
Verify-only run, with atx custom def exec or as a custom analysis (12 runs) | 8.4 to 15.8 | $0.29 to $0.55 |
verify.sh on its own | 0 | $0 |
Few runs per row, and the minutes vary from run to run. A larger application costs more.
--limit caps a direct run; a run started from a continuous modernization finding has no cap.What it does not do
It does not | So |
|---|---|
Patch your servers | Step 4 is yours |
Find PHP outside the repositories you connect | Services without source, PHP inside third-party products and managed platforms need the inventory step |
Detect a compromise | Investigate separately and rotate credentials the application could read |
Prove identical behavior | A PASS is no regressions in what your tests cover, a safe manifest and a clean parse on a patched PHP. Without tests the verdict is INCONCLUSIVE , not a pass |
Cover every extension | The official PHP image has only core extensions. Tests needing pdo_mysql , gd or intl need your own image on the patched base, passed as PHP_IMAGE=your-image (the gate still checks the PHP version inside it and records that the image's provenance was not verified) |
Resist a hostile project | The container limits what a project can reach, but the repository, its tests and its vendor/ are trusted input: a hostile project can fake the test output and the verdict. Run it only on code you would run anyway |
From one repository to the estate
One application is the easy version. Most teams have dozens, and the same removed function appears in all of them. Continuous modernization connects a GitHub organization, a GitLab group or a local directory, discovers the repositories, and returns findings with the transformation that can fix each one. The verify transformation fits the same loop: register it once, and every upgraded repository gets the same gate, with the same pass criteria, instead of fifty slightly different checks.
The pattern has three parts: a managed transformation for the bulk of the upgrade, a custom verify-only transformation to check the result on a patched runtime, and a runtime patch with a restart to close the vulnerability.
Disclaimer: sample code, provided as is, not a security product and not a substitute for your vendor's or your security team's guidance.
AWS/php-version-upgrade was early access when tested. Test in non-production first.Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article