Tell Composer to use a different php version

mvandemar

Well-Known Member
Jun 17, 2006
181
52
178
I am trying to get Composer to run on a client's machine using php 8.0. I installed Composer using the following commands:

Code:
curl -sS https://getcomposer.org/installer | /opt/cpanel/ea-php80/root/usr/bin/php
mv composer.phar /usr/local/bin/composer
chmod +x /usr/local/bin/composer
But when I check `composer diagnose` it keeps telling me that it's using php 7.2:

Code:
Checking composer version: OK
Composer version: 2.5.2
PHP version: 7.2.34
PHP binary path: /opt/cpanel/ea-php72/root/usr/bin/php
OpenSSL version: OpenSSL 1.1.1s  1 Nov 2022
cURL version: 7.87.0 libz 1.2.7 ssl OpenSSL/1.1.1s
zip: extension not loaded, unzip present, 7-Zip not available
Is there a way on a cpanel server to have the php cli default to a higher version, without changing the default for all of the users on that server? Note that in whm php is set to 8.0 for the user in question, but that doesn't seem to have any effect on php cli. I also tried aliasing php to php 8.0 in the ~/.bashrc file, so it does show 8.0 when I type in `php -v`, but that appears to have no effect at all on what Composer sees.

Thanks.

-Michael

PS Is the "code" button in the post editor broken for anyone else? Instead of bringing up the dialog window to insert code, it's bringing up a list of the forums on here.
 
Last edited by a moderator:

ServerHealers

Well-Known Member
Sep 21, 2015
100
58
78
India
cPanel Access Level
Root Administrator
Try running the composer the following way, and see if that helps:

/usr/local/bin/ea-php80 /usr/local/bin/composer install


Regarding the code button, this is a known issue and cPanel team is currently working on a new forum so that would be solved soon.
 
  • Like
Reactions: cPRex

mvandemar

Well-Known Member
Jun 17, 2006
181
52
178
Try running the composer the following way, and see if that helps:

/usr/local/bin/ea-php80 /usr/local/bin/composer install


Regarding the code button, this is a known issue and cPanel team is currently working on a new forum so that would be solved soon.
I know I can use the full path to the binary with php but I was still wondering if there is a way to change which php version is accessed by default when you use the cli version.

-Michael
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
17,460
2,840
363
cPanel Access Level
Root Administrator