If you’re reading this, you are probably having an issue because your composer is returning wrong (system default – native) PHP version. In this case, I tried to change to set PHP CLI version for composer from 7.2 to 8.2. In my case, this was done on CloudLinux environment where alt-php versions are in /opt/alt/. If you are using different PHP manager, find where your PHP binaries are.
I was getting this error:
[thisisme@cp ~]$ composer install
...
Problem 1
- Root composer.json requires php >=8.1 but your php version (7.2.34) does not satisfy that requirement.
...
You have to call composer with correct PHP binary. In my case, binary for version 8.2:
[thisisme@cp ~]$ /opt/alt/php82/usr/bin/php /opt/cpanel/composer/bin/composer diagnose
Checking platform settings: OK
Checking git settings: OK git version 2.43.2
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com rate limit: OK
Checking disk free space: OK
...
Checking composer version: You are not running the latest stable version, run `composer self-update` to update (2.6.5 => 2.8.5)
Composer version: 2.6.5
PHP version: 8.2.27
...
If you don’t want to execute this huge line every time you want to run composer command, create a simple alias, and you should be set:
[thisisme@cp ~]$ vi .bashrc
# add this to the end of the file
alias composer=”/opt/alt/php82/usr/bin/php /opt/cpanel/composer/bin/composer”
[thisisme@cp ~]# source .bashrc
And now you can run simpler version:
[thisisme@cp ~]$ composer diagnose
Checking platform settings: OK
Checking git settings: OK git version 2.43.2
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com rate limit: OK
Checking disk free space: OK
Checking composer version: You are not running the latest stable version, run `composer self-update` to update (2.6.5 => 2.8.5)
Composer version: 2.6.5
PHP version: 8.2.27
...
Recent Comments