如何正确设置 PHP 环境变量以在 Git Bash 中运行命令

整个网站都有一些类似的问题,但没有一个给出我正在寻找的答案.

There are a few similar questions as this throughout the site, but none of them are giving me the answer I'm looking for.

我正在尝试通过 Git Bash 在具有 WAMP 的 Windows 机器上安装 Composer.

我正在使用以下命令:

What I'm trying to do is install Composer via Git Bash on a Windows machine that has WAMP.

I'm using the following command:

curl -s http://getcomposer.org/installer | php

这不起作用,因为无法识别php".所以我研究了这个问题,我意识到Windows不知道'php'是什么,我需要设置一个环境变量.

This is not working, as 'php' is not recognized. So I looked into the problem and I realized that Windows does not know what 'php' is, and I need to set an environment variable.

我进入环境变量对话框并输入 'php' 作为变量和 C:wampinphpphp5.3.8 作为值.这个对吗?我应该针对特定文件还是整个目录?

I go into the environment variable dialogue and enter 'php' as the variable and C:wampinphpphp5.3.8 as the value. Is this correct? Should I be targeting a specific file or the directory as a whole?

执行此操作后,我再次尝试该命令,但由于它仍然无法识别php"而失败.我也试过将文件路径直接放入命令中,但也没有用.

After doing this, I try the command again and it fails because it still does not recognize 'php'. I have also tried putting the file path into the command directly, but that didn't work either.

所以我很好奇我做错了什么.我的路径不正确吗?

So I am curious as to what I am doing incorrectly. Is my path incorrect?

推荐答案

将路径添加到 PATH 变量应该可以解决这个问题.

Adding the path to your PATH variable should fix that.

右击我的电脑,进入高级设置,点击环境变量,然后编辑PATH系统变量.

Right click My Computer, go to advanced settings, click Environment Variables then edit the PATH system variable.

添加分号,然后添加 PHP 二进制文件的路径,即;C:wampinphpphp5.3.8"

Add a semi-colon and then the path to your PHP binary, i.e. ";C:wampinphpphp5.3.8"

最后,重启 Git Bash 以更新 PATH 变量.

Finally, restart the Git Bash so that it updates the PATH variable.

相关文章