What is Replace Legacy PHP with TypeScript and Node.js?
Replacing legacy PHP with TypeScript and Node.js means rewriting or incrementally migrating a custom PHP application to a TypeScript codebase running on Node.js, typically with Next.js for the web app, PostgreSQL for data and Payload CMS for content and admin. The goal is to remove the PHP runtime that PHP2Shell exploited while modernising testing, deployment and the delivery pipeline. Most business-critical apps migrate with a strangler-fig approach rather than a big-bang rewrite.
PHP2Shell, meaning CVE-2026-109618 and CVE-2026-109619, exposed every custom PHP application on a vulnerable runtime, whatever the framework or code quality. For business-critical legacy PHP apps that are hard to patch, untested or on end-of-life PHP, a move to TypeScript and Node.js removes the runtime risk and modernises the whole delivery pipeline. Successful migrations follow a playbook: discover, characterise, design the target, migrate incrementally, move data, cut over, decommission. WordPress owners can usually ask their host to upgrade PHP, but custom PHP applications often run on old PHP branches because a framework upgrade was never budgeted, depend on abandoned Composer packages that will not install on PHP 8.x, have few or no automated tests, encode years of business rules that only exist in the code, and were built by developers who have since left. PHP2Shell runs before any application code, so well-written custom code offered no protection, and PHP 7.3 and older received no fix at all.
Why custom PHP apps are the hardest PHP2Shell problem
WordPress owners can usually ask their host to upgrade PHP, but custom PHP applications are different. They often run on old PHP branches because a framework upgrade was never budgeted; Recorded Future reported Modat findings of about 79% of versioned PHP services on unsupported branches, with PHP 7.4 the single most common. They depend on abandoned Composer packages that will not install on PHP 8.x. They have few or no automated tests, so upgrades are risky. They encode years of business rules that only exist in the code, and they were built by developers who have since left. PHP2Shell runs before any application code, so well-written custom code offered no protection, and PHP 7.3 and older received no fix at all. For many organisations, the honest options are an emergency multi-version upgrade of a fragile system, or a planned migration to a modern stack.
Why TypeScript and Node.js
TypeScript on Node.js is the right replacement for most PHP applications for practical reasons. One language runs end to end: the same TypeScript runs in the browser with React, on the server with Node.js and in the CMS with Payload, so shared types between front end and back end remove a whole category of integration bugs. TypeScript catches many errors at compile time that PHP only reveals in production. JavaScript and TypeScript consistently rank among the most used languages in the Stack Overflow Developer Survey, which makes hiring and handover easier. Node's event-driven model handles I/O-heavy APIs, real-time features such as WebSockets, and integrations efficiently. Containers, serverless, edge runtimes, CI/CD and infrastructure as code are first-class. The leading AI SDKs, agent frameworks and vector tooling all have strong TypeScript support, which keeps the platform ready for AI features. And Node.js publishes a clear LTS schedule, so upgrades can be planned rather than rushed.
The target architecture
A typical target for a legacy PHP business application puts a CDN and WAF in front of a Next.js application written in TypeScript, containing React Server Components and client UI, route handlers and server actions, and a Payload CMS admin for content. Domain services run on Node.js or NestJS with background jobs and queues on cron, all talking to PostgreSQL with row-level security, object storage, and an auth or SSO layer. Concretely: Next.js with the App Router handles SSR, SSG, ISR, routing, caching and image optimisation; Payload CMS provides typed content, an admin UI and access control in code; Next.js route handlers or NestJS cover domain APIs with structure, dependency injection and testability; PostgreSQL, often via Supabase, brings reliability, row-level security, JSONB and pgvector for AI; Drizzle or Prisma provide type-safe queries and migrations; Zod gives runtime validation that matches TypeScript types; BullMQ, pg-boss or platform cron replace PHP cron scripts and Laravel queues; auth comes from Payload, Supabase Auth, Auth.js or enterprise SSO; hosting is Vercel, Railway, AWS or GCP with immutable deploys and autoscaling; and observability uses OpenTelemetry, Sentry and structured logs for fast incident response.
flowchart TB
subgraph Edge
CDN[CDN / WAF]
end
subgraph App[Next.js application, TypeScript]
UI[React Server Components and client UI]
RH[Route handlers / Server actions]
CMS[Payload CMS: admin and content]
end
subgraph Services
API[Domain services: Node.js / NestJS]
Q[Background jobs: queues and cron]
end
DB[(PostgreSQL with row-level security)]
OBJ[(Object storage)]
AUTH[Auth / SSO]
CDN --> UI
UI --> RH --> API
CMS --> DB
API --> DB
Q --> DB
API --> OBJ
RH --> AUTHPHP to TypeScript concept map
Most PHP concepts have a direct, often better, TypeScript equivalent. Composer becomes npm or pnpm with a lockfile. PHP-FPM with Nginx or Apache becomes a Node.js server, serverless functions or an edge runtime. Blade or Twig templates become React components, server and client. Eloquent or Doctrine becomes Drizzle or Prisma, and artisan migrations become Drizzle Kit or Prisma Migrate. Form Requests and validators become Zod schemas. Middleware becomes Next.js middleware or NestJS guards and interceptors. Laravel Queues and Horizon become BullMQ or pg-boss with a dashboard. Scheduler and cron PHP scripts become platform cron with job runners. Laravel Sanctum and Passport become Auth.js, Supabase Auth, Payload auth or OAuth providers. PHP sessions become signed HTTP-only cookies, JWT or server sessions. PHPUnit or Pest becomes Vitest or Jest with Playwright. A Laravel controller that validates email and plan fields and creates a customer becomes a typed server action where a Zod schema parses the input at runtime and compile time, and Drizzle inserts the row and returns a typed result.
import { z } from 'zod'
import { db } from '@/db'
import { customers } from '@/db/schema'
const Input = z.object({
email: z.string().email(),
plan: z.enum(['basic', 'pro']),
})
export async function createCustomer(raw: unknown) {
const data = Input.parse(raw)
const [customer] = await db.insert(customers).values(data).returning()
return customer
}The seven-step migration playbook
Step one is discovery: inventory modules, routes, cron jobs, queues, integrations, reports and admin screens, pull real usage data from access logs and analytics to find what is actually used, because often 20 to 40% of a legacy app is dead, map data stores including MySQL schemas, file uploads, caches and sessions, and identify compliance constraints such as HIPAA, PCI DSS and GDPR. Step two is characterisation: write characterization tests against the existing system, recording real inputs and outputs for key flows like pricing, invoicing and permissions so the new system can be proven equivalent, following Michael Feathers in Working Effectively with Legacy Code, and capture business rules in plain-language specs confirmed with the people who use the system. Step three is designing the target: choose the architecture and the migration strategy, with a big-bang rebuild only for small low-risk apps and strangler fig, replacing module by module behind a router, for most business-critical apps, then define the data strategy. Step four builds the foundation: auth, roles and permissions, multi-tenancy, audit logging, observability, CI/CD and environments. Step five migrates incrementally, starting with a low-risk, high-visibility module such as reporting or a customer-facing page, routing traffic gradually with feature flags or a reverse proxy, and comparing outputs with characterization tests and shadow traffic. Step six moves the data. Step seven cuts over and decommissions: final data sync, DNS or routing switch, a hyper-care period, then shutting down the PHP servers so no forgotten PHP box stays online to become the next PHP2Shell victim.
Data migration without downtime
Most legacy PHP apps use MySQL or MariaDB, and three patterns cover most cases. A shared database during the transition lets new TypeScript services read and write the same MySQL database while modules migrate; it is simple but limits schema improvements. Migrating to PostgreSQL with replication or change-data-capture, using for example Debezium or scheduled sync scripts, keeps PostgreSQL current and lets you redesign the schema, add row-level security, and gain pgvector for AI features such as RAG with PostgreSQL. Dual-write with reconciliation suits high-throughput systems, with nightly diff reports. Whatever the pattern, map every table and column and flag unused ones; fix encodings, because latin1 to UTF-8 is a classic PHP-era trap; convert serialized PHP arrays stored in columns to JSONB; migrate password hashes, keeping bcrypt hashes from PHP's password_hash function because Node's bcrypt libraries can verify them so users do not need to reset passwords; and reconcile row counts and checksums before cutover.
Testing and security in the new stack
Proving the new system behaves like the old one needs layers of testing: characterization tests built from recorded fixtures of the PHP system to prove functional equivalence, unit tests with Vitest for business rules in isolation, integration tests with Vitest against a test database for queries, transactions and integrations, end-to-end tests with Playwright for critical user journeys, contract tests through OpenAPI and typed clients so integrations stay compatible, and shadow traffic through proxy mirroring to compare old and new responses in production without user impact. On security, an honest view matters: moving to TypeScript and Node.js does not make you invulnerable. Node.js publishes security releases, and the npm ecosystem has seen serious supply-chain attacks, including a CISA warning about a widespread compromise impacting npm in September 2025. What changes is how you manage the risk: lockfiles and pinned versions with automated update pull requests from Renovate or Dependabot running through CI, dependency scanning with npm audit, Snyk or GitHub Advanced Security plus package provenance checks, a minimal dependency philosophy, static and edge rendering so most traffic never reaches application code, immutable deployments that ship fixes in minutes and roll back in seconds, database-level authorization with PostgreSQL row-level security as defence in depth, and OWASP-aligned practices throughout the OWASP Top 10.
Note
Node.js has its own vulnerabilities and npm has seen serious supply-chain attacks, including a CISA warning in September 2025. Lockfiles, scanning and immutable deployments are the controls.
Sources and references
Recorded Future analysed PHP2Shell exploitation at recordedfuture.com/blog/php2shell-vulnerability-exploitation, SOCRadar listed the CVEs at socradar.io, and Wiz Research published its research at wiz.io/blog/php2shell-php-rce. The PHP Group lists supported versions at php.net/supported-versions.php, and Node.js publishes its LTS schedule at nodejs.org. Stack Overflow's Developer Survey is at survey.stackoverflow.co, CISA's npm supply-chain alert is at cisa.gov, and OWASP's Top 10 is at owasp.org. Martin Fowler documents the strangler fig pattern at martinfowler.com, Michael Feathers' Working Effectively with Legacy Code is published by O'Reilly, Payload CMS documentation is at payloadcms.com/docs, and Next.js documentation is at nextjs.org/docs.
PHP and Laravel concepts mapped to TypeScript and Node.js
| PHP / Laravel / Symfony | TypeScript / Node.js equivalent |
|---|---|
| Composer | npm or pnpm with a lockfile |
| PHP-FPM with Nginx or Apache | Node.js server, serverless functions or edge runtime |
| Blade or Twig templates | React components, server and client |
| Eloquent or Doctrine ORM | Drizzle or Prisma |
| Migrations via artisan migrate | Drizzle Kit or Prisma Migrate |
| Form Requests and Validator | Zod schemas |
| Middleware | Next.js middleware, NestJS guards and interceptors |
| Laravel Queues and Horizon | BullMQ or pg-boss with a dashboard |
| Scheduler and cron PHP scripts | Platform cron with job runners |
| Laravel Sanctum and Passport | Auth.js, Supabase Auth, Payload auth or OAuth providers |
| PHP sessions | Signed HTTP-only cookies, JWT or server sessions |
| PHPUnit or Pest | Vitest or Jest with Playwright |
| .env and config PHP files | Typed config with Zod-validated environment variables |
Every major PHP concept has a maintained TypeScript equivalent, so a migration is a mapping exercise rather than a reinvention.
The seven-step migration playbook
- 1
Discover
Inventory modules, routes, cron jobs, queues, integrations and admin screens, pull real usage data to find dead code, map data stores, and identify compliance constraints.
- 2
Characterise
Write characterization tests against the existing system for key flows like pricing, invoicing and permissions, and capture business rules in plain-language specs confirmed with real users.
- 3
Design the target
Choose the architecture and migration strategy: big-bang only for small low-risk apps, strangler fig for most business-critical apps, plus a shared-database or replication data strategy.
- 4
Build the foundation
Stand up auth, roles and permissions, multi-tenancy, audit logging, observability, CI/CD and environments, which a pre-built TypeScript foundation provides in days rather than weeks.
- 5
Migrate incrementally
Start with a low-risk, high-visibility module, route traffic gradually with feature flags or a reverse proxy, and compare outputs with characterization tests and shadow traffic.
- 6
Move the data
Keep MySQL shared during the transition or replicate to PostgreSQL with change-data-capture, convert serialized PHP arrays to JSONB, keep bcrypt hashes, and reconcile row counts before cutover.
- 7
Cut over and decommission
Run the final data sync, switch DNS or routing, hold a hyper-care period, then shut down the PHP servers so no forgotten PHP box remains online.
A TypeScript and Node.js system running module by module in production with the PHP servers shut down, characterization tests proving equivalence and users keeping their existing passwords.
Most versioned PHP services run unsupported branches According to Recorded Future, citing Modat internet scans, About 79% of versioned PHP services run unsupported branches, with PHP 7.4 the single most common. That is why patching often means a risky major upgrade under time pressure, and why many organisations plan a migration instead of another emergency fix.
Conclusion
Legacy PHP does not have to be retired in a single risky rewrite, and it should not be left online as the next PHP2Shell victim. Map what your application actually does, prove equivalence with characterization tests, move module by module behind a router, migrate data with reconciliation, and shut the PHP servers down for good. App Corp offers a production-ready TypeScript foundation with auth, roles, multi-tenancy and billing so you rebuild business logic rather than plumbing, plus custom strangler-fig migrations for complex estates, with typical first releases in eight to twelve weeks and fixed, outcome-based pricing.
Frequently Asked Questions
Key Takeaways
- PHP2Shell exposed every custom PHP application on a vulnerable runtime, whatever the framework or code quality
- For business-critical legacy PHP apps that are hard to patch, untested or on end-of-life PHP, moving to TypeScript and Node.js removes the runtime risk and modernises delivery
- Successful migrations follow a playbook: discover, characterise, design the target, migrate incrementally, move data, cut over and decommission
- Most business-critical apps should use a strangler-fig migration, replacing modules behind a router, rather than a big-bang rewrite
- bcrypt password hashes from PHP's password_hash function can be verified by Node.js bcrypt libraries, so users do not need to reset passwords
- The new stack is not invulnerable: npm has seen supply-chain attacks, so lockfiles, dependency scanning, minimal dependencies and immutable deployments keep risk managed