Most guides to legacy application modernization are written for mainframes and COBOL, or are a list of buzzwords with a services pitch at the end. Legacy PHP has its own shape. The code usually works and earns money. It runs on a PHP version that went out of support years ago, on a framework version that did too, and the people who understand it are fewer every year. The question is never whether to modernize, but how far to go and in what order.
This guide sets out the options, how to assess what you have, and how to pick the cheapest path that actually removes the risk.
What makes a PHP application "legacy"
Age alone does not. A ten-year-old Symfony application on a supported PHP version, with tests and a team that changes it weekly, is not legacy. These are the signs that one is:
- It runs on an unsupported PHP version: 8.1 or older today, and 8.2 from January 2027. See the PHP end-of-life timeline.
- Its framework is out of support: Laravel 10 or older, Symfony 4 or older, CodeIgniter 3, CakePHP 2, Zend Framework 1 or 2.
- Dependencies are pinned or abandoned, and
composer updateis a word nobody says out loud. Or there is no Composer at all. - Changes are slow and risky: few or no automated tests, manual deployments, and fear of touching certain files.
- Knowledge is concentrated in one or two people, or in people who have left.
Each of these has a different fix. Modernization goes wrong when one fix, usually a rewrite, is applied to all of them.
The seven options
The industry describes modernization strategies as "the Rs". Here they are, translated into what each means for a PHP application.
| Option | What it means for PHP | Removes | Cost and risk |
|---|---|---|---|
| Retire | Switch off features or whole applications nobody uses | Everything, for that part | Lowest. Usually the first saving found |
| Retain and cover | Keep it as it is, patched under long-term support | Runtime security risk, for a time | Low. A bridge while other work happens |
| Rehost | Move it to containers or new infrastructure, same code | Old servers and operating systems | Low to medium. Does not fix the code |
| Replatform | Upgrade PHP and the framework to supported versions | Unsupported runtime and framework | Medium. The most common right answer |
| Refactor | Improve the code's structure and tests on the same stack | Fragility and slow change | Medium. Best done alongside replatforming |
| Rearchitect | Change the shape: split the front end off, extract services, move routes to Next.js | Architectural limits | High, but incremental if done well |
| Replace | Swap it for a product or rebuild it on a new stack | The whole legacy system | Highest, and the most likely to fail as a big bang |
Most successful modernizations combine several: retire what is unused, cover the runtime while you work, replatform to supported versions, refactor the parts that change most, and rearchitect only where the architecture itself is the constraint.
Step 1: assess what you have
An honest assessment takes about two weeks for one application and saves months of wrong work. Cover:
- Runtime and dependencies. PHP version, extensions, framework version, and every Composer package with its support status. Flag abandoned packages.
- Compatibility with current PHP. Run static analysis (PHPStan, Psalm or PHPCompatibility for PHP_CodeSniffer) against the target version and count the issues by type. Most are mechanical.
- Usage. Access logs tell you which routes and features carry traffic. Code with no traffic in ninety days is a candidate for retirement.
- Change hotspots. Version control history shows which files change most often and cause most bugs. Those are where refactoring pays.
- Test coverage and deployment. How confident can you be in a change, and how long does it take to ship?
- Security findings. Known vulnerabilities in dependencies, plus the usual legacy PHP issues: SQL built from strings, unescaped output, weak password hashing, secrets in code.
- People. Who knows the system, and what does the team want to work in for the next five years?
Our two-week PHP assessment produces exactly this, with a costed plan.
Step 2: choose with a decision table
| If the assessment shows | Then |
|---|---|
| The code works, the team knows PHP, the main problem is an unsupported version | Replatform: upgrade PHP and the framework, version by version |
| The above, plus fragile code that slows every change | Replatform and refactor together: add tests around hotspots as you upgrade |
| The back end is sound, but the front end blocks design and performance | Rearchitect the front end only: move it to Next.js route by route, keep PHP as the back end |
| The team has moved to TypeScript and nobody wants to maintain PHP | Plan a full migration, incrementally. See the PHP to Next.js guide |
| A commodity function (CMS, shop, CRM) built by hand years ago | Replace it with a product, and migrate the data |
| Large parts are unused | Retire them first, whatever else you do |
| Any of the above will take months, and the runtime is unsupported | Cover the runtime with LTS for the length of the project |
Step 3: modernize incrementally
Whichever option you choose, the method that works is the same: small steps, each one released to production, each one reversible.
- Upgrade one PHP version at a time, and one framework major at a time. Each step is small enough to review and test properly. See why upgrades should ship incrementally.
- Automate the mechanical work. Rector handles most syntax and deprecation changes between PHP versions and framework majors. Engineers should spend their time on the changes that need judgment.
- Add tests where you change things, not everywhere. Characterization tests, which record what the code does today, are the fastest way to make a legacy area safe to change.
- Move routes, not applications. When rearchitecting, put the new system in front and move one route at a time, using the strangler approach.
- Keep shipping features. A modernization that freezes product work for a year loses its sponsor. Interleave both.
The rewrite trap
The most expensive mistake in legacy modernization is the big-bang rewrite: building a complete replacement beside the old system and switching over on one day. It is attractive because it promises a clean slate. It usually fails for predictable reasons:
- The old system's behavior is not documented; it is the documentation. The rewrite misses rules nobody remembered.
- The business does not stop. Features added to the old system during the rewrite have to be built twice.
- Nothing is delivered until the end, so the project has no evidence of progress and no early value, and its sponsors lose patience.
Rewrites succeed when they are done incrementally, which makes them rearchitecting in all but name.
What modernization should leave you with
At the end of a good modernization project you should have:
- A supported PHP version and framework, with a plan to stay current with one routine upgrade a year.
- Automated tests on the business-critical paths, and deployments that take minutes, not days.
- Dependencies that are maintained, with nothing abandoned left in the path of the next upgrade.
- A team that can change the system confidently, with knowledge written down.
- An architecture chosen for the next five years, whether that is PHP, Next.js or both.
If you would rather not run it yourself, see how we work, or start with an assessment.