Running PHP works in Command Prompt but not Git Bash

6

3

I've recently got a new laptop and have been in the process of setting it up.

I've installed WAMP, which is what I use to do my PHP development (installs Apache2, MySql, and PHP).

I also like to use Git Bash as my preferred command line tool, however when I try to do anything with PHP through the command line - I get a strange result; nothing happens and there is no error:

enter image description here

Now, if I run this through command prompt it works perfectly fine:

enter image description here

I've set the correct PATH variable for PHP and triple checked this:

enter image description here

What can I do to get PHP working through my Git Bash command line?

EDIT

Output of ll /c/wamp64/bin/php/php7.0.10/php:

-rwxr-xr-x 1 james.b 1049089 122368 Aug 18  2016 /c/wamp64/bin/php/php7.0.10/php*

Output of echo $PATH | tr ":" "\n":

/c/Users/James.b/bin
/mingw64/bin
/usr/local/bin
/usr/bin
/bin
/mingw64/bin
/usr/bin
/c/Users/James.b/bin
/c/ProgramData/Oracle/Java/javapath
/c/WINDOWS/system32
/c/WINDOWS
/c/WINDOWS/System32/Wbem
/c/WINDOWS/System32/WindowsPowerShell/v1.0
/c/Go/bin
/c/wamp64/bin/php/php7.0.10
/c/ProgramData/ComposerSetup/bin
/c/Program Files/Microsoft/Web Platform Installer
/c/Program Files/Microsoft SQL Server/Client SDK/ODBC/110/Tools/Binn
/c/Program Files (x86)/Microsoft SQL Server/120/Tools/Binn
/c/Program Files/Microsoft SQL Server/120/Tools/Binn
/c/Program Files/Microsoft SQL Server/120/DTS/Binn
/c/Program Files (x86)/Microsoft SQL Server/120/Tools/Binn/ManagementStudio
/c/Program Files (x86)/Microsoft SQL Server/120/DTS/Binn
/cmd
/c/Users/James.b/AppData/Local/Microsoft/WindowsApps
/c/Users/James.b/AppData/Roaming/Composer/vendor/bin
/c/wamp64/bin/php/php7.0.10
/usr/bin/vendor_perl
/usr/bin/core_perl

James

Posted 2017-08-07T09:55:39.940

Reputation: 163

Type which php just to make sure, or launch php with the full path. – simlev – 2017-08-07T09:59:24.313

@simlev that returns /c/wamp64/bin/php/php7.0.10/php which is the correct directory? Should the php at the end be php.exe as I am on windows? – James – 2017-08-07T10:01:01.457

1It looks correct. Try with the full path /c/wamp64/bin/php/php7.0.10/php -v, or go into that directory and type ./php -v. – simlev – 2017-08-07T10:11:07.453

@simlev OK that worked. Is there something I can do to get it working? Otherwise I can just setup an alias for it – James – 2017-08-07T10:18:35.613

Yes, I suggest you simply alias it. – simlev – 2017-08-07T10:24:11.480

It works in my instance, I'd double check the path and the permissions. Please post the output of echo $PATH and ll /c/wamp64/bin/php/php7.0.10/php. – simlev – 2017-08-07T10:53:20.473

@simlev have posted the outputs. – James – 2017-08-07T11:13:32.950

All seems ok to me (apart form the path being duplicated among another three or so but this shouldn't hurt). I can't find an explanation, I have the same "working" with PortableGit-2.14.0-64-bit and UniServer. – simlev – 2017-08-07T15:07:43.247

Answers

7

What can I do to get PHP working through my Git Bash command line?

alias php='/c/wamp64/bin/php/php7.0.10/php'

simlev

Posted 2017-08-07T09:55:39.940

Reputation: 3 184

do we need to every time we open git bash? Or we can add it in some .profile file? – Knight017 – 2019-05-01T07:18:39.860

1@Knight017 add it to ~/.bashrc. – simlev – 2019-05-02T14:03:49.233

1

I entered the following command in git bash and it worked.

alias php='/d/xampp/php/php.exe'

Note: My xampp is installed in "D" drive (D:).

Dinesh Yadav

Posted 2017-08-07T09:55:39.940

Reputation: 111

How is your answer better/different than the other one? – gronostaj – 2018-05-24T06:58:00.103

There is a difference in the path. In my case, I needed to enter the full path includingphp.exe. – Dinesh Yadav – 2018-05-24T07:00:09.593