Upgrading a Legacy PHP or Laravel App: A Safe Step-by-Step Plan

Upgrading a Legacy PHP or Laravel App: A Safe Step-by-Step Plan — cover image

Somewhere in your business, there may be a PHP application that quietly does important work. It might be the admin panel that runs operations, a customer portal built years ago, or the original version of your SaaS product. It still works, but nobody wants to touch it. The PHP version is old, a few packages have been abandoned, and every developer who opens the code sighs before saying, "We should really rewrite this."

Usually, you should not. A full rewrite is expensive, slow and risky, and it tends to throw away years of business rules that are hidden in the existing code. A better path for most teams is a staged upgrade: moving the existing PHP or Laravel app to supported versions step by step, with tests and safety nets at every stage.

This guide lays out that path, with a realistic example, a numbered plan, and the benefits you can expect at the end.

Why Old PHP Apps Become a Problem

PHP itself has improved enormously over the last several years. Modern versions are faster, have a stronger type system, and bring features like enums, readonly properties and better error handling. Laravel and other frameworks have evolved alongside it. The problem is not PHP. The problem is being stuck on a version that the rest of the world has moved past.

If you are still deciding whether to repair or replace, our article on when to rebuild legacy software versus paying down technical debt offers a decision framework. This guide assumes you have chosen to upgrade.

A Real-World Example: An Ageing Operations Portal

Consider an illustrative scenario. A logistics company runs an internal portal built on an older Laravel version several years ago. It handles bookings, driver assignments and invoice generation. The original developers have moved on. The app runs on a PHP version that has reached end of life, and the hosting provider has announced that it will stop supporting it.

The team's first instinct is a rewrite in a new stack. A quick estimate suggests many months of work, during which the old system still needs fixes. Instead, they choose a staged upgrade. They spend the first weeks adding tests around booking and invoicing, then upgrade the framework one major version at a time, replacing two abandoned packages along the way.

The result in a scenario like this is the same application, with the same screens staff already know, now running on supported versions with a basic test suite. New features that were previously blocked, like a modern payment integration, become possible. And at no point did the business have to freeze development or run two systems in parallel.

A good upgrade is boring. Users should barely notice it happened, except that things stop breaking.

Step-by-Step: The Safe Upgrade Plan

  1. Audit the current state. Record the PHP version, framework version, every Composer package and its status (maintained, abandoned or forked), the server setup, scheduled jobs and queue workers. Note any code that lives outside the framework, such as custom scripts or cron files.
  2. Get the app running locally and in staging. Containerise the existing setup with Docker so every developer can run the exact same environment. Create a staging server that mirrors production. Many legacy projects have never had one, and this step alone reduces risk.
  3. Write characterisation tests. Before changing anything, add high-level tests that capture current behaviour for critical flows: login, the main business transaction, report or invoice generation, and any integrations. These do not need to be beautiful. They just need to tell you when something changes.
  4. Add static analysis. Run a tool like PHPStan or Psalm at a low strictness level to find obvious errors, undefined variables and type mismatches. Fix the most serious issues and record a baseline for the rest.
  5. Replace abandoned packages. For each abandoned dependency, find a maintained alternative or bring the small amount of needed code into the project. Do this before the framework upgrade so each change can be tested in isolation.
  6. Upgrade PHP in small jumps. Move to the next supported PHP version, run tests and static analysis, and fix deprecations. Tools like Rector can automate many syntax changes. Repeat until you reach a currently supported version.
  7. Upgrade the framework one major version at a time. Follow the official upgrade guide for each version. Laravel Shift or Rector rule sets can handle much of the repetitive work. Deploy each step to staging and test thoroughly before moving on.
  8. Check performance under realistic load. Upgrades usually make apps faster, but configuration changes can surprise you. A quick load test helps. Our practical guide to load testing with k6 shows how to set one up.
  9. Release in stages. Deploy during a quiet period, keep a tested rollback plan, and monitor error logs closely for the first few days. If possible, route a small portion of traffic to the new version first.
  10. Set up ongoing maintenance. Add automated dependency checks, run tests in CI on every change, and schedule regular minor upgrades so the app never falls this far behind again.

Tools That Make the Job Easier

AI coding assistants can also speed up parts of this work, such as explaining unfamiliar code, drafting tests and suggesting fixes for deprecations. They still need careful review. Our AI legacy code modernization playbook covers how to use them safely.

Common Pitfalls

Upgrading everything in one big branch

A single long-lived upgrade branch drifts away from the main code, becomes painful to merge, and makes it hard to tell what broke. Small, frequent merges are much safer.

Ignoring scheduled jobs and queues

Cron jobs, queue workers and background scripts are often forgotten until they fail silently in production. Include them in your audit and your tests.

Mixing upgrades with new features

It is tempting to redesign screens while upgrading. Resist it. Keep the upgrade focused so any change in behaviour is clearly a bug, not a new feature.

Forgetting session and encryption changes

Framework upgrades sometimes change how sessions, cookies or encryption work. Read the upgrade notes carefully so users are not logged out unexpectedly or stored data becomes unreadable.

Key Benefits of a Staged Upgrade

If your team lacks the bandwidth for an upgrade like this, our web development services include legacy upgrades and ongoing maintenance for PHP and Laravel applications.

How to Explain the Upgrade to Non-Technical Stakeholders

One of the hardest parts of a legacy upgrade is not technical at all. It is convincing the business to invest in work that, if done well, users will barely notice. Founders and managers naturally prefer spending on visible features. Framing the upgrade correctly makes approval much easier.

Estimating effort honestly

Estimates for legacy work are uncertain because nobody fully knows what is hidden in old code. A useful approach is to time-box the audit and the first PHP version jump, then use what you learn to estimate the rest. This gives stakeholders a realistic picture after a few weeks instead of a guess on day one.

It also helps to agree upfront on what "done" means: supported PHP version, supported framework version, a defined set of critical tests passing in CI, and documented deployment steps.

Conclusion

Old PHP applications rarely fail suddenly. They become slowly more fragile, more expensive to change and more exposed to security issues. The temptation is to wait until the pressure forces a rewrite. A better approach is to act earlier, with a plan.

Audit what you have, add tests around what matters, replace abandoned packages, and upgrade PHP and your framework one step at a time. It is not glamorous work, but it turns a system everyone fears into one your team can confidently improve again.

Frequently Asked Questions

Is it better to upgrade a legacy PHP app or rewrite it?
For most working applications, a staged upgrade is lower risk than a rewrite. You keep business logic that already works, and you can ship improvements continuously. A rewrite makes sense mainly when the codebase is so tangled that every change breaks something, or when the product itself is changing direction.
Can I jump straight from an old Laravel version to the latest?
It is usually safer to upgrade one major version at a time, following the official upgrade guide for each step. Skipping versions makes it hard to tell which change caused a problem. Tools like Rector and Laravel Shift can automate much of the repetitive work at each step.
What if the app has no automated tests?
Start by writing a small set of high-level tests around the most important flows, such as login, checkout or report generation. These characterisation tests capture current behaviour so you can detect regressions during the upgrade, even if the code underneath is messy.
Why does running an unsupported PHP version matter?
Once a PHP version reaches end of life, it stops receiving security fixes. Hosting providers may also drop support, and modern libraries stop working with it. Staying on an unsupported version increases security risk and makes every future change harder.
How long does a legacy PHP upgrade take?
It varies widely with code size, test coverage and how many abandoned packages are involved. A small app might take a few weeks, while a large one with many custom packages could take several months, usually delivered in stages alongside regular feature work.