Digital Solutions Independent Digital Engineering Studio

Platforms

Modernising a Legacy PHP Application with Laravel, One Route at a Time

Why full rewrites of business PHP applications so often stall, and how to move to Laravel incrementally: tests around today's behaviour, a supported PHP version, Laravel in front of the old code, shared data and logins, then one route at a time.

Diagram: every request reaches Laravel first; rebuilt routes go to new Laravel code, the rest fall through a catch-all route to the legacy PHP code, and both share one database. Bars show the rebuilt share growing.
On this page
  1. Signs that it is time
  2. Why big-bang rewrites so often stall
  3. Step 1: Make the current behaviour visible
  4. Step 2: Get the runtime onto a supported PHP version
  5. Step 3: Put Laravel in front
  6. Step 4: Share data and logins between old and new
  7. Step 5: Move one route at a time
  8. Step 6: Bring scheduled work across
  9. When a rewrite is the better choice
  10. Planning and estimating
  11. How Digital Solutions approaches this work

Many businesses run on a PHP application written years ago. It handles orders, bookings, records or reports, it mostly works, and the business depends on it. It is also hard to change: there are no tests, HTML and SQL are mixed in the same files, it runs on a PHP version that no longer receives security fixes, and perhaps one person really understands it.

There are two ways out. You can rewrite the application from scratch, or you can replace it piece by piece while it keeps running. This article explains why the second approach is usually safer, and how to do it with Laravel: what to do first, how to run old and new code side by side, how to share data and logins between them, and how to know when the old code can finally be switched off. It is written for developers and for technical owners deciding how to approach the work.

Signs that it is time

  • The PHP version is out of support. PHP branches get two years of active support and then two years of security fixes only. As of December 2026, PHP 8.1 and everything older no longer receive security fixes, and PHP 8.2 reaches the end of its support on 31 December 2026 (PHP: supported versions). An application that cannot run on a supported version is carrying a risk that grows every month.
  • Small changes take days because nobody can predict what else they will affect.
  • There are no automated tests, so every release is checked by hand, or not at all.
  • Deployment is manual, for example by copying files to the server.
  • Knowledge sits with one person.

None of these on its own means the application must be replaced. Together they usually mean it cannot be changed safely, which is the real problem.

Why big-bang rewrites so often stall

A complete rewrite looks clean: design it properly, build it, switch over on a chosen date. In practice:

  • The old system contains rules nobody wrote down. Rounding in invoices, special cases for particular customers, a report that one manager depends on. They surface late, often after the switch-over.
  • The business does not stop changing. Every change made to the old system during the rewrite has to be made twice.
  • There is no value until the end. Months of work produce nothing the business can use, which makes the project vulnerable to being cut.
  • The switch-over is a single, high-risk event, including a full data migration.

The alternative has a name: the strangler fig pattern, described by Martin Fowler as "a gradual approach to legacy modernization" (Martin Fowler: Strangler Fig Application). New code grows around the old system and takes over one part at a time until the old system can be removed. Every step is small, delivers something, and can be reversed.

Step 1: Make the current behaviour visible

Before changing anything, find out what the application actually does:

  • Every entry point: pages and scripts reachable over the web, including forgotten ones.
  • Every scheduled task: cron jobs and what they run.
  • Every database table, and which scripts read and write it.
  • Every integration: payment gateways, email, file imports and exports, other systems that call this one.

Then protect the most important behaviour with characterisation tests: tests that record what the system does today, right or wrong, so you notice when that changes. At this stage they are usually high-level: request a page with known data and check what comes back. They are not elegant, but they turn "I hope nothing broke" into something you can run.

Step 2: Get the runtime onto a supported PHP version

Upgrading PHP is often the most urgent step for security, and it is usually separate from Laravel. Tools such as Rector automate many of the mechanical changes between PHP versions, and a static analyser such as PHPStan finds much of what remains. Very old code may still use functions that were removed long ago (the original mysql_* functions disappeared in PHP 7.0), which have to be replaced by PDO or mysqli first.

This step also decides how old and new code can run together. Laravel 13 requires PHP 8.3 or later (Laravel 13 release notes). If the old code can run on the same version, both can live in one process. If it cannot yet, they can still run side by side as two applications behind the same web server, each on its own PHP version, with the web server deciding which one handles each address. That is less elegant, but it lets the modernisation start before the last of the old code has been upgraded.

Step 3: Put Laravel in front

The core idea is simple. Laravel receives every request. If a route has already been rebuilt in Laravel, Laravel handles it. Anything else is passed to the old code.

One detail matters: Laravel's Route::fallback() only answers GET requests, and the old application also needs its form submissions. A catch-all route registered after everything else covers every method. In Laravel 11 and later it can be added in bootstrap/app.php, outside the web middleware group, so Laravel does not start its own session or demand its own CSRF token for pages it does not own yet:

