18 Jun 2026

Upgrading a Legacy Symfony App to Symfony 8 and PHP 8.5: The Phased Playbook

Upgrading a Legacy Symfony App to Symfony 8 and PHP 8.5: The Phased Playbook

Most Symfony upgrade guides end where the hard part starts. They walk you through composer.json, the new security system and annotations to attributes, then call it done once doctrine:schema:validate goes green on a fresh dev database. That green check means very little. A database built from your new entities will always match your new entities.

I've taken several client apps from Symfony 4.x and 5.4 on PHP 7.x up to Symfony 8 on PHP 8.5, and the same playbook has held up every time. It runs in seven phases, each one a separate commit, and the phase that decides whether cutover day is boring or a disaster is the one most guides skip: running the full migration path against a real production database import.

How do you upgrade a legacy Symfony app to Symfony 8?

Upgrade in phases on a dedicated branch, one commit per phase: survey the app, move the Docker stack to PHP 8.5, rewrite dependencies and config, migrate src/, then validate against a real production DB import. Baseline the legacy Doctrine migrations instead of fixing them, and ship one idempotent reconciliation migration for the remaining drift.

The target is Symfony 8.x, which is 8.1 at the time of writing. Symfony 8 needs PHP 8.4 or newer, and I run these apps on 8.5. If the client would rather stay on a long-term support release, 7.4 LTS is the other option; there's more on that choice in the FAQ.

PhaseWhat happensDone when
0. SurveyVersions, bundle list, Doctrine types, security style, uploads, frontend build, route listYou have a plan and a list of replacement mini-projects
1. InfrastructurePHP 8.5 image, new DB engine on a new volume, current Node LTSContainers up, bin/console about runs
2. Dependencies + configcomposer.json rewrite, config/ migration, DBAL 4 typescomposer update is clean inside the container
3. src/ migrationControllers, forms, entities, repositories, listeners, admins, commandsThe app boots and routes resolve
4. Schema + runtimeSchema diffs, page-by-page click-through, real prod DB import, migrate.shA prod dump migrates cleanly and every page loads
5. IntegrationsSOAP/WSDL, file uploads on the new Vich versionExternal calls work, or fail only for environmental reasons
6. FinishingDeploy script, backup, cutover, final verificationStaging is ready for the client to test

Work on a branch like upgrade/symfony-8 and keep each phase its own commit so the whole thing stays reviewable and bisectable. I also keep a running log file in the project root, appending a heading per phase with what actually changed: packages bumped from which version to which, bundles replaced and with what, migrations created, pages fixed, known issues left open. I write it as I finish each phase, not at the end. If the work gets interrupted, the log survives, and later it becomes the commit message source.

Phase 0: survey before touching anything

The survey decides your estimate. Write down the current Symfony and PHP versions (composer show symfony/framework-bundle), then go through the full bundle list and check each one on Packagist. An abandoned or incompatible package can't be fixed by bumping a version constraint. Treat each one as a small replacement project, and find them on day one.

What I've found in legacy appsWhat replaced it
CraueFormFlowBundleA hand-rolled multi-step wizard that keeps state in the session
FOSUserBundleSymfony's own security: password hashers and the authenticator system
Guard authenticatorsAuthenticators (guards are gone)
webpack-encoreVite
Old VichUploader / Liip versionsCurrent versions, same storage locations
Local .wsdl filesEnv-configured remote WSDL URLs behind a lazy client
DBAL array, object, json_array columnsjson where safe, a small legacy type shim where it isn't

Also check the Doctrine mapping format (annotations or attributes), the security config style (old encoders and guards, or authenticators), every VichUploader mapping and where its files live today, the frontend build tool and Node version, and every route in the app. That route list becomes your test plan in Phase 4.

For the DBAL types, don't stop at the mapping. Look at the real data sitting in those columns. That's what decides whether a column can move to json or needs the shim.

Phase 1: infrastructure first

Upgrade the Docker stack before any code, so everything after runs on the target platform. That means a PHP 8.5 image with the extensions the app needs, a current Node LTS, and usually a database engine bump too (MySQL 5.7 to MariaDB 11.x is a common one).

For the database, create a new named volume and leave the old data directory untouched. Keep a SQL dump in the project's Docker setup folder so anyone on the team can rebuild the DB. Then make sure the containers come up and bin/console about runs before you move on.

If your host PHP is older than 8.5, run every Composer and console command inside the container from here on:

docker compose exec php composer update
docker compose exec php bin/console about

Phase 2: dependencies and config

Rewrite composer.json to the target dependency set and resolve until composer update is clean. If you've already upgraded a sibling app the same way, copy its dependency set and config shapes instead of working them out again.

