Why Composer reports the wrong PHP version (and how to fix it)
Composer says "your php version (8.1.x) does not satisfy that requirement" when your server runs 8.3? The cause is usually the CLI binary, config.platform.php, or platform_check.php.
On this page
Composer does not ask your web server which PHP it runs. It uses either the PHP binary that is running Composer, or the version you told it to pretend in composer.json. When those disagree with production, you get confusing errors in both directions.
Check what Composer sees
which php && php -v
composer --version # prints the PHP version Composer is running on
composer config platform # shows any faked platform versions
composer check-platform-reqs
php -v on the command line can be a different version from PHP-FPM or Apache’s mod_php. On shared hosts and Plesk or cPanel servers, php on the PATH is often an old default while each site uses a newer one.
Fix 1: run Composer with the right binary
/usr/bin/php8.3 /usr/local/bin/composer install
# Debian/Ubuntu: switch the default CLI
sudo update-alternatives --set php /usr/bin/php8.3
On macOS with Homebrew, brew link --overwrite [email protected]. In Docker, run Composer inside the same image your app uses rather than on the host.
Fix 2: set config.platform.php deliberately
If you build on one machine and deploy to another, tell Composer the production version so it resolves packages that will run there:
{
"require": { "php": "^8.2" },
"config": {
"platform": { "php": "8.2.27" }
}
}
This is also the cause of the opposite problem. If someone set "platform": {"php": "8.1.0"} years ago, Composer keeps resolving for 8.1 even after you upgraded, and newer packages “require php >=8.2”. Raise or remove the setting, then run composer update on a branch.
Fix 3: the runtime platform check
Composer 2 writes vendor/composer/platform_check.php. If the site then runs on a lower PHP than the packages need, every request dies with:
Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.2.0". You are running 8.1.31.
The fix is to run the site on the PHP version you installed for, or to reinstall dependencies for the version you actually run. Turning the check off ("platform-check": false) only hides the error until code fails in a less obvious place.
Which one is it?
| Symptom | Likely cause |
|---|---|
Composer says your PHP is older than php -v in your site |
Composer runs a different CLI binary |
| Composer says your PHP is older than any binary you have | config.platform.php is set too low |
| Install works, the website shows “Composer detected issues” | Web server PHP is older than the CLI that installed |
| Works locally, fails in CI | CI image has a different PHP; pin it |
Upgrading PHP itself? Generate a step-by-step list with the PHP upgrade checklist.