简体   繁体   English

使用 Composer 定位不同的 php 版本

[英]Targeting a different php version with Composer

Is there a way to do a Composer build with a php version different from what is installed locally?有没有办法使用不同于本地安装的 php 版本进行 Composer 构建?

My use case is that I have a development container using php56 which lives on a host that has php54.我的用例是我有一个使用 php56 的开发容器,它位于具有 php54 的主机上。 The two environments have a shared folder where the project files live, and I do my builds from an IDE living on the host machine (which uses 5.4).这两个环境有一个共享文件夹,项目文件所在的文件夹,我从位于主机(使用 5.4)上的 IDE 进行构建。

In a perfect world, I would just upgrade my host to 5.6, but I work on some projects with the lower version.在一个完美的世界中,我只会将我的主机升级到 5.6,但我在一些较低版本的项目上工作。

I don't think you can change that because composer uses the php version that composer is run with, so there are only a few options我认为你不能改变它,因为 composer 使用运行 composer 的 php 版本,所以只有几个选项

  • Install the required php version as extra installation (as you already did)安装所需的 php 版本作为额外安装(就像你已经做的那样)
  • Change the source of composer where the version is taken from the php environment (not really a good idea)更改从 php 环境中获取版本的 composer 的来源(不是一个好主意)
  • Maybe installing the dependencies from your development box, because you said that you had a shared folder between the systems也许从你的开发箱安装依赖项,因为你说你在系统之间有一个共享文件夹

The last option is the most promising in my opinion because linux has very nice support for hosting multiple versions of php with phpenv在我看来,最后一个选项是最有前途的,因为 linux 对使用 phpenv 托管多个版本的 php 有很好的支持

Sorry I couldn't give you a real solution抱歉我不能给你一个真正的解决方案

我一直在使用Docker完成此操作:

docker run -v $(pwd):/app composer/composer update

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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