How to Actually change PHP Version that used by composer?

心不动则不痛 提交于 2021-02-10 15:29:09

问题


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?


回答1:


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.




回答2:


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?



来源:https://stackoverflow.com/questions/46817384/how-to-actually-change-php-version-that-used-by-composer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!