laravel 更改 Composer 在 Windows 上使用的 PHP 版本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39881924/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change PHP version used by Composer on Windows
提问by JMS786
I have already use WAMP 2.5 with PHP 5.5.12, and with Composer. The php is on:
我已经在 PHP 5.5.12 和 Composer 中使用了 WAMP 2.5。php 开启:
C:\wamp\bin\php\php5.5.12
For new project, I need to use nginx and installed PHP 7. The php is on:
对于新项目,我需要使用 nginx 并安装 PHP 7。 php 开启:
C:\nginx\php
Now, using GitBash MINGW32, I tried to install laravel 5.3 using Composer create-project
but it said
现在,使用 GitBash MINGW32,我尝试使用 Composer 安装 laravel 5.3,create-project
但它说
[InvalidArgumentException]
Could not find package laravel/laravel with version 5.3 in a version
installable using your PHP version 5.5.12.
I already put both C:\wamp\bin\php\php5.5.12
and C:\nginx\php
on Windows System PATH variable.
我已经把C:\wamp\bin\php\php5.5.12
和 都C:\nginx\php
放在了 Windows 系统 PATH 变量上。
How do I change the PHP version used by Composer?
如何更改 Composer 使用的 PHP 版本?
采纳答案by BVengerov
Three ways to do this, really.
三种方法可以做到这一点,真的。
Create an alias in .bashrc
to always run composer with the corresponding version
创建别名.bashrc
以始终使用相应版本运行 composer
Something like alias ncomposer=`/path/to/php /path/to/composer.phar `
就像是 alias ncomposer=`/path/to/php /path/to/composer.phar `
Specify the path to PHP version inside composer.phar
itself
在composer.phar
自身内部指定 PHP 版本的路径
This is specified at the start of the file: #!/path/to/php php
. Then composer should run with composer.phar
这是在文件开头指定的:#!/path/to/php php
. 然后作曲家应该运行composer.phar
NB!The line will disappear upon self-update, so it's not a reliable solution.
注意!这条线会在自我更新时消失,所以这不是一个可靠的解决方案。
Move up the path with the newest PHP version
使用最新的 PHP 版本向上移动路径
If you place C:\nginx\php
first, it should be used by default when using composer.
如果C:\nginx\php
先放置,则在使用 composer 时应默认使用它。
Hope this helps!
希望这可以帮助!
回答by w3spi
Although this question was solved, the answer didn't help me. I will explain how I managed to make composerto work in a version of PHP different from the one which is installed by default on my OS (PHP 7.1.1) as well as in my environment variables (these will not be changed !). Note that I'm using Xampp, but the principle remains the same for Wamp.
虽然这个问题已经解决了,但答案对我没有帮助。我将解释我如何设法让Composer在不同于默认安装在我的操作系统 (PHP 7.1.1) 以及我的环境变量中的 PHP 版本中工作(这些不会改变!)。请注意,我使用的是 Xampp,但 Wamp 的原理保持不变。
Starting from this answer:
- Start up Git Bash
- Type
cd ~/
to go to your home folder - Type
touch .bash_profile
to create your new file. - Edit
.bash_profile
with your favorite editor
从这个答案开始:
- 启动 Git Bash
- 键入
cd ~/
以转到您的主文件夹 - 键入
touch .bash_profile
以创建新文件。 - 编辑
.bash_profile
带你喜欢的编辑器
In my case I have a folder named
php733
inside xampp folder which corresponds to PHP 7.3.3. This is this other answerthat helped me in creating the alias :alias composer733='/c/[xampp folder]/php733/php.exe /c/ProgramData/ComposerSetup/bin/composer.phar '
Then, type
. .bash_profile
to reload.bash_profile
and update any functions you add. Notice the space between the two dots!
就我而言,我有一个名为
php733
xampp 文件夹内的文件夹,它对应于 PHP 7.3.3。这是另一个帮助我创建别名的答案:alias composer733='/c/[xampp folder]/php733/php.exe /c/ProgramData/ComposerSetup/bin/composer.phar '
然后,键入
. .bash_profile
以重新加载.bash_profile
和更新您添加的任何功能。注意两个点之间的空间!
Finally, type this command in Git Bash :
最后,在 Git Bash 中输入以下命令:
composer733 [whatever you wan]
Example: in the project that requires at least PHP 7.1.3
示例:在至少需要 PHP 7.1.3 的项目中
Using composer:
$ composer update This package requires php ^7.1.3 but your HHVM version does not satisfy that requirement.
Using composer733(the alias I created) :
$ composer733 update Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 98 installs, 0 updates, 0 removals - Installing [...] (v1.11.0): Loading from cache
使用作曲家:
$ composer update This package requires php ^7.1.3 but your HHVM version does not satisfy that requirement.
使用composer733(我创建的别名):
$ composer733 update Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 98 installs, 0 updates, 0 removals - Installing [...] (v1.11.0): Loading from cache
It works, without having to change the environment variables
它可以工作,而无需更改环境变量