When you execute Composer, it uses the default PHP version. Sometimes, you will have problems if you use Composer with a different version that the one that executes the project.
For example, in one server, the default version is PHP 8.0:
$ php -v PHP 8.0.7 (cli) (built: Jun 4 2021 23:14:20) ( NTS )
To execute Composer with other PHP version like PHP 7.4, first I get the PHP 7.4 and Composer full paths:
$ which php7.4 /usr/bin/php7.4 $ which composer /usr/local/bin/composer
To execute Composer with PHP7.4, I simply have to use the full paths. For example, to get the Composer version, I execute:
$ /usr/bin/php7.4 /usr/local/bin/composer -v Composer version 2.1.3 2021-06-09 16:31:20