Tell Composer to use Different PHP Version
Solution 1
Ubuntu 18.04 case ... this run for me.
/usr/bin/php7.1 /usr/local/bin/composer update
Solution 2
Maybe this can't solve exactly your issue but probably it will help others who comes here from web search.
Just run the command to add below code to your composer.json
file to set different PHP version:
$ composer config platform.php 8.0.7
"config": {
"platform": {
"php": "8.0.7"
}
}
Solution 3
On xubuntu I had php 7.2 as default. But needed to run composer with php 5.6.
So this worked for me:
php5.6 /usr/bin/composer
Solution 4
If you just need to get composer to ignore the version requirements, you can bypass using:
composer install --ignore-platform-reqs
Solution 5
You always can use that way.
In project folder where you has composer.json file. Run the command
php7.4 /usr/local/bin/composer install
or
php7.4 /usr/local/bin/composer update
where php7.4 your specific version can be(php7.0, php5.5, php7.3 etc...) where /usr/local/bin/composer path for system folder with composer
!!! you should have php7.4-cli
sudo apt-get install -y php7.4-cli
That way for linux/ubuntu user
Cheers ;-)
Boom
Knowledgeable in Java, JavaScript, C/C++, C#, GML, and TorqueScript.
Updated on February 03, 2022Comments
-
Boom about 2 years
I've been stuck at this for a few days. I'm using 1and1 hosting, and they have their PHP set up a bit weird.
If I use just
php composer.phar install
, then I'm using PHP 4.4.6, which is horribly insufficient. However, I can runphp5.5 composer.phar install
, get a little bit further, but it still fails because somewhere along the line, PHP is called again, but it fails, as it's using 4.4.6.Is there any way to tell Composer to use the
php5.5
command? Has anyone successfully gotten Composer configured on 1and1 hosting?I'm trying to get Laravel up and running (which uses Composer). I've been able to do it on my GoDaddy domain, but not 1and1.
-
Boom over 8 yearsI don't have write access to the home directory. 1and1 has littered this domain with red tape.
-
Boom about 8 yearsI don't have a
post-root
package-install` field. Should I add one? -
Carlo Espino about 8 yearsIs not needed, you can achieve same effect running
cp .env.example .env
, it just copies contents of.env.example
to a new file called.env
-
Gregory Cosmo Haun over 4 yearsI guess this isn't really the answer the OP was looking for, but it matches the title of the question very well and might be of great help to people arriving here from web search as it was to me.
-
Pedro Lobito almost 4 yearsbeware, this answer may break your system.
-
Bhavesh Prajapati almost 4 yearsI have use sudo /opt/lampp/bin/php /usr/bin/composer install and it works for me Thank you +1
-
samerivertwice over 3 yearsWill this override the shebang at the start of the file?
-
Ibrahim.H over 3 yearsThat's right, although it's not recommended to change the Shebang in the head of
composer
, you could break the originalcomposer.phar
file. -
Sybille Peters almost 3 yearsIsn't this the same thing the OP was doing which failed for him because "but it still fails because somewhere along the line, PHP is called again, but it fails, as it's using 4.4.6."?
-
Sybille Peters almost 3 yearsHow is this fundamentally different from what the OP did and which did not work for him (php5.5 composer.phar install) because the commands invoked by Composer will still use the default PHP version? Test this yourself, add a "scripts" : "php-version": "php --version" and call e.g. /user/bin/php7.4 /usr/bin/composer php-version.
-
Darius.V almost 3 yearsmaybe no, because he done in not exactly same way
-
pixelbrackets over 2 yearsThis is the correct answer. As Sybille outlined with the example the
platform
setting does not change any local PHP paths. Instead Composer will use this value to fetch dependencies matching this version only. No more, they still run with the current PHP version. Only a change of the$PATH
variable will change the PHP version used to run subscripts. -
heady12 over 2 yearsLegend, just what I needed :)
-
Boyan Georgiev over 2 yearsAdded "$@" at the end, like so: /opt/plesk/php/7.4/bin/php /usr/local/psa/var/modules/composer/composer.phar "$@"
-
Nico Haase about 2 yearsThis won't run Composer with a different PHP version, but configure Composer to run the dependency resolver for another PHP version. IMHO, this does not answer the given question properly
-
Nico Haase about 2 yearsThis won't run Composer with a different PHP version, but configure Composer to run the dependency resolver for another PHP version. IMHO, this does not answer the given question properly
-
Nico Haase about 2 yearsThis won't run Composer with a different PHP version, but configure Composer to run the dependency resolver for another PHP version. IMHO, this does not answer the given question properly
-
Nico Haase about 2 yearsThis won't run Composer with a different PHP version, but configure Composer to run the dependency resolver for another PHP version. IMHO, this does not answer the given question properly
-
Nico Haase about 2 yearsThis won't run Composer with a different PHP version, but configure Composer to run the dependency resolver for another PHP version. IMHO, this does not answer the given question properly
-
Nico Haase about 2 yearsThis won't run Composer with a different PHP version, but configure Composer to run the dependency resolver for another PHP version. IMHO, this does not answer the given question properly
-
Nico Haase about 2 yearsPlease share more details. What do you mean by "SIP"? Also, on shared hosting (as given in the question), you cannot edit anything in
/usr/local/bin
-
Anony Mous about 2 years@SybillePeters, change your script to be e.g. "php-version": "/user/bin/php7.4 --version" I suppose you could configure your entire machine to use a specific version for
php
usingsudo update-alternatives --set php /usr/bin/php7.4
-
wapmorgan about 2 yearsBut this sometimes can help. For example, when you build your app in docker, and have another php version on local machine where develops
-
ssi-anik about 2 yearsjust in case someone wants to verify if it works or not, try this. stackoverflow.com/a/56379908/2190689
-
pixelbrackets about 2 yearsOne more comment - there are several tools available to change the PHP version via the
$PATH
env variable. One example is github.com/webit-de/php-version-pickup. It picks up the version from a.php-version
file and continues to use it in the current shell session, also for all subprocesses like the ones initiated by Composer. -
Neek almost 2 yearsDespite being down voted, this did work for me :) Fresh Rocky linux install with composer from remi repo, composer kept trying to use the core system PHP 7.2 and not my PHP 7.4 from remi required by composer.json packages.