Composer reports a different PHP version than php -v on Ubuntu
Composer detected issues in your platform: Your Composer dependencies require a PHP versionShort answer
Composer takes its PHP version from the interpreter that runs it, unless config.platform fakes one. First run composer check-platform-reqs: it ignores the override and shows the real version. If it differs from php -v, Composer starts another php binary. If it matches, a platform entry in composer.json is the cause.
Fix it fast
1Find out which cause you have
Compare three things: the version of php your shell uses, the real platform Composer sees, and any faked platform in your configuration.
php -v composer check-platform-reqs composer config --list | grep -i platform2Match what you see, then jump to its fix
- 1
check-platform-reqs shows the right PHP, yet install or update still says your php version does not satisfy the requirementconfig.platform in composer.json fakes an older PHPFix - 2
check-platform-reqs lists an older PHP than php -v printsThe composer command starts a different php than your shell's phpFix - 3
composer works in the terminal, but the site fails at runtime with 'Composer detected issues in your platform'The web server or php-fpm runs another PHP than the command lineFix
- 1
What does the error look like?
Composer detected issues in your platform: Your Composer dependencies require a PHP versionYou are running 8.1.2.
Cause 1 of 3
config.platform in composer.json fakes an older PHP
1Check
The config docs say the platform option lets you fake PHP and extension versions, to emulate a production machine. check-platform-reqs ignores it and checks the real platform. Look for it in the project and in the global config.
grep -n -A4 '"platform"' composer.json
composer global config --list | grep -i platform2Fix
Change the php value to the version you really target, or remove the platform block when you do not need it.
composer config --unset platform.php
composer update --lock3Verify
Resolution now uses the real interpreter's version.
composer config --list | grep -i platform
composer installConfirmed by getcomposer.org
Cause 2 of 3
The composer command starts a different php than your shell's php
1Check
The platform docs say versions come from the environment Composer is executed in: the php package gets the version of the interpreter that runs Composer. Find which php binary the composer file asks for and which alternatives exist.
head -n 1 "$(command -v composer)"
command -v php
update-alternatives --display php2Fix
Run Composer with the PHP you want, or switch the system default with update-alternatives.
# one-off: choose the interpreter explicitly
php8.3 "$(command -v composer)" install
# or change the default for the whole system
sudo update-alternatives --set php /usr/bin/php8.33Verify
check-platform-reqs now lists the PHP version you expect.
composer check-platform-reqs | head -n 3Confirmed by getcomposer.org
Cause 3 of 3
The web server or php-fpm runs another PHP than the command line
1Check
Since Composer 2 the autoloader checks the PHP version when the app starts. The php-only default checks only the version, so the CLI and the web PHP can disagree. Print the version from the web side with a test script.
php -r 'echo PHP_VERSION, PHP_EOL;'
# in a temporary file served by the web server:
# <?php echo PHP_VERSION;2Fix
Point the web server to the PHP you install with: change the php-fpm socket in the virtual host, or the Apache PHP module. Do not turn off platform-check to hide the mismatch.
# nginx: use the socket of the right version
fastcgi_pass unix:/run/php/php8.3-fpm.sock;3Verify
Reload the web server and request the test script again.
sudo nginx -t && sudo systemctl reload nginxConfirmed by raw.githubusercontent.com
How do I stop it coming back?
- Keep the platform block out of composer.json unless a deploy target really needs it, and write the real production PHP version when it does.
- Run composer check-platform-reqs in CI and on every deploy.
- Use one PHP version on the CLI and in php-fpm; install both from the same package source.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Servers
Apache and the command line run different PHP versions
a2enmod php8.3 succeeds but php -v still shows the old version
Apache and the php command are two separate things.
2 causes, each with a fixServers
Apache returns 504 Gateway Timeout when PHP takes too long
Quick requests work, slow ones end in a 504 after a fixed wait
A 504 from Apache means the backend did not answer within the proxy timeout.
2 causes, each with a fixServers
docker-php-ext-install mbstring fails: oniguruma not found
The docker-php-ext-install step exits with a non-zero code
mbstring needs the Oniguruma library to build its regex functions, and the PHP build finds it through pkg-config.
3 causes, each with a fixServers
Laravel returns 500 Internal Server Error on Apache
/var/www/html/.htaccess: RewriteCond: bad flag delimiters
Apache and Laravel report different 500s.
5 causes, each with a fixServers
nginx gives up waiting for the app and returns 504
upstream timed out (110: Connection timed out) while reading response header from upstream
nginx returns 504 when the app behind it takes the request but sends nothing back within proxy_read_timeout (60 seconds by default), or when the connection cannot be opened in time.
5 causes, each with a fixServers
nginx and PHP-FPM show File not found or Primary script unknown
File not found.
PHP-FPM received a script path it could not turn into a file.
4 causes, each with a fix