How to access PHP with the Command Line on Windows

2019-01-04 00:52发布

I am trying to learn how to access PHP scripts from the command line (CLI)

Below is an image from my attempt, please help. I am running Windows 7

Cli

3条回答
一夜七次
2楼-- · 2019-01-04 01:13

Easy Way: Run CMD then type

C:\wamp\bin\php\php5.4.3\php.exe -f "C:\wamp\www\timenow.php"

Change the last part for a different script, and make sure you have the same version php folder as I do. (php5.4.3)

查看更多
不美不萌又怎样
3楼-- · 2019-01-04 01:19

For temporary use, try this: (benefit for use npm or composer)

> SET PATH=c:\wamp\bin\php\php5.3.29\;%PATH%

For test use this:

> echo %PATH%
c:\wamp\bin\php\php5.3.29\;c:\anothers\;

Now you can access to PHP command:

> php -v
PHP 5.3.29 (cli)
查看更多
手持菜刀,她持情操
4楼-- · 2019-01-04 01:31

You need to add your PHP installation directory to the %PATH% environment variable, or work from the PHP installation directory.

To add it to path (The best approach - Edited for Windows 7):

  • Right-click on a My Computer icon
  • Click Properties
  • Click Advanced system settings from the left nav
  • Click Advanced tab
  • Click Environment Variables button
  • In the System Variables section, select Path (case-insensitive) and click Edit button
  • Add a semi-colon (;) to the end of the string, then add the full file system path of your PHP installation (e.g. C:\Program Files\PHP)
  • Keep clicking OK etc until all dialog boxes have disappeared
  • Close your command prompt and open it again
  • Sorted

Alternatively, you can run cd <PHP installation path> before you try and run you command, or call your script like <FULL file system path of php.exe> <path to script>

查看更多
登录 后发表回答