Then migrate config/: bundles.php, the security system (password hashers plus authenticators, no guards), the framework, Doctrine and Twig recipes, Sonata 4 admin service definitions, mailer, messenger and the asset build. Moving off FOSUserBundle is also a good moment to look at how the login itself is protected. I wrote up how I lock down a Symfony admin after credential spraying, and it fits on top of the new authenticator setup.

The DBAL 4 type problem

DBAL 4 dropped the array, object and json_array types. Some columns hold PHP-serialized arrays you can't rewrite safely, like legacy roles or stored API request payloads. For those I don't migrate data. I ship a small shim that re-implements the old array type:

namespace App\Doctrine;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;

/**
 * Re-implements DBAL's legacy "array" type, removed in DBAL 4,
 * so existing PHP-serialized columns keep working without a data migration.
 */
final class ArrayType extends Type
{
    public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
    {
        return $platform->getClobTypeDeclarationSQL($column);
    }

    public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?string
    {
        return serialize($value);
    }

    public function convertToPHPValue(mixed $value, AbstractPlatform $platform): mixed
    {
        if ($value === null) {
            return null;
        }

        $value = is_resource($value) ? stream_get_contents($value) : $value;
        $decoded = @unserialize((string) $value, ['allowed_classes' => false]);

        if ($decoded === false && $value !== 'b:0;') {
            return [];
        }

        return $decoded;
    }
}

Register it under the old name so every existing mapping keeps working:

# config/packages/doctrine.yaml
doctrine:
    dbal:
        types:
            array: App\Doctrine\ArrayType

Two things to decide per column. First, allowed_classes => false is right for plain arrays, since years-old serialized data shouldn't be able to wake up objects in your new codebase. If a column really holds objects, list those classes in allowed_classes instead, or they come back as __PHP_Incomplete_Class. Second, the shim turns an unreadable value into an empty array. That keeps pages loading, but if the entity is flushed later, the empty array overwrites the original payload. When that data matters, log or throw at that point instead of returning [].

Phase 3: migrating src/

This is the phase people picture when they think "Symfony upgrade", and it's the most mechanical. Controllers move to AbstractController with typed arguments and attribute routes. Entities, event listeners and subscribers move to attributes. Repositories extend ServiceEntityRepository. Forms get their option and typehint changes. Sonata admins move to the v4 API. Console commands become #[AsCommand] classes.

I also do the PHP 8.5 cleanup here: constructor promotion, readonly, and enums where they fit naturally. And I delete scaffolding the recipes drop in that the app doesn't use, Stimulus being the usual one.

AI coding tools are useful for this phase because the work is repetitive and the patterns are clear. I wrote about giving an agent real context about a Symfony app through MCP tools, which is what keeps it from guessing at your service wiring.

Phase 4: rehearse the Symfony 8 migration on a real production database

Start with the easy half. Run doctrine:schema:update --dump-sql against your existing dev database, the one that still has the old schema (not a fresh schema:create), and turn the diff into a migration. ORM 3 and bundle upgrades often change column definitions, audit tables especially.

Then click through every page, admin and front, with a real login. Mark each route on your list as you go. Runtime-only failures (Twig functions, form themes, serializer behavior) never show up in a static migration, so there's no shortcut. Some of what you find will be broken templates or dead routes that were already broken before the upgrade. Fix those minimally, for example by redirecting a dead route to the login page, and tell the client instead of inventing features.

Now the part that matters most.

Why the dev database lies to you

A dev database built with doctrine:schema:create from your new entities passes schema:validate trivially. It tells you nothing about whether a production schema that has collected years of migrations, hotfixes and manual changes will reconcile. So import an actual production dump into a scratch database and run the full migration path there. Every surprise below came from doing exactly that.

Surprise 1: production looks completely unmigrated

Doctrine Migrations 2 tracked applied migrations in a table called migration_versions, storing bare timestamps. The modern bundle reads doctrine_migration_versions and expects fully qualified class names. Import a prod dump, run doctrine:migrations:migrate, and Doctrine decides none of your legacy migrations have ever run. It tries to execute all of them from the first one.

They fail. Old migrations call APIs that DBAL 4 removed, and you'll see errors like Call to undefined method ...Platform::getName().

The tempting move is to go back and patch the legacy migrations so they run on DBAL 4. Don't. Those migrations already ran on production years ago. You'd be rewriting history to replay changes that are already in the schema. Instead, baseline them: tell the new tracker they're applied, without running them. On one client's app that meant marking 60 legacy migrations as applied, the oldest written in December 2020.

