简体   繁体   English

作曲家使用较新版本的 php

[英]composer to use newer version of php

How do i get composer to use a newer version of php i have installed?我如何让作曲家使用我安装的较新版本的 php? 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.我已经在所有本地服务器中下载并使用了 php 5.4,但是当我下载 composer 时,它指向我 mac 的默认 #!/usr/local/bin/env 版本,即 5.3.15。 I tried editing the composer executable and change the php used but it broke the executable.我尝试编辑 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 <naderman@naderman.de>
 *     Jordi Boggiano <j.boggiano@seld.be>
 *
 * 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"
}

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.了解可执行路径: which {EXECUTABLE}可能非常有帮助。 Ex: which composer gave below output which I used in command above:例如: which composer给出了我在上面的命令中使用的以下输出:

/usr/local/bin/composer

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.我将 composer.phar 文件移动到我的 /usr/local/bin/ 目录,无论我做什么,它总是使用 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.我从我的 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.这样我就可以在全球范围内使用它,我可以定义我想要使用的 php 版本。 Hopefully others will find this useful.希望其他人会发现这很有用。

By default composer on *nix systems uses the PHP binary/executeable specified by the environment.默认情况下,*nix 系统上的 composer 使用环境指定的 PHP 二进制文件/可执行文件。 You can see that in the first line which is the shebang :您可以在第一行中看到shebang

#!/usr/bin/env php

You can tell the shell to bang against a more concrete PHP version instead, eg:您可以告诉 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.在 Windows 系统上,如果您使用 Composer 设置,您可以指定 PHP 二进制文件,然后设置将更改环境以满足这些需求。 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 操作系统以使用特定的 PHP 二进制文件执行 .phar 文件。

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

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

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