Skip to content

Migrating PHP 7.x applications to PHP 8.x: the operator checklist

Migrate a production PHP 7 application to PHP 8 without taking the site down. You will scan the code for breaking changes, audit extensions and Composer packages, run PHP 8 in parallel on its own pool, and move live traffic over once your tests pass.

This guide walks you through upgrading a live PHP 7.x application to PHP 8.x on a server you run yourself. You likely have an app that works fine on PHP 7.4, a supplier or security scanner telling you to move, and no clear list of what will break. The safest route is to install PHP 8 beside PHP 7 instead of on top of it, then point a staging copy of the site at the new version. Once the compatibility scanner and your tests come back clean, you move production over by changing one line in your web server config and reloading it. By the end you will have PHP 8.3 serving live traffic with the PHP 7 setup still running, so a rollback takes seconds.

How to verify

Before anything else, get a baseline read on what PHP version is running where:

php -v
php-fpm8.1 -v 2>/dev/null || php-fpm8.0 -v 2>/dev/null
systemctl status "php*-fpm" --no-pager | grep -E 'Active|Main PID'
# CLI version mismatch check
php -r 'echo phpversion() . PHP_EOL;'
# Check what SAPI is wired to your web server
curl -sI https://example.com/info.php | grep -i 'x-powered-by'

Collect your extension inventory — you will need this to cross-reference PHP 8 availability:

php -m | sort
php -r 'foreach (get_loaded_extensions() as $e) echo $e . " " . phpversion($e) . PHP_EOL;'

What’s happening

PHP 8.0 is the hardest step: it removed create_function(), each(), ereg_* functions, short-open tags, and the __autoload() global. It also made the type coercion for strict comparisons more rigorous, which means code that compared 0 == "foo" and expected true in PHP 7 will get false in PHP 8 — silently breaking auth guards and lookup tables. PHP 8.1 adds the never return type, readonly properties, enums, and makes several implicit coercions emit deprecation notices. PHP 8.2 and 8.3 continue the trend of tightening what had been sloppy but legal PHP.

The most common runtime failures during a 7-to-8 migration are: (1) removed functions that were still in production code, (2) named argument collisions in user-defined functions that shadow built-ins, (3) extension version mismatches — the PHP 7 .so does not load under PHP 8 FPM, (4) OPcache preloading scripts that reference deprecated APIs, and (5) Composer packages that declared PHP 7 constraints and have not been updated.

Your web server does not know which PHP version handles a request — it just forwards to whichever FPM socket you configured. This gives you a clean mechanism for a parallel-pool upgrade: stand up an FPM pool bound to the new version, serve a staging vhost from it, test thoroughly, then atomically swap the socket path in your web server config.

The procedure

  1. Run a static compatibility scan against your codebase.

    composer require --dev phpcompatibility/php-compatibility
    vendor/bin/phpcs --standard=PHPCompatibility \
      --runtime-set testVersion 8.0-8.3 \
      --extensions=php -sp src/ web/

    Also run Rector in dry-run mode — it identifies remediable patterns automatically:

    composer require --dev rector/rector
    vendor/bin/rector process --dry-run src/
  2. Audit Composer dependencies for PHP 8 compatibility.

    composer outdated --direct
    # Check for packages that hard-constrain to ^7
    composer show --all | grep -E '"php".*7\.'
    # Run on PHP 8 in dry mode
    composer update --dry-run --ignore-platform-reqs 2>&1 | grep -i 'requires php'

    Packages that require ^7.4 will not install under PHP 8 without --ignore-platform-reqs. Identify whether they have PHP 8-compatible releases or need to be swapped.

  3. Install the target PHP-FPM version in parallel — do not remove PHP 7 yet.

    sudo add-apt-repository ppa:ondrej/php
    sudo apt update
    sudo apt install -y php8.3-fpm php8.3-cli php8.3-common \
      php8.3-opcache php8.3-mysql php8.3-redis php8.3-mbstring \
      php8.3-xml php8.3-curl php8.3-intl php8.3-gd

    Match your installed extension set against what you collected in step 1. Most extension packages exist under the php8.3-* namespace; some (like igbinary, imagick) may need PECL.

  4. Configure the PHP 8 pool to listen on a separate socket.

    ; /etc/php/8.3/fpm/pool.d/app-php83.conf
    [app-php83]
    user = www-data
    group = www-data
    listen = /run/php/php8.3-fpm-app.sock
    listen.owner = www-data
    listen.group = www-data
    pm = dynamic
    pm.max_children = 20
    pm.start_servers = 4
    pm.min_spare_servers = 2
    pm.max_spare_servers = 6
    pm.max_requests = 500
    php_admin_value[error_log] = /var/log/php8.3-app-fpm.log
    php_admin_flag[log_errors] = on
  5. Wire a staging vhost to the PHP 8 socket and run your test suite under traffic.

    # /etc/nginx/sites-available/staging-php83
    server {
        listen 443 ssl;
        server_name staging.example.com;
        root /var/www/app/public;
        location ~ \.php$ {
            fastcgi_pass unix:/run/php/php8.3-fpm-app.sock;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        }
    }

    Run your smoke suite and integration tests against staging.example.com. Enable E_ALL on this pool (php_admin_value[error_reporting] = E_ALL) to surface every deprecation notice before they become fatal in a later minor.

  6. Perform the production cutover atomically.

    Edit the production Nginx location block to point at the PHP 8.3 socket, then reload — not restart:

    # Change fastcgi_pass in /etc/nginx/sites-available/app.conf
    # From: fastcgi_pass unix:/run/php/php8.1-fpm-app.sock;
    # To:   fastcgi_pass unix:/run/php/php8.3-fpm-app.sock;
    sudo nginx -t && sudo systemctl reload nginx

    Keep the PHP 7 FPM pool running for 15 minutes post-cutover so you can rollback by editing the socket path and reloading again.

  7. Post-cutover: validate OPcache and preloading.

    php -r 'echo opcache_get_status()["opcache_enabled"] ? "enabled\n" : "disabled\n";'
    # If you use preloading:
    php-fpm8.3 -t
    journalctl -u php8.3-fpm --since "5 min ago" | grep -i preload

Common pitfalls

  • 0 == "foo" evaluates to false in PHP 8. Auth checks that compared a numeric-looking string against 0 with == will silently fail. Search your codebase for == 0 and == '' comparisons and audit them before cutover.
  • null coercion is now a deprecation notice. Passing null to a parameter typed as string or int emits E_DEPRECATED in PHP 8.1 and will become fatal in a future version. Grep for nullable-style usage patterns in typed function signatures.
  • Extension .so files do not cross PHP versions. If you compiled a PECL extension under PHP 7.4, it will not load under PHP 8. Recompile or reinstall via apt from the correct version namespace.
  • Composer’s platform-check will fail at boot, not install time. When platform-check.php runs at app bootstrap, it reads the actual PHP version. If you deploy a lock file generated against PHP 7 and boot under PHP 8 (or vice versa), the app will refuse to start. Regenerate composer.lock after the version switch.
  • OPcache cache files are not compatible across major versions. Clear the cache immediately after cutover: sudo systemctl reload php8.3-fpm flushes it. Do not rely on opcache_reset() from CLI — it targets a different SAPI process.

PHP 8.x migration is straightforward when you have full visibility into your runtime: which extensions load, what the static scanner finds, and where your integration tests run. Stack Harbor’s managed operations service includes PHP version lifecycle management, automated compatibility scanning in CI, and zero-downtime cutovers coordinated around your release schedule.