How to switch php version when running composer? [duplicate]
Asked Answered
S

3

6

I have composer installed on windows 8.1. I use it to download drupal distributions and modules. I have also installed acquia dev desktop. As you know that dev desktop comes with different versions of php and it has separate folders for it. I have setup composer to use php 5.6. How can I make it use php 7?

Should I uninstall composer and install again or what?

Santa answered 8/3, 2018 at 17:4 Comment(1)
#45790660 may be useful.Albeit
U
11

IF you have multiple php version installed in your system

you can run composer with different versions like

In linux

PHP

    usr/local/php usr/bin/composer install

for PHP 7.1

usr/local/php7.1 /usr/local/composer install

actually the idea is which version you wants to run get its bin path and then run the composer.

In Windows.

path/to/php.exe composer install

Hope this helps

Upbraid answered 8/3, 2018 at 17:10 Comment(8)
@laravel.levaral Can you please tell me how to use the path? I am using "C:\Program Files\DevDesktop\php7_0\php.exe" composer create-project markaspot/mark-a-spot project-dir --stability dev It says Could not open input file: composerSanta
@Santa give it a composer.exe pathUpbraid
@laravel.levaral How?Santa
reinstall composer and give it php7 path while installingUpbraid
@laravel.levaral Should I uninstall composer installed previously in php 5.6 folder? Or is it ok to have composer installed twice?Santa
accepted your answer, but I would request/suggest you to make your answer easy to understandSanta
This guide is enlightening but I have provided quite a detailed answer here (https://mcmap.net/q/127212/-tell-composer-to-use-different-php-version) on SO! Give it a tryAlert
Excellent. Solved for me. I now have an alias for composer8Grider
P
7

If you just want to ignore the php version dependency then you can use this -

--ignore-platform-reqs

Example:

composer require symfony/css-selector --ignore-platform-reqs

This way you don't have to edit Environment variables(windows os) or using any full path of php etc. This very useful when I use different php lib from github which requires different php version set in my windows Environment variables though I have all PHP versions in my WAMP server so it will not be any problem running those lib after installing.

Priorate answered 8/2, 2019 at 17:32 Comment(0)
P
6

In my case worked with this:

ea-php72 /opt/cpanel/composer/bin/composer update
Propaganda answered 8/2, 2019 at 6:34 Comment(1)
Perfect! This is it for cPanel/WHM Setups. +1Prescription

© 2022 - 2024 — McMap. All rights reserved.