如何更改作曲家使用的 PHP 版本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46986139/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 03:16:44  来源:igfitidea点击:

How to change PHP version used by composer

phpcomposer-php

提问by Jonjie

I want to use another php version on my machine than the one already installed using WAMP (2 PHP version installed).

我想在我的机器上使用另一个 php 版本,而不是已经使用 WAMP 安装的那个版本(2 PHP version installed)

  • The composer installed uses PHP 5.6
  • A new project requires PHP7.0.
  • 安装的作曲家使用 PHP 5.6
  • 一个新项目需要PHP7.0.

Whenever I choose PHP 7 from the control panel of WAMP and then run php -vit still printing PHP5.6 (CLI)...instead of PHP7.

每当我从 WAMP 的控制面板中选择 PHP 7 然后运行php -v它时仍然打印PHP5.6 (CLI)...而不是PHP7.

How can I use PHP7 without reinstalling the composer again?

如何在不重新安装作曲家的情况下使用 PHP7?

回答by geeky

You can change php version of composer without uninstalling it, follow these steps :

您可以在不卸载的情况下更改 composer 的 php 版本,请按照下列步骤操作:

  1. Search for system environment variables in cortana.
  2. Click on the button "Environment variables".
  3. Under "System variables" select path and click on edit, you will see one entry like this "C:\wamp\bin\php\php5.6.13".
  4. Just change this to the folder name of the php located at your wamp/bin/php7.1.9, here php7.1.9 is folder name.
  5. Replace php5.6.13 with bin7.1.9, it will look like these "C:\wamp\bin\php\php7.1.9", just click ok on all the boxes.
  6. You are done.
  7. To verify, first close all the cmd windows, than open cmd and type php -v, press enter and you should see php7.1.9.
  8. If you don't see change in php version than just restart your pc and run php -vagain in cmd , it will work.
  1. 在 cortana 中搜索系统环境变量。
  2. 单击“环境变量”按钮。
  3. 在“系统变量”下选择路径并点击编辑,你会看到这样一个条目“C:\wamp\bin\php\php5.6.13”。
  4. 只需将其更改为位于 wamp/bin/php7.1.9 的 php 文件夹名称,此处 php7.1.9 是文件夹名称。
  5. 将 php5.6.13 替换为 bin7.1.9,它看起来像这样“C:\wamp\bin\php\php7.1.9”,只需在所有框上单击“确定”即可。
  6. 你完成了。
  7. 要验证,首先关闭所有 cmd 窗口,然后打开 cmd 并键入php -v,按回车键,您应该看到 php7.1.9。
  8. 如果您没有看到 php 版本的变化,而只是重新启动您的电脑并php -v在 cmd 中再次运行,它将起作用。

回答by Devon

I'm assuming Windows if you're using WAMP. Composer likely is just using the PHP set in your path: How to access PHP with the Command Line on Windows?

如果您使用 WAMP,我假设您使用的是 Windows。Composer 可能只是在您的路径中使用 PHP 集:How to access PHP with the Command Line on Windows?

You should be able to change the path to PHP using the same instructions.

您应该能够使用相同的说明更改 PHP 的路径。

Otherwise, composer is just a PHAR file, you can download the PHAR and execute it using any PHP:

否则,composer 只是一个 PHAR 文件,您可以下载 PHAR 并使用任何 PHP 执行它:

C:\full\path\to\php.exe C:\full\path\to\composer.phar install

回答by 0CDc0d3r

If anyone is still having trouble, remember you can run composer with any php version that you have installed e.g. $ php7.3 -f /usr/local/bin/composer update

如果有人仍然遇到问题,请记住您可以使用已安装的任何 php 版本运行 Composer,例如 $ php7.3 -f /usr/local/bin/composer update

Use which composercommand to help locate the composer executable.

使用which composer命令来帮助定位 composer 可执行文件。

回答by themroc

I found out that composer runs with the php-version /usr/bin/env finds first in $PATH, which is 7.1.33 in my case on MacOs. So shifting mamp's php to the beginning helped me here.

我发现 Composer 使用 php-version 运行 /usr/bin/env 在 $PATH 中首先找到,在我的情况下,MacOs 是 7.1.33。因此,将 mamp 的 php 移到开头对我有所帮助。

PHPVER=$(/usr/libexec/PlistBuddy -c "print phpVersion" ~/Library/Preferences/de.appsolute.mamppro.plist)

export PATH=/Applications/MAMP/bin/php/php${PHPVER}/bin:$PATH