Upgrading a Laravel 11 Application to Laravel 13 and PHP 8.5: What It Took

Upgrading a Laravel 11 Application to Laravel 13 and PHP 8.5: What It Took

We've just moved a client's internal staff application from Laravel 11 on PHP 8.2 to Laravel 13 on PHP 8.5. It's running on staging now. It's a small application, with eight Eloquent models, a handful of controllers and a 69-line routes file, and that's partly why it's a useful example: the framework upgrade turned out to be the easy part.

This post is what we actually did, in order. Our Laravel 9 to 13 guide covers the breaking changes in each version in more depth, and What a Laravel Upgrade Needs From Your Server covers the hosting side.

Where it started

The lockfile had laravel/framework at v11.1.1, a very early Laravel 11 release, and production runs PHP 8.2. Both have run out of road. Laravel 11 passed its security-fix date on March 12, 2026, so it's had no fixes of any kind since. PHP 8.2 gets security fixes until December 31, 2026. Laravel 13 needs PHP 8.3, so neither could move far on its own.

The code had come to us as a snapshot of what was on the production server, with no tests beyond Laravel's two examples. So the job included two things the framework upgrade itself doesn't: somewhere to run it that looks like production, and tests.

A staging server with every PHP version installed

Before touching the framework, we built a staging environment on its own small droplet. It's provisioned by the same scripts as production, from the same config files, with a per-environment settings file. Production's rendered config didn't change.

Staging installs PHP 8.2, 8.3, 8.4 and 8.5 side by side from Ondřej Surý's packages. Only one of them runs the PHP-FPM pool, the php command, Composer and artisan at a time, and that's a single line:

PHP_VERSIONS=(8.2 8.3 8.4 8.5)
PHP_VERSION=8.5

Changing PHP means editing that line, re-applying the server config (a few seconds while FPM moves to the new version), and redeploying, so Composer installs and the artisan caches are rebuilt on the new PHP. Going back is the same steps in reverse. When a version is right, the same change goes into the production settings file.

Staging also sits behind HTTP basic auth and tells search engines not to index it, and its deploys come from a staging branch, while production only ever deploys tagged releases.

It's the part that will still be useful next year, when PHP 8.6 or Laravel 14 comes along.

The Composer changes

The constraints that changed in composer.json:

Package Before After
php ^8.2 ^8.3
laravel/framework ^11.0 ^13.0
laravel/tinker ^2.8 ^3.0
phpunit/phpunit ^10.1 ^12.0
nunomaduro/collision ^8.1 ^8.6
laravel/sail ^1.18 ^1.41
mockery/mockery ^1.4.4 ^1.6
fakerphp/faker ^1.9.1 ^1.23

laravel/sanctum (^4.0), laravel/ui (^4.5), guzzlehttp/guzzle (^7.2) and spatie/laravel-ignition (^2.0) already allowed versions that support Laravel 13, so their constraints stayed and Composer moved them up within them.

The lockfile is where the size of the change shows. Of the 113 packages installed before, 98 changed version, 8 were added and 5 removed. Laravel ended up on 13.42.0, the Symfony components went from 7.0 to 8.1, and PHPUnit went from 10.5 to 12.5. Carbon was already on version 3, so the Carbon 2 removal in Laravel 12 didn't affect it.

Why one step instead of two

We usually go one major version at a time, because each upgrade guide is written for the version immediately before it. Here we read the 11 to 12 guide and checked each change against the code first:

  • HasUuids generating UUIDv7. No model uses HasUuids.
  • Carbon 2 removed. Already on Carbon 3.
  • The image validation rule rejecting SVGs. No validation rule uses image.
  • The local disk defaulting to storage/app/private. That only applies when the disk isn't defined, and config/filesystems.php defines it with storage_path('app'). The application doesn't use Storage anyway.

None applied, so going straight to 13 changed nothing that a separate 11 to 12 step would have caught. On a bigger application, any one of those could have, and we'd have done the hops separately.

The 12 to 13 guide has two changes that are easy to miss. The cache's serializable_classes defaults to false now, which doesn't matter here because nothing uses the cache. And the Laravel 13 skeleton sets session serialization to json, which logs everyone out if you change it on a live site. We didn't copy the new skeleton's config files over, and with no serialization key in config/session.php Laravel still uses php, so sessions carry on as before.

The three code changes

The CSRF middleware's parent class. Laravel 13 renamed the framework's CSRF middleware to PreventRequestForgery. VerifyCsrfToken still exists, marked @deprecated, so this wasn't breaking yet. In app/Http/Middleware/VerifyCsrfToken.php:

use Illuminate\Foundation\Http\Middleware\PreventRequestForgery as Middleware;

The application's own class kept its name, so app/Http/Kernel.php didn't need touching.

The $dates property on two models. Both soft-deleting models still had protected $dates = ['deleted_at'];. Laravel stopped reading $dates in version 10, and SoftDeletes casts deleted_at itself, so the lines were dead code. We removed them.

A PDO constant PHP 8.5 deprecates. Laravel's default config/database.php sets the MySQL SSL option with PDO::MYSQL_ATTR_SSL_CA. PHP 8.5 deprecates the PDO::MYSQL_* constants in favor of the driver-specific class that PHP 8.4 added:

use Pdo\Mysql;

// ...
Mysql::ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),

Pdo\Mysql doesn't exist before PHP 8.4. Laravel 13 itself runs on 8.3, but once this line is in, the config file fails to load on anything older than 8.4. If you make this change, set the php constraint in composer.json to ^8.4 so Composer's platform check says so before the application does.

What didn't need changing

The application still has the Laravel 10-era structure: app/Http/Kernel.php, app/Console/Kernel.php, and the long bootstrap/app.php that builds the application by hand. Laravel 11 introduced a slimmer skeleton, and Laravel has said from the start that existing applications don't need to move to it. It runs on 13 unchanged. Restructuring would have made this upgrade much bigger, and it would have mixed a cosmetic change into one where we needed to know exactly what had changed.

The PHP settings needed nothing either. In October, after PHP's advisory about session upload progress, we'd already turned session.upload_progress.enabled off in the FPM pool. The application keeps its own sessions in Laravel's file driver, has no file uploads, and never used the feature. PHP's November release now turns it off by default.

Testing it

We wrote unit tests, and end-to-end tests that go through the application the way its staff use it. Our 9 to 13 guide says an application without tests should get some before an upgrade, and on a job like this it's most of the safety net.

Staging runs on a copy of the production database with the sensitive data removed, so the tests and anyone checking by hand see real records in their real shapes without real personal details. Once our checks passed, the client used staging and reported what they found, and we fixed those issues.

Production is next, with the same steps: add PHP 8.5 to the production settings, apply them, and deploy the release.

If you have a Laravel application on an old version, or on a PHP version that's about to stop getting fixes, get in touch. We do Laravel upgrades and maintenance and can tell you how big the job looks before you commit to it.

Frequently asked questions

Can you upgrade from Laravel 11 straight to Laravel 13?

Sometimes. Laravel's upgrade guides are written one version apart, so read the 11 to 12 guide as well as the 12 to 13 one and check each change against your code. In this application none of the 11 to 12 changes applied, so one Composer change covered both. If any of them do apply to yours, do the hops separately.

What code changes does Laravel 13 need?

For this application, two framework-related ones. The CSRF middleware now extends PreventRequestForgery, because Laravel 13 deprecated the VerifyCsrfToken base class, and two models dropped the $dates property, which Laravel has ignored since version 10. The third change was for PHP 8.5, not Laravel.

What breaks when moving a Laravel app to PHP 8.5?

In this application, only a deprecation: PHP 8.5 deprecates the PDO::MYSQL_ATTR_* constants that Laravel's default config/database.php uses for the MySQL SSL option. The replacement is Pdo\Mysql::ATTR_SSL_CA, which only exists from PHP 8.4, so making that change means the application needs PHP 8.4 or newer.

Do I need to move to the new Laravel 11 application structure before upgrading?

No. This application still has app/Http/Kernel.php, app/Console/Kernel.php and the older bootstrap/app.php, and it runs on Laravel 13. Laravel supports the older layout on purpose. Restructuring is a separate project.

How do you test a Laravel upgrade when the application has no tests?

Write some. For this application we wrote unit tests and end-to-end tests, ran it on a staging server with a copy of the production database that had the sensitive data removed, and then had the client use staging and report problems, which we fixed before production.

Why upgrade PHP and Laravel at the same time?

Laravel 13 requires PHP 8.3, so this application couldn't move past PHP 8.2 without a newer Laravel, or past Laravel 12 without a newer PHP. Doing the PHP switch on staging first, with every version installed, kept the two changes separable if something broke.

Work with Emyrix

Working on something like this?

We build and maintain Laravel applications — customer portals, internal tools, integration layers, and inherited codebases nobody wants to touch. If you've got a performance or security problem you'd rather not sit on, tell us what's going on and we'll tell you what we think.