// bootstrap/app.php
->withRouting(
    web: __DIR__.'/../routes/web.php',
    commands: __DIR__.'/../routes/console.php',
    then: function () {
        // Registered last: anything not handled above goes to the old app.
        Route::any('{legacyPath?}', LegacyController::class)
            ->where('legacyPath', '.*');
    },
)
final class LegacyController
{
    public function __invoke(Request $request): Response
    {
        // Make $_GET, $_POST, $_COOKIE and $_SERVER reflect this request
        // (needed in tests, harmless in production).
        $request->overrideGlobals();

        ob_start();
        // The old application's own front controller.
        require base_path('legacy/index.php');
        $html = ob_get_clean();

        return response($html, http_response_code() ?: 200);
    }
}

This works well for code that behaves like a normal PHP page, but old code has habits to check first:

  • exit and die end the whole request, so Laravel never finishes its response. Replace them in the paths that will run through the bridge.
  • global variables stop working as expected, because the old script now runs inside a method rather than at the top level of a file. Variables the old code defines at the top and reads elsewhere through global must be made global explicitly.
  • Several entry scripts instead of one front controller (/orders.php, /customers/edit.php) need a small allow-list that maps each address to its file. Never build the path from user input.

Once this is in place, something useful happens: Laravel's HTTP tests can exercise the old pages, so the characterisation tests from step 1 can live in the same test suite as the new code.

Step 4: Share data and logins between old and new

The database

Keep one database. Laravel's Eloquent models can map onto existing tables without changing them:

final class Customer extends Model
{
    protected $table = 'tbl_customers';
    protected $primaryKey = 'cust_id';
    public $timestamps = false;

    protected function casts(): array
    {
        return ['date_added' => 'datetime', 'is_active' => 'boolean'];
    }
}

To start managing the schema with Laravel migrations, php artisan schema:dump records the existing schema as a starting point; new changes are then made as migrations, and both halves of the application see them at once.

Sign-in

Sign-in is usually the hardest shared concern. A common sequence is to rebuild login in Laravel early and let the old pages trust it, or to have the old code read the new session for a while.

Old applications often stored passwords with fast, unsalted or outdated hashes. They can be upgraded without forcing everyone to reset their password, by checking the old hash once and replacing it at the next successful sign-in:

if ($user->legacy_password !== null) {
    // Reproduces exactly how the old system hashed passwords (hash_equals).
    $password = $request->input('password');

    if (! LegacyPassword::matches($password, $user->legacy_password)) {
        throw ValidationException::withMessages(['email' => __('auth.failed')]);
    }

    $user->forceFill([
        'password' => Hash::make($password),
        'legacy_password' => null,
    ])->save();
}

Accounts that never sign in keep the old hash, so set a date after which any remaining ones must reset their password.

Step 5: Move one route at a time

Choose the order deliberately:

  1. Areas that change most often, because every future change there becomes cheaper.
  2. Read-only pages and reports, which are low-risk and build confidence.
  3. Core transactions (orders, payments, payroll inputs) once the team and the tests are ready for them.

For each route: write or extend the tests, rebuild it in Laravel, release it, watch the logs, and then delete the old script and record it in a list of retired files. That last step matters. A modernisation that never removes old code ends up maintaining two systems.

Step 6: Bring scheduled work across

Cron jobs that call old scripts can move into Laravel's scheduler one at a time, so they gain logging and overlap protection:

// routes/console.php
use Illuminate\Support\Facades\Schedule;

Schedule::command('invoices:send-reminders')
    ->dailyAt('07:00')
    ->withoutOverlapping();

The server then needs only one cron entry, which runs php artisan schedule:run every minute, instead of a list of individual scripts.

When a rewrite is the better choice

The incremental approach is not always right. A rewrite, or a move to an existing product, can make more sense when the application is small enough to rebuild in a few weeks, when the business process itself is changing completely, or when a standard product now does what the custom system was built for. The same questions apply as in any build-or-buy decision: what fits the process, who will maintain it, and what it costs over its life.

Planning and estimating

Nobody can honestly estimate the whole modernisation on day one, because the inventory in step 1 always finds more than expected. What can be estimated is the first phase: the inventory, the PHP upgrade, the bridge and the first one or two routes. After that, the speed of each subsequent route is visible and the rest of the plan can be based on evidence. Keep releasing throughout, with backups and a way to roll back each step; the website maintenance and security checklist covers backups and restore tests.

How Digital Solutions approaches this work

Digital Solutions works on custom PHP development and Laravel business applications, including the situation the custom PHP service describes: legacy logic that has to be understood before it can be improved. The founder's background in WordPress, PHP and Laravel business systems is described on the Laravel and full-stack practice page.

If you depend on a PHP application that has become risky to change, the first step is usually the inventory and an upgrade path. Tell us what it does and what it runs on.

Explore Digital Solutions

/ or Ctrl / ⌘ K to open · ↑ / ↓ to navigate · Enter to follow · Esc to close