← ALL ARTICLES

· Laravel · Laravel 13 · PHP 8.5

Upgrading a Laravel 5.4 site to Laravel 13 and PHP 8.5

Moving a ten-year-old site from Laravel 5.4 and PHP 7.4 to Laravel 13 and PHP 8.5 in one go: the slim bootstrap, quiet behaviour changes, Vite and CI.

jedkirby.com has been a Laravel app since March 2016, and until this October it was still running Laravel 5.4 on PHP 7.4, with Gulp and Laravel Elixir building the assets. PHP 7.4 reached end of life on 28 November 2022. On 21 October 2026 I moved it to Laravel 13 and PHP 8.5 in a single pull request: twelve framework releases, the new slim application structure, Vite instead of Elixir, and updated CI and deploy workflows. If you're looking after an old Laravel 5.x app and wondering how to upgrade it to Laravel 13, this is what changed, what nearly broke without anyone noticing, and how I checked the site still behaved the same.

One jump, not twelve

Laravel's upgrade guides go one release at a time, and they're written for apps that have kept up. The Laravel 11 upgrade guide even says it does not recommend that Laravel 10 apps migrate to the new application structure, because Laravel 11 still supports the old one. That's good advice for a Laravel 10 app. For a 5.4 app there's far less worth keeping: files like bootstrap/autoload.php, config/compile.php and server.php belong to a skeleton that's long gone.

So rather than stepping through 5.5, 5.6 and onwards, I treated it as moving the app's own code (the domain classes, views, routes and tests) onto a current Laravel 13 skeleton. The upgrade guides were still essential, but as a list of behaviour changes to check rather than steps to follow. Laravel 13 was released on 17 March 2026, needs PHP 8.3 or later, and gets security fixes until 17 March 2028, so it's a sensible place to land.

The slim bootstrap: where everything went

Laravel 11 folded the HTTP kernel, console kernel, exception handler and most service providers into bootstrap/app.php. On this site that removed app/Http/Kernel.php, app/Console/Kernel.php, app/Exceptions/Handler.php, the RouteServiceProvider, the CSRF middleware class and a provider that set up Slack error logging (which is now a channel in config/logging.php). The remaining providers are listed in bootstrap/providers.php.

The old kernel was deliberately tiny:

// app/Http/Kernel.php (Laravel 5.4)
class Kernel extends HttpKernel
{
    protected $middleware = [
        \App\Http\Middleware\TrustProxies::class,
        \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
    ];

    protected $middlewareGroups = [
        'web' => ['session', 'csrf', 'bindings'],
    ];
}

And this is roughly where it ended up:

// bootstrap/app.php (Laravel 13)
return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(web: __DIR__ . '/../routes/web.php')
    ->withMiddleware(function (Middleware $middleware): void {
        // use() replaces the default global stack, so TrimStrings and
        // ConvertEmptyStringsToNull are deliberately left out.
        $middleware->use([
            TrustProxies::class,
            RemoveTrailingSlash::class,
            PreventRequestsDuringMaintenance::class,
        ]);

        $middleware->group('web', [
            StartSession::class,
            ValidateCsrfToken::class,
            SubstituteBindings::class,
        ]);
    })
    ->withExceptions(function (Exceptions $exceptions): void {
        // The site's own error page, as before.
    })->create();

The detail worth slowing down for is $middleware->use(). It replaces Laravel's default global middleware rather than adding to it, and that default stack includes TrimStrings and ConvertEmptyStringsToNull. A fresh Laravel 13 app runs both on every request; this site never had them. Its contact form has a hidden honeypot field and expects form input exactly as it was submitted, so quietly picking up the new defaults would have made the honeypot treat every genuine message as spam. Nothing would have errored. Messages would just have stopped arriving.

If you're upgrading from an old version, compare your old $middleware and $middlewareGroups with the new defaults line by line, and decide on purpose which ones you want.

Behaviour that changed without an error

The failures that worry me in a big upgrade aren't the ones that throw. They're the ones where the code still runs and does something slightly different. Three from the upgrade guides applied here.

Cache lifetimes moved from minutes to seconds in Laravel 5.8, rated "Very High" likelihood of impact. The site caches Cloudflare's IP ranges so it can trust their proxy headers, and the TTL was the integer 1440:

// Laravel 5.4: 1440 minutes, i.e. a day.
// Laravel 5.8 and later: 1440 seconds, i.e. 24 minutes.
$this->cache->put($key, $ips, 1440);

// Unambiguous in every version:
$this->cache->put($key, $ips, now()->addDay());

That's not a bug you'd spot by clicking around; it just means 60 times as many requests to Cloudflare. Search your code for integer TTLs passed to put, add and remember, and use a date or now()->add...() instead.

Blade started double-encoding entities in Laravel 5.6. Some of the site's content, such as the case study intros, contains & and relied on the old behaviour, so Blade::withoutDoubleEncoding() in AppServiceProvider keeps the output identical.

The email validation rule became RFC-based in Laravel 5.8, which accepts addresses like email@example that the old filter_var check rejected. The contact form now uses email:filter, which uses PHP's filter_var as before.

I also kept the old environment variable names (MAIL_DRIVER, CACHE_DRIVER, QUEUE_DRIVER) as fallbacks in the config files, so the production .env didn't need to change on the day of the deploy. That's one less thing to get right at the same moment as everything else.

