[英]Calling Composer With Specific PHP Version on Homestead
I'm using Homestead to develop a site that will be on a server with PHP 7.0. 我正在使用Homestead开发一个将在PHP 7.0服务器上的站点。 I want to use
.env
files, so I ran this Composer command: 我想使用
.env
文件,所以我运行了这个Composer命令:
composer require vlucas/phpdotenv
When I perused the file, composer.lock
, I noticed that a dependency, doctrine/annotations
, was requiring PHP 7.1. 当我仔细阅读文件
composer.lock
,我注意到依赖项, doctrine/annotations
需要PHP 7.1。
I tried adding this to my composer.json
file: 我尝试将其添加到我的
composer.json
文件中:
"config": {
"platform": {
"php": "~7.0"
}
},
When I run composer update
, I get this error: 当我运行
composer update
,我收到此错误:
[UnexpectedValueException]
Invalid version string "~7.0"
I realize that this is because PHP 7.2 is the default version on Homestead. 我意识到这是因为PHP 7.2是Homestead的默认版本。 How do I run Composer with PHP 7.0 instead of PHP 7.2?
如何使用PHP 7.0而不是PHP 7.2运行Composer?
Executing which composer
will give you this output: 执行
which composer
会给你这个输出:
/usr/local/bin/composer
The Homestead documentation discusses the multiple PHP versions supported and how to call them from the command line for Artisan. Homestead文档讨论了支持的多个PHP版本以及如何从Artisan的命令行调用它们。 Combining that with the composer path above allows you to do this:
将其与上面的作曲家路径相结合可以实现以下目的:
php7.0 /usr/local/bin/composer update
运行命令php70
,将PHP 7.0设置为PHP的默认系统版本,然后您可以正常运行composer
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.