简体   繁体   中英

How to Actually change PHP Version that used by composer?

I'm quite new to this composer and laravel stuff, and I'm using XAMPP in Windows 10 .. so, sorry if I missed something.

At first I Install my composer on my windows, and I'm using PHP V.5.6 as default php engine on my composer, for starter i could develop my laravel project normally, atleast until Laravel V.5.4 ..

but now i have install other XAMPP with PHP V.7.1 ("in Partition") and when I try to developing Laravel V.5.5 app, I couldn't develop my new Laravel App freely, because my composer still running on PHP V.5.6 . For some reason I need both of my PHP version , and I still couldn't figure out a way to switch between PHP Engine that used by the Composer ..

So, My Question is . Is there any simple way to change PHP Version used by composer without install/uninstalling it?

I don't really know how do you run the composer script so my answer can be useless for you.

You have two different versions of php, so you have two binary files for each version, so you can use needed binary file to run the composer from your command line:

$ /path/to/needed/binary/php composer.phar install

But it can be a really bad idea. Libraries in the composer can depend of others and those can depend from php version. Your composer loads libraries which are relying on php version wich is currently running. So it can load libraries which will not work in other php version.

IFAIK, you cannot do that with built-in composer functionality.

But if you really want to manage PHP version with with composer you can use pre-install-cmd hook in order to switch the default PHP version using, for example PHPenv.

And yes, IMHO, XAMPP is not the best development env. I see that you use Laravel, have you tried Homestead?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM