DEV Community

Cover image for Test Your Laravel App on PHP 8.4 and 8.5 with Docker
devTalk
devTalk

Posted on Originally published at dev-talk.com

Test Your Laravel App on PHP 8.4 and 8.5 with Docker

Last updated: 18 November 2026. Based on Laravel 13.x, PHP 8.4.27 and PHP 8.5.12. SeeHow this was checkedat the end, because the Docker images themselves were not pulled for this article.

Most upgrade problems are not crashes. The app boots on the new PHP version, the tests go green, and the first sign of trouble is a deprecation warning in production logs, or a Composer package that refuses to install. The way to find them early is to run your real test suite on each PHP version you might deploy, side by side, without touching the PHP on your laptop.

The timing is not abstract. According to endoflife.date, PHP 8.4 leaves active support on 31 December 2026, PHP 8.2 loses security support the same day, and PHP 8.5 (released 20 November 2025) is supported until the end of 2029. The Laravel 13 docs list PHP 8.3 to 8.5 as supported. So 8.4 and 8.5 are the two versions most teams should be testing now.

What you need

  • A Laravel 13 project with a test suite (Pest or PHPUnit).
  • Docker with Compose v2 (docker compose, not docker-compose).
  • A database for the tests. This article uses MySQL in a container; use whatever matches production.

1. One Dockerfile, the PHP version as a build argument

The official php image publishes tags like 8.4-cli and 8.5-cli. In the image documentation at the time of writing, 8.5-cli pointed at 8.5.12 and 8.4-cli at 8.4.27. A floating minor tag is what you want for compatibility testing, since it picks up patch releases. Pin the full version only when you need a reproducible build.

# Dockerfile (project root)
ARG PHP_VERSION=8.4
FROM php:${PHP_VERSION}-cli

