在 WAMP PHP Google+ 项目中安装 Composer,PHP 无法识别

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

Installing Composer in WAMP PHP Google+ Project, PHP is not recognised

phpwampservercomposer-php

提问by Anthony

I am following this PHP Google+ tutorialand I am trying to install composer in my WAMP directory

我正在关注这个 PHP Google+ 教程,我正在尝试在我的 WAMP 目录中安装作曲家

C:\wamp\www\gplus-quickstart-php>curl -s https://getcomposer.org/installer | php

but I'm getting this error

但我收到了这个错误

'php' is not recognized as an internal or external command operable program or batch file.

'php' 不是内部或外部命令可操作的程序或批处理文件。

How do I resolve this problem? I already have PHP installed (via WAMP Server). Do I have to install PHP in my computer as well?

我该如何解决这个问题?我已经安装了 PHP(通过 WAMP 服务器)。我是否也必须在我的计算机中安装 PHP?

回答by RiggsFolly

Ok a couple of things you need to do here.

好的,您需要在这里做一些事情。

First windows does not have a curl processor like unix so you need to use the other option for installing Composer

第一个 Windows 没有像 unix 这样的 curl 处理器,所以你需要使用另一个选项来安装 Composer

php -r "eval('?>'.file_get_contents('https://getcomposer.org/installer'));"

For this to work you need the php.exe processor to be on your path, so you have 2 options here. Either add the c:\wamp\bin\php\phpx.y.zfolder to your PATH thats the bad option for WAMPServeras you can have more than one version of PHP installed and when you activate another version your PATH will still be pointing at the Old version. Or my prefered option write yourself a little .cmd file which will do it for you like this

为此,您需要 php.exe 处理器在您的路径上,因此您在这里有 2 个选项。要么将该c:\wamp\bin\php\phpx.y.z文件夹添加到您的 PATH 中,这对 WAMPServer 来说一个错误的选择,因为您可以安装多个版本的 PHP,并且当您激活另一个版本时,您的 PATH 仍将指向旧版本。或者我更喜欢的选项是自己写一个小 .cmd 文件,它会像这样为你做

filename = addphp.cmd

文件名 = addphp.cmd

PATH=%PATH%;c:\wamp\bin\php\phpx.y.z

Put this file in a folder already registered on your path so you can run it from anywhere in a command window.

将此文件放在已在您的路径上注册的文件夹中,以便您可以从命令窗口中的任何位置运行它。

Now you will have to edit the \wamp\bin\php\phpx.y.z\php.ini file. This is similiar to the one used by php code run through the Apache web server but is only used by the PHP CLI (Command Line Interpreter)

现在您必须编辑 \wamp\bin\php\phpx.yz\php.ini 文件。这与通过 Apache Web 服务器运行的 php 代码使用的类似,但仅由 PHP CLI(命令行解释器)使用

Make sure the extension php_curl is uncommented or the above line wont work i.e. remove the ;comment symbol

确保扩展名 php_curl 未注释,否则上面的行将不起作用,即删除;注释符号

extension=php_curl.dll

So now run a command window, cd into the folder that you want composer installed into and run the command above, then follow the rest of the install instructions on Install instructions

所以现在运行一个命令窗口,cd 进入你想要 Composer 安装到的文件夹并运行上面的命令,然后按照安装说明中的其余安装说明进行操作

回答by gagath

On windows, just installed composer with windows installer -> easy and with wizard - like it.

在 Windows 上,只需使用 Windows 安装程序安装 Composer -> 简单且带有向导 - 喜欢它。

https://getcomposer.org/Composer-Setup.exe

https://getcomposer.org/Composer-Setup.exe

回答by programmingnewb

No idea if anyone will answer this late but I'm having issues with this. I created the .cmd file and put in the path as suggested. I put this file in my wamp\www\sitename folder. Is that not what you mean when you say putting it in a "registered path folder"? After creating the file, and running the code it still says php not recognized.

不知道是否有人会这么晚回答,但我对此有疑问。我创建了 .cmd 文件并按照建议放入路径。我将此文件放在 wamp\www\sitename 文件夹中。当您说将其放入“注册路径文件夹”时,这不是您的意思吗?创建文件并运行代码后,它仍然说 php 无法识别。

回答by Farid Ait Benali

first you have to add your php path to system after go to php.ini and rmove ;for extension=php_openssl.dllit will be active 3 run this command in cmd :

首先,您必须在转到 php.ini 和 rmove 之后将您的 php 路径添加到系统中;extension=php_openssl.dll因为它将处于活动状态 3 在 cmd 中运行此命令:

php -r "eval('?>'.file_get_contents('https://getcomposer.org/installer'));"

回答by jim smith

If using phpstorm you can download composer using their built in composer option in the tools menu.

如果使用 phpstorm,您可以使用工具菜单中的内置作曲家选项下载作曲家。

You can run it from CLI by locating your php.exe, e.g

您可以通过找到 php.exe 从 CLI 运行它,例如

C:\wamp\bin\php\php7\php.exe composer.phar install

C:\wamp\bin\php\php7\php.exe composer.phar install

回答by Nick Weavers

First, to get php into your path see my answer here

首先,要让 php 进入您的路径,请在此处查看我的答案

Installing composer is explained nicely here(code below just for illustration. Be sure to get latest from the link)

安装作曲家在这里得到了很好的解释(下面的代码仅用于说明。请务必从链接中获取最新信息)

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === 'e115a8dc7871f15d853148a7fbac7da27d6c0030b848d9b3dc09e2a0388afed865e6a3d6b3c0fad45c48e2b5fc1196ae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

A quick check to confirm it worked:

快速检查以确认它有效:

    $ php composer.phar --version
    Composer version 1.2.1 2016-09-12 11:27:19