Using Composer with ea-php-cli - Incorrect PHP version

jcwacky

Active Member
Sep 4, 2002
30
2
158
Using MultiPHP, I'm setting some accounts to use PHP 7.1. This is working fine, and also works on the command line for these accounts, if I type php -v I get:
Code:
ea-php-cli Copyright 2017 cPanel, Inc.
PHP 7.1.20 (cli) (built: Jul 30 2018 09:39:58) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
All good.

But if I run composer install it doesn't seem to pick up the specified version of PHP and defaults to 5.6, which in turn causes it to fail, complaining that my project requires PHP 7.1.

How can I get composer to pick up the correct PHP version?

---

One workaround I have found is to use:
Code:
php -ea_php 71 /opt/cpanel/composer/bin/composer install
But including the PHP version in the command isn't ideal for various reasons, I'd prefer if could detect it automatically like it does when running php.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,884
2,250
463
Hello @jcwacky,

Can you verify which directory you are running the command from? You should be able to use the "/usr/bin/php" path for the EA4 php-cli package and it should find the version specified for the directory you are currently in (not the directory the file exists in). If you do not run the command from the document root for the domain (e.g. /home/username/public_html/), it will use the system default version. We document how this works at:

EasyApache 4 and the ea-php-cli Package - EasyApache 4 - cPanel Documentation

You may also find the following thread helpful:

composer using wrong php package

Thank you.
 

jcwacky

Active Member
Sep 4, 2002
30
2
158
I'm running the command from the document root. (/home/username/public_html/)

As mentioned, php -v shows the correct version (as set in MultiPHP), the correct version is also used when running php ./myscript.php but not when running composer install from the same directory.

Composer claim they are not able to fix this, and that it's up to cPanel. They say they are detecting the PHP version correctly, as seen here: composer/composer
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,884
2,250
463
Hello @jcwacky,

The behavior you notice is because composer is installed on the system and not in individual accounts:

/opt/cpanel/composer/bin/composer

The easiest way to address this issue is to make sure any account using Composer is assigned the PHP version configured as the "System PHP Version" in WHM >> MultiPHP Manager. The other option is to define the SCL for composer per the instructions in this post:

Updating to php-cgi instead of using cli causing whole lot of issues · Issue #1 · CpanelInc/php-cli

Let me know if this helps.

Thank you.
 
  • Like
Reactions: Optimizr