Skip to content

Example scenario · Legacy LAMP to managed PaaS · zero-downtime deploys · autoscaling

Modernizing a 10-year-old Laravel monolith without rewriting it

How a 12-person Canadian B2B SaaS moved a decade-old PHP/Laravel monolith from a single dedicated server to a managed PaaS in 8 weeks — zero-downtime deploys, PHP 8.2, autoscaling — without rewriting the app.

Illustrative client profile: Canadian B2B SaaS · ~12 employees · ~150 customers · PHP/Laravel monolith. This example scenario shows how we approach the work; it does not describe a specific client, and its figures are illustrative.

Outcomes

Monthly traffic
~6M requests/mo · 4 background workers
Uptime
99.98% post-migration (was ~99.4% with announced maintenance windows)
Response p95
p95 240 ms (was p95 720 ms during the 4PM batch jobs)
Tickets
−43% customer-reported incidents
Incident response
Sev-1 ack 12 min · automated rollback within 4 min on failed deploys
Migration window
23-min cutover · DB switchover under 90 seconds · zero customer-visible 5xx
MRR
Retainer continued + customer credit-incidents eliminated
Infra cost change
+11% on infra · −60% on founder-engineering time

The text message came in at 5:42 p.m. on a Friday in October. “Deploy failed. Site is down. Can’t roll back. About to start the weekend without login.” The CTO — also one of two co-founders, also the only person who had ever touched the production server — had pushed a tarball over scp, restarted Apache, and watched 502s start flowing. The build had a Composer dependency that needed a PHP extension the production box didn’t have. There was no staging environment to catch it. There was no previous-deploy directory to roll back to; the deploy script overwrote in place. Customers couldn’t log in for thirty-eight hours. Two of them filed credit requests. One of them, in the renewal conversation that followed, said the quiet thing out loud: we like the product. We’re not sure you’ll be running it in two years.

That was the conversation that triggered our engagement. Not the outage itself. The renewal call after it.

At a glance

  • 12-person Canadian B2B SaaS, CRM-adjacent, ~150 paying customers, ~6M requests/month with four background workers.
  • 10-year-old PHP/Laravel monolith on a single dedicated server. MySQL co-located. Redis on the same box. PHP 7.4 (EOL since November 2022). No staging. No CI. Deploys via scp.
  • Stack Harbor engaged for an 8-week migration to managed Cloud PaaS — same application, modern runtime, autoscaling, zero-downtime deploys, managed databases, staging that mirrors production.
  • 90 days after cutover: 99.98% uptime, p95 240 ms steady-state, deploy success rate 96% (rollback inside 4 minutes on the failures), customer-reported incidents down 43%, both founders out of the deploy path.

What the audit found

The audit ran ten business days. We didn’t propose architecture until we had finished it. Here is what we documented, in the order we found it.

Runtime: PHP 7.4. End of life since November 2022. The production server had never been upgraded because the founders weren’t sure what would break. A reasonable instinct in isolation; a compounding risk in practice. Composer hadn’t been run on the production box in fourteen months — the build was happening on the CTO’s laptop and being tarballed up.

MySQL: custom my.cnf, undocumented. Someone — not the current team — had tuned the InnoDB buffer pool, query cache (still on, despite being deprecated in 8.0), and a handful of session variables in 2018. The configuration worked. Nobody on the team could explain why each value was what it was. The file was 380 lines. We pulled it apart line by line; a third of the settings were defaults written explicitly, a third were 2018-era tuning advice from a blog post we found in the Wayback Machine, and a third were load-bearing tuning we eventually preserved.

Redis: same host, no persistence. Redis was running on the application box with no AOF, no RDB beyond the default, and a maxmemory policy of noeviction. It had filled up twice in the last year, at which point the application started throwing exceptions because the cache layer assumed Redis would always accept a write. The team had been restarting Redis to clear it.

The 4 p.m. batch job. A cron job kicked off at 16:00 ET every weekday, ran an invoice-generation pass over the customer table, and walked the application’s p95 response time from 180 ms to over 700 ms for the duration of the run. It was the single biggest customer-visible performance problem and the team had stopped noticing it because it had always been there.

