Using Composer with ea-php-cli - Incorrect PHP version
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:
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:
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.
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 TechnologiesAll 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:
php -ea_php 71 /opt/cpanel/composer/bin/composer installBut 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.
-
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: You may also find the following thread helpful: Thank you. 0 -
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. composer/composer 0 -
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. 0
Please sign in to leave a comment.
Comments
3 comments