How to properly set PHP environment variable to run commands in Git Bash

我是研究僧i 提交于 2019-11-28 12:07:48

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:\wamp\bin\php\php5.3.8"

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

If you prefer to have it all in the unixy context of your bash cmd window:

  1. Open the bash window and you find by default you're in the root directory

    $ pwd
    /
    
  2. change to your user directory

    $ cd ~
    $ pwd
    /c/Users/nickw
    
  3. create a .bash_profile file or append to an existing one (use single quotes or $PATH will get interpolated)

    $ echo 'PATH=$PATH:/i/wamp64/bin/php/php5.6.19' >> .bash_profile
    
  4. check the file has the entry

    $ cat .bash_profile
    PATH=$PATH:/i/wamp64/bin/php/php5.6.19
    
  5. close the bash window and open a new one to check

    $ php --version
    PHP 5.6.19 (cli) (built: Mar  2 2016 20:09:42)
    Copyright (c) 1997-2016 The PHP Group
    Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    

If you're in git bash, just type PATH="path to php goes here"

It might be useful to copy the existing path and modify it, so you don't lose other useful paths. Type in export to see the path.

The new path is only valid for the session.

Hyder B.

You need to add the PHP directory to your path. On the command line, it would look like this:

SET PATH=%PATH%;C:\wamp\bin\php\php5.5

if in doubt, it's the directory containing the php.exe.

You can also pre-set the path in Windows' control panel. See here on how to do this in Windows 7 for example.

Be aware that if you call the PHP executable from an arbitrary directory, that directory will be the working directory. You may need to adjust your scripts so they use the proper directories for their file operations (if there are any).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!