6

I've just upgraded PHP to the latest version. When I get back to Git, to my command shell, if I execute any PHP function, then I get this error :

sh.exe": php: command not found

I know I have to tell git bash where my new PHP path is, but I don't know how to do so and I can't find anything on Google about that.

EDIT :

I made a confusion you're right : I meant Git BASH by git. Thanks :)

SO here is the function I tried to call when I was dealing with symfony in the root foler of my app :

php app/console dump-sql

then Git BASH sent me the error above.

halfer
  • 19,824
  • 17
  • 99
  • 186
Miles M.
  • 4,089
  • 12
  • 62
  • 108
  • 1
    I don't get it. What's the link between git and php ? – Denys Séguret Jun 28 '12 at 16:19
  • 3
    Git doesn't need to know about the location of the PHP binary, at least not normally. What command are you issuing that causes that error? Sounds to me like you need to put PHP in your path, which you can do in My Computer > Advanced > Environment Variables (true on XP, may be different on more recent versions - do a web search for "set Windows PHP path"). – halfer Jun 28 '12 at 16:19
  • How did you upgrade PHP? Looks like the binary moved. When you upgrade PHP ensure, the binary location does not change. – hakre Jun 28 '12 at 16:28
  • And please give an example how you execute a PHP function that gives this error. – hakre Jun 28 '12 at 16:30
  • yes, the php location changes to php5.3.9 to php5.4.3. I upgrade php by re-installing wamp. – Miles M. Jun 28 '12 at 18:40
  • For clarification: if you're on Windows, it's unlikely you're using bash, and the error message you received was not from Git. The error message was probably from the Windows console, and was raised because it couldn't find the "php" binary in the system path. – halfer Jun 28 '12 at 21:01
  • that's true, it was the same on the windows console. But what do you mean by :"if you're on Windows, it's unlikely you're using bash" ? Is there something more adapted for this ? – Miles M. Jun 29 '12 at 13:52

3 Answers3

10

If you are windows, then following up on halfer's comment, it is required that you add the new /bin/ directory of the php folder to your PATH.

To do this: 1. Open start menu
2. Right click my computer->properties
3. Click advanced tab -> Environment variables
4. Scroll down in the second listbox for a entry called PATH
5. add this to the end ;C:/%PHP_LOCATION%/bin
where %PHP_LOCATION% is the place that you installed PHP to.

Braden
  • 1,548
  • 2
  • 12
  • 20
  • I had to log out and then log back in for 'Git Bash' to recognize this change, after logging back in all was fine. – Mike Sep 08 '12 at 01:09
3

I think you have git and bash confused.

Git is a program that would be running under bash, and isn't directly related to git unless you've gone out of your way to entangle them.

Most likely, the incantation you need is

export PATH=/path/where/php/is:$PATH

And then everything will be working. Note that needs to be the path to the directory, not the binary.

the $PATH at the end is to make sure that you don't clobber your old path.

richo
  • 8,717
  • 3
  • 29
  • 47
  • All true, but the OP is on Windows `:)` – halfer Jun 28 '12 at 21:02
  • Yes, but the point is that he's running bash, which in turn will let him manipulate his path using `export PATH` etc. I agree that manipulating the path system wide is more robust though :) – richo Jun 29 '12 at 00:10
3

I had the same error. I found that I needed the environment variable path in this format:

/c/wamp/bin/php/php5.3.13 (instead of C:\wamp\bin\php\php5.3.13)

Using Windows 7 & Git 1.7.10.

Danny Thompson
  • 1,526
  • 1
  • 11
  • 18