# Create the modern metadata table
bin/console doctrine:migrations:sync-metadata-storage --no-interaction

# Mark the whole legacy range as applied, without executing it
bin/console doctrine:migrations:version --add \
    --range-from='DoctrineMigrations\Version20200101000000' \
    --range-to='DoctrineMigrations\Version20250101000000' \
    --no-interaction

# Now only the new upgrade migrations run
bin/console doctrine:migrations:migrate --no-interaction

Use your own first and last legacy version names in the range. Everything you wrote during the upgrade comes after that range, so only the new migrations execute. Two warnings here. Don't delete the legacy migration classes to tidy up: --range only marks classes it can find, so whatever you removed stays "unapplied" in the tracker. And if you're coming from Symfony 3.x, the old migrations live in app/DoctrineMigrations under the Application\Migrations namespace and extend Doctrine\DBAL\Migrations\AbstractMigration, a class that no longer exists. Move them into migrations/, change the namespace and the parent class, and only then baseline. Otherwise Migrations 3 fatals before it gets that far.

Surprise 2: real drift that only production has

After the baseline and your security migration (FOSUser to Symfony's own user handling), run schema:update --dump-sql against the imported prod DB again. It usually still shows real drift. The common sources:

  • auditor-bundle. Every *_audit table gains a nullable extra_data column, diffs becomes native JSON, and created_at loses its DC2Type:datetime_immutable comment.
  • DBAL 4 JSON. Columns that were LONGTEXT with a DC2Type:json comment become native JSON. user.roles is the classic one.
  • Leftover FOSUser indexes on the user table.

Generate a migration with doctrine:migrations:diff against the imported DB, then rewrite it to be idempotent. The goal is one migration that's a no-op on a dev or CI database (already in the new shape) and a real transform on production:

<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20260601000000 extends AbstractMigration
{
    private const AUDIT_TABLES = ['user_audit', 'order_audit', 'page_audit'];

    public function getDescription(): string
    {
        return 'Reconcile a pre-upgrade schema with ORM 3 / DBAL 4 / auditor-bundle (idempotent).';
    }

    public function isTransactional(): bool
    {
        return false;
    }

    public function up(Schema $schema): void
    {
        foreach (self::AUDIT_TABLES as $table) {
            $this->addSql(sprintf('ALTER TABLE %s ADD COLUMN IF NOT EXISTS extra_data JSON DEFAULT NULL', $table));
            $this->addSql(sprintf('ALTER TABLE %s CHANGE diffs diffs JSON DEFAULT NULL', $table));
            $this->addSql(sprintf('ALTER TABLE %s CHANGE created_at created_at DATETIME NOT NULL', $table));
        }

        $this->addSql('ALTER TABLE `user` CHANGE roles roles JSON NOT NULL');
        $this->addSql('DROP INDEX IF EXISTS UNIQ_OLD_USERNAME_CANONICAL ON `user`');
    }
}

Why this shape works:

  • ADD COLUMN IF NOT EXISTS and DROP INDEX IF EXISTS are safe to repeat. They're MariaDB syntax, though. On MySQL, guard each statement in PHP instead, with $schema->getTable('user_audit')->hasColumn('extra_data') or hasIndex(), or a query against information_schema.
  • A CHANGE that sets a column to its final type is naturally re-runnable. Running it on a column that's already JSON changes nothing.
  • isTransactional(): false, because MariaDB auto-commits DDL anyway, so a transaction would only promise a rollback you don't get. The flip side: if a statement fails on bad data halfway through, the schema is left half reconciled. Fix the data, then re-run. That's exactly why the statements have to be idempotent, and why you rehearse on an import before production.

The roles line needs care. In the apps I've upgraded, user.roles was already JSON text in a LONGTEXT column, so the conversion was safe. If yours is still FOSUser's old DC2Type:array with PHP-serialized values, that CHANGE will fail, because the values aren't valid JSON. Either rewrite the values to JSON in the security migration first, or keep the column on the ArrayType shim.

On MariaDB, JSON is an alias for LONGTEXT with a json_valid() check constraint. That's the real bonus of running this against the import: it proves every existing row passes that check. If some old row holds invalid JSON, you find out on a scratch database, not during the production cutover.

Write the index name you actually see in your own diff output. The one above only shows the shape.

Surprise 3: the diff wants to delete things

This is where an upgrade can lose data. doctrine:migrations:diff and schema:update only know your entity mapping. Anything in the database that isn't mapped looks like garbage to them, so they'll happily suggest:

  • DROP TABLE migration_versions, the old tracker you just baselined against.
  • DROP TABLE for ad-hoc backup tables someone created on production years ago, something like users_backup_old. Nobody remembers why they exist, and that's exactly why you don't drop them in a framework upgrade.
  • DROP TABLE for tables left behind by bundles you removed.
  • Unmapped columns that predate the upgrade and may still hold data.
  • Tightening a column to NOT NULL because the entity says JoinColumn(nullable: false), when production never enforced that at the DB level.

Before you even consider any of these, look at the data:

-- Does the "obsolete" table hold anything?
SELECT COUNT(*) FROM users_backup_old;

-- Would NOT NULL break on real rows?
SELECT COUNT(*) FROM order_item WHERE order_id IS NULL;

Then strip them out of the migration. You'll end up with a handful of permanent, benign schema:validate diffs, and that's the correct result. Document each one in the migration's docblock with the reason it stays, so the next developer doesn't "fix" it. I'll take a few documented diffs over a perfectly clean validator that cost the client rows of production data.

migrate.sh: the one-time reconcile script

Once the sequence works on the import, wrap it in a script at the project root that someone can run once, right after importing a pre-upgrade prod DB. Here's the shape I use:

#!/usr/bin/env bash
#
# ONE-TIME reconcile after importing a pre-upgrade prod DB.
# Run once INSTEAD of deploy.sh's plain migrate step.
# Usage:  PHP_BIN=ea-php85 ./migrate.sh
set -euo pipefail

PHP_BIN="${PHP_BIN:-php}"
CONSOLE="$PHP_BIN bin/console"

FIRST_LEGACY="DoctrineMigrations\\Version20200101000000"
LAST_LEGACY="DoctrineMigrations\\Version20250101000000"

echo "==> 1/4  Ensuring the modern migration metadata table exists"
$CONSOLE doctrine:migrations:sync-metadata-storage --no-interaction

echo "==> 2/4  Baselining legacy migrations (mark applied WITHOUT running)"
$CONSOLE doctrine:migrations:version --add \
    --range-from="$FIRST_LEGACY" --range-to="$LAST_LEGACY" \
    --no-interaction

echo "==> 3/4  Applying new upgrade migrations"
$CONSOLE doctrine:migrations:migrate --no-interaction --allow-no-migration

echo "==> 4/4  Validating the schema"
set +e
$CONSOLE doctrine:schema:validate
VALIDATE_EXIT=$?
set -e

cat <<'NOTE'
Expected residual diffs (intentional, do not "fix"):
  - migration_versions: legacy tracker, kept
  - users_backup_old: production backup table, kept
NOTE

exit $VALIDATE_EXIT

Details that matter:

  • PHP_BIN is overridable. It's php inside the container and something like ea-php85 on a cPanel server.
  • The baseline step is safe to re-run. With a range, Migrations 3 reports versions that are already in the table and moves on. I don't append || true, because that would also swallow a real error like a mistyped range, and you want the script to stop there.
  • It ends with a printed list of expected diffs, so whoever runs it on cutover night doesn't panic at the schema:validate output.
  • LF line endings and chmod +x, with *.sh text eol=lf in .gitattributes. A script checked out with CRLF on a Windows machine fails in bash with cryptic $'\r' errors.

Phase 5: integrations, and what not to change

SOAP and WSDL

Move local .wsdl files to remote URLs configured by env vars. If your dev network can't reach the endpoint, wrap the client so the WSDL is only fetched on first call. Symfony's lazy: true can't proxy SoapClient's internals, so it has to be your own small wrapper:

final class LazySoapClient
{
    private ?\SoapClient $client = null;

    public function __construct(private readonly string $wsdlUrl, private readonly array $options = [])
    {
    }

    public function call(string $method, array $arguments): mixed
    {
        $this->client ??= new \SoapClient($this->wsdlUrl, $this->options);

        return $this->client->__soapCall($method, $arguments);
    }
}

Without this, a blocked WSDL turns unrelated pages into 500s just because a service got built during the request. A 403 or 404 from your dev network usually means the network can't reach the endpoint, and the code may be fine. Label each failure in your report as environmental or as a code bug, so the client knows what to test on staging.

Don't move file storage to S3 during the upgrade

It's tempting. You're already touching VichUploader, the client mentions S3 sometime, and it feels efficient to do both at once. Don't. Changing the storage backend is a separate project with its own risks: credentials, a data migration for existing files, and the URL of every existing DB row. Bundle it into the framework upgrade and any bug could come from either change.

Keep every Vich mapping on its current upload_destination and uri_prefix and just make it work on the new Symfony and Vich versions.

When a client does ask for S3 as its own piece of work, get the bucket name and credentials before you write any code. An empty base URL env var silently produces relative URLs like /uploads/brands/logo.png. Those 404 with "No route found", which looks exactly like a routing bug and sends you debugging the wrong layer. Use a one-off command to push existing files to the bucket (with dry-run and check modes), set delete_on_update and delete_on_remove to false, and verify end to end: upload, count, download.

Don't add a directory namer to an existing mapping

Same trap, smaller. A date-based directory namer (Y/m/d from createdAt) looks like a harmless tidy-up. On a mapping that already has rows, it's a breaking change. The namer recomputes the directory at read time, so every existing row's URL moves to a path where its file has never existed. Every old upload breaks at once. Only add a namer to a mapping with no existing rows, or migrate the files to match.

Phase 6: deploy and cutover

The deploy script for these apps is a single deploy.sh that works out the environment from the directory it runs in. Production requires typing yes. Composer gets resolved at runtime, because many cPanel accounts have no global composer and the checkout ships its own composer.phar. The exact PHP binary comes from the app's existing cron entries rather than a guess, since crontab -l shows which ea-phpXX the server really runs.

The cutover note is the one people miss. On the first deploy after importing the pre-upgrade production DB, run migrate.sh once instead of relying on deploy.sh's plain doctrine:migrations:migrate. That plain step would hit the legacy migrations and die on DBAL 4. Every deploy after that, the normal migrate step works fine.

And before migrate.sh touches production, take a full dump or a database snapshot. The reconciliation migration is non-transactional DDL, so your rollback plan is restoring that dump, not migrations:migrate prev.

# 0. Backup first. Rollback = restore this dump.
mysqldump --single-transaction --routines --triggers app_db | gzip > pre-upgrade-$(date +%Y%m%d-%H%M).sql.gz

# 1. First deploy after the prod import only
PHP_BIN=ea-php85 ./migrate.sh

# 2. Every deploy after that
./deploy.sh

Final verification: the full page click-through again, imports and cron jobs actually run (heavy import jobs deserve their own test, and I've written about speeding up big Symfony imports), composer validate passes, and the logs aren't full of deprecation warnings. Then hand over a summary: replaced bundles, behavior changes, and everything you couldn't verify locally, like blocked endpoints or production-only integrations, so the client can test those on staging.

FAQ

What decides how long a Symfony 4 to 8 upgrade takes?

The Phase 0 survey answers this for a specific app, and the same few things drive it every time. Abandoned bundles each need a replacement, with FOSUserBundle and CraueFormFlowBundle being common ones. Sonata admins have to move to the v4 API. Columns using DBAL types that DBAL 4 dropped need their real data checked. SOAP and other external integrations need testing against real endpoints. And then there's the drift the production import turns up, which you can't size until you've imported a real dump.

Should I target Symfony 7.4 LTS or 8.x?

Choose 7.4 LTS if the client can't commit to a minor upgrade every six months, since each Symfony 8.x minor gets bug fixes for only eight months. Go with 8.x if you want the newest framework features on PHP 8.5 and the team will keep up with those minor bumps. The playbook is the same either way; only the target versions in composer.json change.

Can I go straight from Symfony 4.4 to Symfony 8?

Yes, that's what this playbook does, on one branch, split into reviewable phase commits. The trade-off is real: you skip the intermediate releases, so you don't get the deprecation log from each one telling you what to change next. That's why the full page click-through and the production import rehearsal carry so much weight here. They catch what the deprecation warnings would have pointed at.

Do I need to fix my old Doctrine migrations for DBAL 4?

No. They already ran on production. Baseline them with doctrine:migrations:version --add over the legacy range so the new tracker marks them applied, then put any remaining schema changes in one idempotent reconciliation migration. Keep the old classes in the repo so the range can find them.

Should I move uploads to S3 while I'm upgrading?

No. Keep local storage working on the new versions and treat S3 as a separate project. It brings credentials, a file migration and URL changes for every existing record, and mixing that into a framework upgrade makes every bug harder to trace.

Stuck on an old Symfony app?

I'm Adil, a full-stack developer in Tampa. I've spent 15 years building PHP, Laravel, Symfony and React apps for US brands, and taking over legacy Symfony apps and bringing them to current versions is a big part of my work. Lately I also add AI features to those systems, including making them usable by agents.

If your company runs a Symfony 4 or 5 app on PHP 7 that nobody wants to touch, I can survey it, give you a phase-by-phase plan and do the upgrade, including the production DB rehearsal. Development agencies can bring me in white-label on a client project. You can see what I offer, or send me your composer.json and Symfony version and I'll reply with a list of the risks I see.