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

2024-08-10php开发问题
1

本文介绍了如何正确设置 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.

这篇关于如何正确设置 PHP 环境变量以在 Git Bash 中运行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17