CodeIgniter 4 Migration From Legacy PHP Code

Migrating legacy PHP into CodeIgniter 4 is a process. I share how I slice the work without stopping feature delivery.

CodeIgniter 4 Migration From Legacy PHP Code

The focus here is migrating legacy PHP into CodeIgniter 4 — not generic admin advice, but what I actually shipped. Migrating legacy PHP into CodeIgniter 4 is a process. I share how I slice the work without stopping feature delivery.

Migrate by Feature, Not by File Count

Migrating legacy PHP into CodeIgniter 4 is a process. I share how I slice the work without stopping feature delivery.

  • module extraction — applied directly to migrating legacy PHP into CodeIgniter 4.
  • route mapping — applied directly to migrating legacy PHP into CodeIgniter 4.
  • service classes — applied directly to migrating legacy PHP into CodeIgniter 4.
  • phased cutover — applied directly to migrating legacy PHP into CodeIgniter 4.

How I Built It

The working version of CodeIgniter 4 Migration From Legacy PHP Code centred on module extraction, route mapping, service classes, and phased cutover. I avoided copying patterns from other modules unless they solved a problem this feature actually had.

Keep Legacy Running During Transition

Representative code from the implementation — simplified for readability, but structurally what I deploy.

CodeIgniter 4 service registration

<?php
namespace App\Services;

class OrderService
{
    public function __construct(private \App\Models\OrderModel $orders) {}

    public function markShipped(int $id, int $actorId): void
    {
        $this->orders->update($id, [
            'status' => 'shipped',
            'updated_by' => $actorId,
        ]);
    }
}

Cron heartbeat file for job monitoring

<?php
file_put_contents('/var/www/app/storage/cron-heartbeat.txt', time());
$last = (int) @file_get_contents('/var/www/app/storage/cron-heartbeat.txt');
if (time() - $last > 90000) {
    mail('ops@example.com', 'Cron failed', 'Nightly job did not run.');
}

Where This Approach Paid Off

Shipping migrating legacy PHP into CodeIgniter 4 cleanly meant the next developer could extend it without untangling hidden coupling.

Document the three configuration values that differ between staging and production — that saved me hours on similar projects.

Where I Would Begin Again

  1. Start with the exact problem statement for migrating legacy PHP into CodeIgniter 4 — one sentence, no buzzwords.
  2. Prioritise module extraction before polishing secondary UI details.
  3. Validate route mapping under realistic data volume, not demo rows.