Replacing abandoned packages

The Laravel Collective abandoned laravelcollective/html in 2023, and it doesn't support Laravel 11 or later. The site only used it for a handful of form fields and for obfuscated mailto: links, so it became plain Blade plus a small mailto() helper that mixes decimal and hex HTML entities the way Collective's did. The reCAPTCHA package went the same way: a small in-app service and a recaptcha validation rule, with the same markup and config file.

For heavier form-builder use, spatie/laravel-html is the usual replacement. But when a package is doing very little, a few lines of your own code you can read is often better than another dependency to upgrade next time.

Gulp and Elixir to Vite

Elixir was replaced by Laravel Mix years ago, and Vite has been the default for new Laravel apps since mid-2022, so the build moved straight from a Gulp file to Vite 8 and Dart Sass. In the views it's a small change from elixir() to the @vite directive:

<!-- Before: Laravel Elixir -->
<link href="{{ elixir('assets/css/build/main.css') }}" rel="stylesheet">
<script src="{{ elixir('assets/js/build/app.js') }}"></script>

<!-- After: Vite -->
@vite('resources/assets/sass/main.scss')
@vite(['resources/assets/js/vendor.js', 'resources/assets/js/app.js'])

Two things caught me out. First, Vite's default CSS minifier is Lightning CSS, which doesn't just minify but rewrites some rules, including normalize.css's deliberate monospace, monospace font hack. Switching to esbuild (which has to be installed separately) kept the output equivalent to the old build:

// vite.config.js
export default defineConfig({
    plugins: [laravel({ input: [/* ... */], refresh: true })],
    build: {
        // esbuild only minifies; Lightning CSS (the default) also rewrites rules.
        cssMinify: 'esbuild',
    },
});

Second, Vite bundles JavaScript as ES modules, so old scripts that expected jQuery to be a global needed it put on window explicitly. Node went from 8 to 24 and Yarn was replaced with npm ci at the same time.

Proving nothing changed

With this much moving at once, "the tests pass" isn't enough on its own, because the old tests mostly called controllers directly. So the upgrade added tests that go through the full HTTP kernel: every page, every article, the sitemap, the 404 and 500 pages, the contact form (valid, invalid and honeypot) and reCAPTCHA. 101 tests passed on PHP 8.5.

Then I ran the old and new stacks side by side in Docker and crawled both. All 34 responses (every page, all 22 articles at the time, the sitemap, 404s and contact form posts) and 73 referenced assets returned matching status codes. The HTML was identical apart from the asset tags, Facebook's newer share URL from an updated package, and the code samples in one article, which Laravel 5.4's Blade had been re-spacing. A semantic diff of the CSS showed the same rules, apart from colours rounding differently by 1/255.

That comparison is what made a one-jump upgrade feel safe. It's cheap to do: you need both versions running and a list of URLs.

CI and deploy

The old Travis CI config went, and the GitHub Actions deploy workflow moved to PHP 8.5, Node 24 and npm run build. Because Composer runs with --no-scripts in the build, package discovery now runs on the server after the files are synced, along with clearing views compiled by the previous release:

# Composer runs with --no-scripts, so discover packages on the server and
# drop any views compiled by the previous release.
# NB: Don't add `config:cache`; some config files contain objects.
- name: Optimise
  run: ssh ${{ env.DEPLOY_USER }}@${{ env.DEPLOY_HOST }} 'php${{ env.DEPLOY_PHP_VER }} ${{ env.DEPLOY_PATH }}/artisan package:discover && php${{ env.DEPLOY_PHP_VER }} ${{ env.DEPLOY_PATH }}/artisan view:clear'

Note the comment about config:cache: this site's blog config holds Carbon objects, which can't be cached, so the usual optimisation step would break it. Check your own config files before adding it.

One more gotcha came the same night: the repository's default branch had been renamed from master to main, so the deploy workflow wasn't triggering until its branch filter was updated. A separate CI workflow running PHPUnit and PHP CS Fixer on every pull request followed later, along with the code-style changes I'd left out of the upgrade to keep its diff reviewable. It now checks blog posts too, like the recent one on Composer dependency cooldowns, before they're published.

What I'd do

  • Check your PHP version first. Laravel 13 needs PHP 8.3 or later. PHP 8.5 came out on 20 November 2025 and has security support until 31 December 2029.
  • From Laravel 5.x, rebuild on a fresh skeleton and move your code across, rather than stepping through every version. Read the upgrade guides for behaviour changes.
  • Take over the global middleware stack on purpose, or not at all. TrimStrings and ConvertEmptyStringsToNull change what your form handlers receive.
  • Search for integer cache TTLs and replace them with dates.
  • Write full-kernel page tests before you start, then crawl the old and new versions and compare status codes and HTML.
  • Replace abandoned packages with your own code when you only use a small part of them.
  • Keep the pull request reviewable. Leave restyling and redesigns for follow-up PRs.

A ten-year-old site that had sat on Laravel 5.4 since 2020 sounds like a big upgrade, and it was. But most of the risk was in a short list of quiet behaviour changes, and checking those explicitly made it a lot less frightening.

Sources