The “queue worker” that was a poller. Background jobs — primarily transactional emails and webhook fan-out — were processed by a PHP script that ran every 30 seconds via cron, queried a MySQL table for pending jobs, and processed up to 50 of them. It was not a queue worker. It was a polling loop dressed as one. Failure semantics were ambiguous; jobs that errored were left in processing state and required a manual SQL update to retry. The team kept a Notion page of “stuck jobs to unstick on Monday.”

No CI. No staging. The CTO built locally, ran the test suite (122 tests, last passing run two months prior, currently nine failing), tarballed vendor/ with the code, scp’d it, and restarted Apache. The “rollback procedure” was to keep the previous tarball on his desktop. The Friday outage happened because the previous tarball had been deleted in a Downloads-folder cleanup the week before.

Backups: nightly mysqldump to S3. Retention 30 days. Restore had never been tested. We ran a test restore into a sandbox on day six; the dump completed, the schema imported, and one trigger failed to install because of a DEFINER clause referencing a user that didn’t exist in the sandbox. A real restore would have worked with manual intervention. It would not have worked unattended.

We wrote up nineteen findings. Twelve operational, four architectural, three contractual (the hosting provider’s terms gave them 72 hours to respond to a Sev-1, which nobody had read).

Why PaaS over a rebuild

We were direct with the founders about this on day eleven, because they expected us to recommend a rebuild and they had budgeted six months and a contractor for it.

A rebuild would have been the wrong move here. The application worked. The product fit the market well enough to retain 150 customers with no infrastructure team and a polling worker. Customer-facing problems were operational — outages, slow afternoons, the occasional 500 — not architectural. Rewriting a 10-year-old Laravel monolith with a small team is a 12-to-18-month project that ships no new customer value while it’s underway, and there is a non-trivial probability it never finishes. We’ve watched two companies in this stage band attempt a rewrite. Neither completed it. One ran out of money. One is two years in and still parallel-running.

The right move was different. Lift the working application onto a managed runtime that ships the operational maturity their team didn’t have time to build: autoscaling, zero-downtime deploys, managed databases with point-in-time recovery, a CI pipeline with rollback, a staging environment that actually mirrors production. Same code. Modern runtime. The founders go back to building product. The infrastructure becomes someone else’s full-time job.

There are teams for whom this would be the wrong call. If the application’s architecture is actively preventing you from shipping the next product line — if every new feature requires touching the same five thousand-line controller, if the data model has accumulated enough technical debt that even read queries are getting expensive — a rebuild may be the right call, and we will say so. This team was not in that position. They were six months from product-market fit graduation, not six months from architectural collapse.

The target architecture

Cloud PaaS. Stack Harbor’s PaaS substrate runs on Virtuozzo’s application platform; we use it because it gives us the autoscaling and isolation primitives we need without the leaky abstractions of a Kubernetes-on-everything story for a workload this size.

Application tier. Autoscaling group of PHP 8.2 containers, sized from 2 nodes minimum to 8 nodes maximum, scaling on CPU utilization above 70% sustained for two minutes and back down on idle below 30% for ten. The 4 p.m. batch job pre-warms an extra two nodes via a scheduled trigger at 15:55 ET so the autoscaler isn’t reacting to the spike — it’s already provisioned.

Managed MySQL. MySQL 8.0, primary + read replica, daily automated backups with seven-day point-in-time recovery. We ported the tuning we could justify from the old my.cnf and dropped the rest. The query cache went away. The InnoDB buffer pool was sized against the new instance class. The DBA notes are now a documented file in the runbook repository, not a 380-line config file nobody dared touch.

Managed Redis. Separate from the application nodes, with persistence and a sane eviction policy (allkeys-lru). Sized to absorb the cache load without filling. The application code that assumed Redis was always writable was patched to handle eviction gracefully — three lines of code, two changed call sites, on our prompt.

Queue worker, not poller. We moved the background jobs to Laravel’s built-in queue driver against the managed Redis. Two worker processes per application node, supervised. The “stuck jobs” Notion page was deleted in week six.

CI/CD with rollback. A GitHub Actions pipeline builds the application image on push, runs the test suite (we fixed the nine failing tests in week three, on a path we’ll come back to), promotes to staging automatically, and gates production deploys on a two-click approval. A failed health check after a production deploy auto-rolls back to the previous image within four minutes. Here’s the autoscale rule, edited for clarity:

