PHP 7: Maintaining and Upgrading Legacy Apps · Upgrading from PHP 7 to PHP 8
Planning a PHP 8 Upgrade
Inventory, test coverage, dependency upgrades and target version choice.
Plan before changing code: pick a target version (the latest supported PHP 8.x your hosting and dependencies support), inventory extensions and Composer packages (composer why-not php 8.3), increase test coverage on critical paths, and upgrade frameworks/libraries to versions supporting both your current and target PHP where possible. Then run the code under PHP 8 in CI alongside PHP 7.4 until it's green.
composer why-not php 8.3 # which packages block PHP 8.3
composer require --dev phpcompatibility/php-compatibility squizlabs/php_codesniffer
vendor/bin/phpcs -p src --standard=PHPCompatibility --runtime-set testVersion 7.4-8.3
Common pitfalls
- Upgrading PHP and the framework major version in one giant step.
- Ignoring PHP extensions that aren't available for PHP 8 (e.g., old
mcrypt). - No CI job on the target version until the very end.
Key points
- Pick a supported target version
- Unblock dependencies first
- Run CI on both versions during the transition
Further reading: PHP manual: migrating from 7.4 to 8.0
Practice questions
What does composer why-not php 8.3 tell you?
Answer
Which installed packages declare constraints that prevent running on PHP 8.3, so you know which dependencies to upgrade or replace first.
Why run CI against both PHP 7.4 and PHP 8 during an upgrade?
Answer
So you can merge compatibility fixes continuously while production still runs 7.4, and know when the codebase is fully green on the target version.
Open in the app to mark lessons complete, take notes and track your progress.