Composer uses wrong php version, but php -v shows the correct one (Ubuntu)

If you're using Debian based systems, you can ask it to globally use a specific version with the following command (depending on how and where your php versions are installed to):

sudo update-alternatives --set php /usr/bin/php7.2

update-alternatives creates, removes, maintains and displays informations about the symbolic links comprising the Debian alternatives system.


composerreferences the PHP executable here as follow:

#!/usr/bin/env php

When I do which php I get /c/Program Files/php-7.1/php under GIT-Bash (Windows 10).

Under Linux (at home I have Debian), php may be a symbolic link to an actual PHP binary.

So do the following:

  • Double-check the said php with ls -l `which php`
  • Make sure that you only have one PHP version installed, this may cause mixing incompatible versions which may be the root cause of your problem

That should help you, finding the root cause.


try this:

composer install --ignore-platform-reqs

or this in composer.json

"config": {
    "preferred-install": "dist",
    "platform": {
        "php": "7.0.0"
    }
}

in the second solution basically you're faking a platform, and run composer.phar update after this


Try this it worked for me :

  alias php='/usr/local/php7/bin/php'

php composer.phar install