autoscale:
  triggers:
    - metric: cpu
      threshold: 70
      sustained_for: 2m
      action: scale_up
    - metric: cpu
      threshold: 30
      sustained_for: 10m
      action: scale_down
  scheduled:
    - cron: "55 15 * * 1-5"  # 15:55 ET weekdays
      min_replicas: 4
      reason: "Pre-warm for 16:00 invoice batch"

Staging that mirrors production. Same image, same database engine version, weekly snapshot of production data with PII scrubbed by a documented script. The team’s first staging deploy on day five of the engagement surfaced a problem we’ll talk about next.

The PHP 7.4 → 8.2 hop

This was the technical centerpiece. PHP 8.2 is two major versions and four minor versions ahead of 7.4. Anybody who has done this hop on a 10-year-old codebase knows what they’re walking into: a long tail of 8.0 deprecated, 8.1 deprecated, 8.2 deprecated, and the occasional outright breaking change. We ran the compatibility audit with PHPCompatibility and Rector in week two, against the application code, the Composer dependencies, and the small handful of in-house packages.

The audit surfaced 314 deprecation warnings and 47 fatal issues. Four of the fatal issues were load-bearing. The rest were mechanical.

Issue one: dynamic properties. PHP 8.2 deprecates dynamic property assignment on classes that don’t declare #[AllowDynamicProperties]. The application had 60 places where this happened — mostly on Eloquent models being decorated with computed fields after the fact. We added #[AllowDynamicProperties] to the offending parent classes as a tactical fix, and filed an issue against the team’s backlog to refactor toward explicit properties or accessor methods. The tactical fix shipped. The refactor is ongoing as a separate workstream.

Issue two: each() removed in 8.0. Two helper functions used each() in a while loop pattern that doesn’t survive past PHP 7.4. Both were in one date-range utility that hadn’t been touched since 2017. We rewrote them as foreach loops. Twelve lines of code, two unit tests added.

Issue three: a Composer dependency that pinned to PHP < 8.0. A markdown-parsing library, used by exactly one route (an admin help-page renderer), had not been updated since 2019 and required PHP < 8.0 in its composer.json. We replaced it with a maintained alternative (league/commonmark), wrote a one-page migration note in the runbook repository, and shipped it in week four.

Issue four: a custom MySQL collation. The application’s users table used utf8_general_ci — not utf8mb4. Customer names with accented characters (a lot of é and ç in a Canadian customer base) had been silently truncated for years; the team had a “known issue” tag in their support tool for it. The migration to the managed MySQL was the natural moment to fix this. We converted the schema to utf8mb4_unicode_ci in a separate migration step, recovered the original characters from the application’s audit log (which was thankfully on a different table that had used utf8mb4), and shipped the fix with the cutover. We made sure the founders saw the diff. They had not known the audit log preserved the correct encoding.

The remaining 310 deprecation warnings were mechanical — null-on-non-nullable parameters, optional-parameter-before-required, that family. We ran Rector with a conservative ruleset and committed the diff over three days, with each rule landing in its own commit so the team could review it.

By the end of week five, the application ran on PHP 8.2 in staging against a clone of the production database. The test suite was back to green. Local performance on the staging dataset was 30–40% faster on the hot paths.

The cutover

We ran cutover on a Sunday at 02:00 ET in week eight. The maintenance window communicated to customers was four hours. The actual customer-visible degradation was 23 minutes, with the DB switchover taking 87 seconds.

The plan, as documented in the runbook:

  1. Freeze writes at the application layer (read-only mode, customer-facing banner).
  2. Take a final logical replication snapshot of the production MySQL to the managed MySQL primary. Replication had been running for 36 hours at this point and was sitting at sub-second lag; the final snapshot was 41 seconds of binlog catch-up.
  3. Repoint the application’s database connection string in the PaaS environment to the managed MySQL. Restart the application nodes in a rolling fashion.
  4. Switch DNS at the CDN provider, using a pre-staged 60-second TTL that had been deployed 48 hours earlier.
  5. Smoke-test the five highest-revenue routes plus the 4 p.m. batch job (manually triggered against a non-billable customer).
  6. Lift read-only mode. Watch.

