Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

Composer reports a different PHP version than php -v on Ubuntu

ErrorComposer detected issues in your platform: Your Composer dependencies require a PHP version

Short 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.

  • Applies to Composer 2.8, PHP 8.3, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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 platform
  2. 2Match what you see, then jump to its fix

    1. 1check-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. 2check-platform-reqs lists an older PHP than php -v printsThe composer command starts a different php than your shell's phpFix
    3. 3composer 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

What does the error look like?

  • Composer detected issues in your platform: Your Composer dependencies require a PHP version
  • You 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 platform

2Fix

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 --lock

3Verify

Resolution now uses the real interpreter's version.

composer config --list | grep -i platform
composer install

Confirmed by getcomposer.org

Did this fix it?

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 php

2Fix

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.3

3Verify

check-platform-reqs now lists the PHP version you expect.

composer check-platform-reqs | head -n 3

Confirmed by getcomposer.org

Did this fix it?

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 nginx

Confirmed by raw.githubusercontent.com

Did this fix it?

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

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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.