Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
537 views
in Technique[技术] by (71.8m points)

windows - How to properly set PHP environment variable to run commands in 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.

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

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.

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?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Adding the path to your PATH variable should fix that.

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

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...