The moment of tension was step three. The first application node came up clean. The second hit a connection error against the managed MySQL and refused to serve traffic. The on-call senior engineer paused the rollout (the deploy pipeline supports a hold-and-investigate state), pulled logs, and found that the application’s connection pool was configured for a host that resolved to the old MySQL via the application’s local /etc/hosts override — a holdover from a 2021 incident response that nobody had documented. Three minutes to find, one minute to remove, two minutes to re-roll. The total customer-visible 5xx count during cutover was zero; the read-only mode handled the gap. The 23 minutes was the read-only window, not an outage.

We held the application in monitoring-only mode for 30 minutes after lifting read-only. No anomalies. We released the all-clear to the founders at 02:58 ET. The next 4 p.m. batch job, the following day, completed in 8 minutes against the new architecture (it had been taking 22). The autoscaler pre-warmed for it. The p95 during the batch was 260 ms.

90 days after

The metrics block at the top of this page covers the headline numbers. With context:

  • Uptime: 99.98% across the 90-day window, against a measured 99.4% across the previous six months (and that 99.4% included announced maintenance windows the founders had stopped announcing because customers complained). The improvement is partly fewer incidents and partly faster recovery on the incidents that did happen.
  • Performance: p95 240 ms steady-state, against p95 720 ms during the 4 p.m. batch jobs on the old environment. The batch job no longer touches customer-facing latency at all; it runs in isolation on a pre-warmed pool.
  • Deploy success rate: 96%. Of the 4% that failed (six deploys across the 90-day window), every one auto-rolled back inside four minutes. No customer saw a 5xx attributable to a failed deploy. The CTO told us, around day sixty, that he had stopped feeling his chest tighten when he hit “deploy.”
  • Customer-reported incidents: down 43%. The single biggest driver is the elimination of the 4 p.m. slowness — which had been generating ten to fifteen “is the site slow for anyone else?” tickets per week — but it’s also that the team can ship a fix for a bug in under an hour now, where it used to take a day.
  • Sev-1 ack: 12 minutes under our managed support. Our senior on-call engineers carry the Sev-1 pager. The trained rotation handles routine. The founders are no longer in the on-call path; they get a post-incident note within two hours of an acknowledged Sev-1.
  • Infrastructure cost: up 11%. We didn’t try to make this number go down. The old dedicated server was underpriced for what it was doing (and was about to be priced up at the next contract renewal, which we found in the provider’s terms during the audit). The +11% buys autoscaling headroom, managed database with PITR, managed Redis, and a staging environment that didn’t exist before. The founder-engineering hours saved — we estimate, conservatively, sixty hours per month between the two of them — is the cost number that matters at this stage.

One honest thing we are still working on with this team at the 90-day mark: test coverage. The application has 122 tests, all passing, but coverage is uneven. The hot paths are well-covered. The 4 p.m. batch job has one test. The admin help-page renderer has none. We have scoped a six-week test-hardening sprint with their lead developer, focused on the five most-changed files in the last six months of commits. That work is starting in month four. We did not push it into the cutover window because the cutover window had a finite number of engineering hours and we spent them where the production risk was.

What we’d say to a small SaaS in this position

If you’re a sub-twenty-person SaaS with a working application on aging infrastructure, the question is not whether to modernize. It is what to modernize and what to leave alone. A rebuild is the right answer when the application is what’s broken — when the architecture is the reason you can’t ship. A managed-PaaS migration is the right answer when the application works and the operational layer around it does not. We see both situations. We say both things.

The mistake we see most often in this stage band is the inverse pairing: a team rebuilds an application that worked, ships nothing for fourteen months, and emerges with a different application running on the same un-monitored dedicated server. The architecture changed. The operating model did not. The next Friday outage looks the same as the last one.

A managed PaaS migration is a smaller bet, finished in weeks rather than quarters, and it leaves you with a runtime your team can ship into for years before the application’s architecture becomes the constraint. When it does, you rebuild — with a staging environment to test the rebuild in, a CI pipeline to ship it through, and an operating layer that didn’t disappear when the architecture changed.

That is what we built here. That is what Cloud PaaS is meant to do.


This is an example scenario: an illustrative engagement that shows how we approach this kind of work. It does not describe a specific client, and its figures are illustrative.

Considering a similar migration? Read about Cloud PaaS or request a modernization assessment.

Tell us what you're running. We'll tell you what needs to change.

Book a consult with Stack Harbor. We will review your current environment, risk points, support needs, and the best path forward.