RUN apt-get update \
 && apt-get install -y --no-install-recommends git unzip libzip-dev libicu-dev \
 && docker-php-ext-install -j"$(nproc)" pdo_mysql bcmath intl zip pcntl \
 && rm -rf /var/lib/apt/lists/*

COPY --from=composer:2 /usr/bin/composer /usr/bin/composer

WORKDIR /app
Enter fullscreen mode Exit fullscreen mode

docker-php-ext-install is the helper script the image documents for bundled extensions. Install only what your app needs, and check what the base image already includes with docker run --rm php:8.5-cli php -m before adding more. Extensions from PECL (Redis, Xdebug) are a separate question: each needs a release that supports the PHP version you are testing, so confirm that per extension. The PIE article covers the newer install route.

2. Compose file with a health-checked database

The same service runs under either version. The version comes from an environment variable, and so does the name of the vendor volume:

# compose.yaml
services:
  db:
    image: mysql:8.4
    environment:
      MYSQL_DATABASE: laravel_test
      MYSQL_ROOT_PASSWORD: secret
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-uroot", "-psecret"]
      interval: 5s
      timeout: 3s
      retries: 20

  app:
    build:
      context: .
      args:
        PHP_VERSION: ${PHP_VERSION:-8.4}
    working_dir: /app
    volumes:
      - .:/app
      - vendor:/app/vendor
    environment:
      DB_CONNECTION: mysql
      DB_HOST: db
      DB_DATABASE: laravel_test
      DB_USERNAME: root
      DB_PASSWORD: secret
    depends_on:
      db:
        condition: service_healthy

volumes:
  vendor:
    name: vendor-php${PHP_VERSION:-8.4}
Enter fullscreen mode Exit fullscreen mode

Why a separate vendor volume per PHP version: Composer resolves packages against the PHP version it runs on and writes that result into composer.lock and vendor/. Sharing one vendor directory between versions hides exactly the problems you are looking for. With the interpolated volume name, PHP_VERSION=8.5 gets vendor-php8.5 and the default gets vendor-php8.4. I confirmed that interpolation with docker compose config.

3. Run the suite on each version

# PHP 8.4 (the default)
docker compose build app
docker compose run --rm app composer install
cp -n .env.example .env && docker compose run --rm app php artisan key:generate
docker compose run --rm app vendor/bin/pest

# PHP 8.5
PHP_VERSION=8.5 docker compose build app
PHP_VERSION=8.5 docker compose run --rm app composer install
PHP_VERSION=8.5 docker compose run --rm app vendor/bin/pest
Enter fullscreen mode Exit fullscreen mode

Run the two sequentially. Both use the same database, so parallel runs can step on each other's tables. Because of depends_on with service_healthy, docker compose run should start the db service and wait for its health check first. I could not run that part.

4. When Composer refuses the new PHP version

This is the most common first failure. A package declares its supported PHP versions as a closed list, and 8.5 is not in it. I reproduced it with a local package that requires ~8.2.0 || ~8.3.0 || ~8.4.0. Installing on PHP 8.4 worked. On 8.5.12:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires acme/legacy-pkg * -> satisfiable by acme/legacy-pkg[1.0.0].
    - acme/legacy-pkg 1.0.0 requires php ~8.2.0 || ~8.3.0 || ~8.4.0 -> your php version (8.5.12) does not satisfy that requirement.
Enter fullscreen mode Exit fullscreen mode

If you install from a lock file created on 8.4, Composer says "Your lock file does not contain a compatible set of packages" with the same reason. To find every offender in a real project:

docker compose run --rm app composer why-not php 8.5.12
docker compose run --rm app composer check-platform-reqs
Enter fullscreen mode Exit fullscreen mode

In my run, why-not listed the package and its constraint, and check-platform-reqs marked it failed. The real fixes are to update the package, replace it, or open an issue upstream. Composer has an --ignore-platform-req=php option for a throwaway experiment, but I did not use it here, and a green run with the check disabled tells you nothing about whether the package works.

5. Why a green test run is not enough: Laravel hides deprecations

Here is the part most "test on the new PHP" guides skip. I added a test that deliberately used null as an array key, which PHP 8.5 deprecates:

function lookup(array $map, $key)
{
    return $map[$key];
}

it('returns the empty-string entry for a null key', function () {
    expect(lookup(['' => 'empty'], null))->toBe('empty');
});
Enter fullscreen mode Exit fullscreen mode

On PHP 8.5.12 it passed, with no warning anywhere. The reason is in the framework: HandleExceptions routes deprecations to a log channel, and it skips them completely when the app is running tests unless the LOG_DEPRECATIONS_WHILE_TESTING environment variable is set. Turn that on and point the deprecations channel at stderr, and the test run prints it:

LOG_DEPRECATIONS_WHILE_TESTING=true LOG_DEPRECATIONS_CHANNEL=stderr vendor/bin/pest
Enter fullscreen mode Exit fullscreen mode
testing.WARNING: Using null as an array offset is deprecated, use an empty string instead in /app/tests/Feature/DeprecationTest.php on line 5
Enter fullscreen mode Exit fullscreen mode

I also tried PHPUnit's failOnDeprecation="true" in phpunit.xml. It made a plain unit test fail (exit code 1), but a test that boots the Laravel app still exited 0, because Laravel's error handler takes the deprecation before PHPUnit sees it. So the setting alone gives a false sense of safety in feature tests. The environment variables above are what make the deprecation visible, and a small script turns them into a failing build.

6. A compatibility script that fails on deprecations

Two kinds of deprecation need two checks. Compile-time ones (an implicit nullable parameter, an old cast name) are emitted when PHP reads the file, so a lint pass finds them in code your tests never execute. Runtime ones (null array offsets, string increments) only appear when the line runs, so they need the logging variables during the test run. Save this as bin/php-compat-check.sh and make it executable:

#!/usr/bin/env bash
set -uo pipefail

echo "PHP $(php -r 'echo PHP_VERSION;')"

# 1. Compile-time deprecations in project code.
scan=$(find app bootstrap config database routes tests -name '*.php' -print0 \
  | xargs -0 -n1 php -d error_reporting=-1 -d display_errors=1 -l 2>&1 \
  | grep -E '^(PHP )?Deprecated' || true)

if [ -n "$scan" ]; then
  echo "Compile-time deprecations:"
  echo "$scan"
  scan_failed=1
else
  scan_failed=0
fi

# 2. Runtime deprecations. Laravel ignores them while testing unless told otherwise.
export LOG_DEPRECATIONS_WHILE_TESTING=true
export LOG_DEPRECATIONS_CHANNEL=stderr
log=$(mktemp)
vendor/bin/pest "$@" 2>&1 | tee "$log"
tests_status=${PIPESTATUS[0]}

if grep -qE 'is deprecated' "$log"; then
  echo "Runtime deprecations:"
  grep -E 'is deprecated' "$log"
  exit 1
fi

[ "$scan_failed" -eq 0 ] && exit "$tests_status" || exit 1
Enter fullscreen mode Exit fullscreen mode

Run it inside the container: PHP_VERSION=8.5 docker compose run --rm app bin/php-compat-check.sh. I ran this script against PHP 8.4.27 and 8.5.12 and got three outcomes:

  • Clean tree: exit 0 on both versions.
  • A class withfunction greet(string $name = null): exit 1 on both 8.4 and 8.5 with Implicitly marking parameter $name as nullable is deprecated, naming the file and line. The tests themselves still passed, which is the point. On PHP 8.3 the same file produced no warning and exit 0.
  • The null-offset test above: exit 0 on 8.4, exit 1 on 8.5.

The lint pass reads each file's syntax with the running PHP, so it only sees compile-time problems. It will not find the null-offset case, which is why both checks exist. I also ran the lint pass over the roughly 8,700 PHP files of the test app's dependencies (Laravel, Pest, PHPUnit and their packages) on both versions, and it reported no deprecations. Your dependency tree is bigger, so run it over vendor once yourself, accepting that vendor code is not yours to fix.

7. What 8.4 and 8.5 deprecate that commonly hits Laravel apps

These are the ones I reproduced, with the message PHP printed. The full lists are in the UPGRADING files of each PHP release.

PHP Deprecated Message (shortened) Fix
8.4 Implicitly nullable parameter (string $x = null) Implicitly marking parameter $x as nullable is deprecated ?string $x = null
8.5 Non-canonical casts such as (boolean) Non-canonical cast (boolean) is deprecated, use the (bool) cast instead Use (bool), (int), (float), (string)
8.5 null as an array offset Using null as an array offset is deprecated, use an empty string instead Cast or default the key to ''
8.5 Incrementing a non-numeric string ($s++) Increment on non-numeric string is deprecated, use str_increment() instead str_increment()
8.5 Driver constants like PDO::MYSQL_ATTR_SSL_CA Constant PDO::MYSQL_ATTR_SSL_CA is deprecated since 8.5, use Pdo\Mysql::ATTR_SSL_CA instead See below

The PDO one lands in your database config, so it deserves a closer look. If config/database.php still has the old constant, PHP 8.5 prints the deprecation while the app loads its configuration. I saw it printed straight to the console during boot, not routed through the test log. The Pdo\Mysql class only exists from PHP 8.4, so a bare replacement would break 8.3. The Laravel docs use a version check:

'options' => extension_loaded('pdo_mysql') ? array_filter([
    (PHP_VERSION_ID >= 80500 ? \Pdo\Mysql::ATTR_SSL_CA : \PDO::MYSQL_ATTR_SSL_CA) => env('MYSQL_ATTR_SSL_CA'),
]) : [],
Enter fullscreen mode Exit fullscreen mode

With that pattern, booting the config on 8.4 and 8.5 printed no deprecation. If you also use PDO::MYSQL_ATTR_INIT_COMMAND or the other driver constants, the 8.5 UPGRADING file lists the replacement for each.

Other deprecations in the 8.5 notes that I did not reproduce include the backtick operator, a semicolon after case, curl_close(), constant redeclaration, and soft-deprecated __sleep() and __wakeup(). Search your code for them rather than waiting for a log line.

8. The same check in GitHub Actions

A two-version matrix reuses the Compose file. Each job builds the image for its version and runs the script:

# .github/workflows/php-versions.yml
name: PHP versions

on:
  pull_request:
  push:
    branches: [main]

jobs:
  tests:
    name: PHP ${{ matrix.php }}
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        php: ['8.4', '8.5']
    env:
      PHP_VERSION: ${{ matrix.php }}
    steps:
      - uses: actions/checkout@v4

      - name: Build the PHP image
        run: docker compose build app

      - name: Install dependencies
        run: docker compose run --rm -T app composer install --no-interaction --prefer-dist

      - name: Prepare the application
        run: |
          cp .env.example .env
          docker compose run --rm -T app php artisan key:generate

      - name: Run tests and fail on deprecations
        run: docker compose run --rm -T app bin/php-compat-check.sh
Enter fullscreen mode Exit fullscreen mode

fail-fast: false matters here, because you want to see the 8.5 result even when 8.4 fails. The workflow passes actionlint, but I did not run it on GitHub. For a version matrix without Docker, the setup-php route in GitHub Actions for Laravel: Run Tests with PHP Matrix, MySQL is lighter; Docker earns its keep when you want the same container locally and in CI.

Common mistakes

  • Sharing onevendordirectory between PHP versions, so Composer's result from one version masks the other.
  • Trusting a green run. Laravel suppresses deprecations while testing by default, as shown above.
  • Testing only the version you deploy. When you move from 8.4 to 8.5 later, the warnings arrive all at once. Running both now spreads the work out.
  • Forgetting the script's executable bit. The bind mount keeps host permissions, so run chmod +x bin/php-compat-check.sh and commit the mode.
  • Pointing the test run at a development database. Use a dedicated database name, as in the Compose file.

Related Dev Talk articles

Frequently asked questions

Do I need Docker for this?

No. Any way of running two PHP versions works, including your OS packages or a tool like Herd. Docker is convenient because the same image runs on your machine and in CI, and nothing changes on the host.

Can I run 8.4 and 8.5 at the same time?

Not against the same database without care, since both runs would use the same tables. Run them one after the other, or give each run its own database name.

Is PHP 8.3 still fine for a Laravel 13 app?

Laravel 13 requires PHP 8.3 as a minimum according to its docs, and endoflife.date lists 8.3 as security-supported until 31 December 2027. It is the oldest version worth keeping in a matrix, not a reason to skip testing 8.4 and 8.5.

Should I test the PHP 8.6 pre-release too?

The official image documentation lists 8.6 release-candidate tags. If you want early warning, add one extra matrix job marked continue-on-error: true so it never blocks a merge. I did not test any 8.6 build.

update log

  • 18 November 2026: first published.
  • To recheck on each update: the tag-to-version mapping of php:8.4-cli and php:8.5-cli, the 8.4 end of active support on 31 December 2026, the Laravel docs' supported PHP range, and whether the Laravel skeleton's config/database.php still needs the PDO version check.

Sources


Originally published on DEV Talk.

Top comments (0)