作曲家使用较新版本的 php
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15673334/
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
composer to use newer version of php
提问by David
How do i get composer to use a newer version of php i have installed? I have downloaded and am using php 5.4 in all my local servers but when i download composer it points to my mac's default #!/usr/local/bin/env version, which is 5.3.15. I tried editing the composer executable and change the php used but it broke the executable.
我如何让作曲家使用我安装的较新版本的 php?我已经在所有本地服务器中下载并使用了 php 5.4,但是当我下载 composer 时,它指向我 mac 的默认 #!/usr/local/bin/env 版本,即 5.3.15。我尝试编辑 composer 可执行文件并更改使用的 php,但它破坏了可执行文件。
I'm trying to use composer to install Laravel and it is downloading the wrong version because of this.
我正在尝试使用 composer 安装 Laravel,因此它下载了错误的版本。
This is what the top of my composer executable looks like but then there's a bunch of weird characters below.
这是我的作曲家可执行文件顶部的样子,但下面有一堆奇怪的字符。
#!/usr/bin/env php
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <[email protected]>
* Jordi Boggiano <[email protected]>
*
* For the full copyright and license information, please view
* the license that is located at the bottom of this file.
*/
Phar::mapPhar('composer.phar');
define('COMPOSER_DEV_WARNING_TIME', 1366931166);
require 'phar://composer.phar/bin/composer';
composer.json for laravel project
Laravel 项目的 composer.json
{
"require": {
"laravel/framework": "4.0.*@dev"
},
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
]
},
"scripts": {
"post-update-cmd": "php artisan optimize"
},
"minimum-stability": "dev"
}
回答by Diwaker Tripathi
If you don't care for permanent settings, below command worked for me:
如果你不关心永久设置,下面的命令对我有用:
/Applications/MAMP/bin/php/php5.6.27/bin/php /usr/local/bin/composer install
Syntax is:
语法是:
{PATH TO YOUR PHP VERSION} {PATH TO COMPOSER EXECUTABLE} {COMPOSER COMMAND}
To know the executable path: which {EXECUTABLE}
can be very helpful.
Ex: which composer
gave below output which I used in command above:
了解可执行路径:which {EXECUTABLE}
非常有帮助。例如:which composer
给出了我在上面的命令中使用的以下输出:
/usr/local/bin/composer
回答by David
i found the problem. I moved the composer.phar file to my /usr/local/bin/ directory and no matter what i did, it was always using 5.3.15. I deleted the executable from my bin and redownloaded the .phar and moved that to my projects root and ran "php composer.phar install" and it looks like that worked.
我发现了问题。我将 composer.phar 文件移动到我的 /usr/local/bin/ 目录,无论我做什么,它总是使用 5.3.15。我从我的 bin 中删除了可执行文件并重新下载了 .phar 并将其移动到我的项目根目录并运行“php composer.phar install”,它看起来像这样工作。
To clean things up i did the following:
为了清理东西,我做了以下事情:
I left composer.phar at the root of my user profile
我将 composer.phar 留在了我的用户配置文件的根目录
/Users/davidadams/composer.phar
I then opened my .bash_profile and added the following alias
然后我打开了我的 .bash_profile 并添加了以下别名
alias composer='/usr/local/php5/bin/php /Users/davidadams/composer.phar'
That way it's available to me globally and i can define which php version i want to use. Hopefully others will find this useful.
这样我就可以在全球范围内使用它,我可以定义我想要使用的 php 版本。希望其他人会发现这很有用。
回答by hakre
By default composer on *nix systems uses the PHP binary/executeable specified by the environment. You can see that in the first line which is the shebang:
默认情况下,*nix 系统上的 composer 使用环境指定的 PHP 二进制文件/可执行文件。您可以在第一行中看到shebang:
#!/usr/bin/env php
You can tell the shell to bang against a more concrete PHP version instead, e.g.:
您可以告诉 shell 使用更具体的 PHP 版本,例如:
#!/usr/local/php5/bin/php
On Windows systems if you use the composer setup you can specify the PHP binary and the setup then will change the environment to match those needs. But you can as well easily rewrite the batchfile -or- configure the windows operating system to execute .phar files with the specific PHP binary.
在 Windows 系统上,如果您使用 Composer 设置,您可以指定 PHP 二进制文件,然后设置将更改环境以满足这些需求。但是您也可以轻松地重写批处理文件 - 或者 - 配置 Windows 操作系统以使用特定的 PHP 二进制文件执行 .phar 文件。
回答by Raul
sudo vim ~/.bash_profile
add
添加
export PATH="/Applications/MAMP/bin/php/php7.3.1/bin:$PATH"
in the above path I have php 7.3.1 so change that to whatever path you have
在上面的路径中我有 php 7.3.1 所以把它改成你有的任何路径
then hit Esc then :wq
然后按 Esc 然后 :wq