在Windows CMD中运行php文件

时间:2021-07-31 02:29:48

I wanna run a .php file in windows cmd. i have follow this suggestion : php is not recognized as an internal command (in Windows)

我想在Windows cmd中运行.php文件。我遵循这个建议:php不被识别为内部命令(在Windows中)

But not working.

但不工作。

I am trying to do in command program C:\Windows\system32\cd \myfolder Then it enter in my folder like C:\php but when i enter my my php file address like C:\myfolder\php file.php it just showing error "php is not recognized as internal or external" But when i try without php command like C:\myfolder\file.php it just open in notepad. But i wanna run it in CMD. How can be it possible ?

我正在尝试在命令程序C:\ Windows \ system32 \ cd \ myfolder然后它进入我的文件夹,如C:\ php,但当我输入我的我的PHP文件地址,如C:\ myfolder \ php file.php它只是显示错误“php不被识别为内部或外部”但是当我尝试没有像C:\ myfolder \ file.php这样的php命令时,它只是在记事本中打开。但我想在CMD中运行它。怎么可能呢?

3 个解决方案

#1


34  

If running Windows 10:

如果运行Windows 10:

  1. Open the start menu
  2. 打开开始菜单

  3. Type path
  4. Click Edit the system environment variables (usually, it's the top search result) and continue on step 6 below.
  5. 单击编辑系统环境变量(通常是*搜索结果),然后继续执行下面的步骤6。

If on older Windows:

如果在较旧的Windows上:

  1. Show Desktop.

  2. Right Click My Computer shortcut in the desktop.

    在桌面右键单击“我的电脑”快捷方式。

  3. Click Properties.

  4. You should see a section of control Panel - Control Panel\System and Security\System.

    您应该看到控制面板的一部分 - 控制面板\系统和安全\系统。

  5. Click Advanced System Settings on the Left menu.

    单击左侧菜单上的高级系统设置。

  6. Click Enviornment Variables towards the bottom of the System Properties window.

    单击“系统属性”窗口底部的“环境变量”。

  7. Select PATH in the user variables list.

    在用户变量列表中选择PATH。

  8. Append your PHP Path (C:\myfolder\php) to your PATH variable, separated from the already existing string by a semi colon.

    将PHP路径(C:\ myfolder \ php)附加到PATH变量,通过分号与现有字符串分隔。

  9. Click OK

  10. Open your "cmd"

    打开你的“cmd”

  11. Type PATH, press enter

    输入PATH,按enter键

  12. Make sure that you see your PHP folder among the list.

    确保在列表中看到PHP文件夹。

That should work.

这应该工作。

Note: Make sure that your PHP folder has the php.exe. It should have the file type CLI. If you do not have the php.exe, go ahead and check the installation guidelines at - http://www.php.net/manual/en/install.windows.manual.php - and download the installation file from there.

注意:确保您的PHP文件夹具有php.exe。它应该具有文件类型CLI。如果您没有php.exe,请继续查看安装指南 - http://www.php.net/manual/en/install.windows.manual.php - 并从那里下载安装文件。

#2


1  

You should declare Environment Variable for PHP in path, so you could use like this:

你应该在路径中声明PHP的环境变量,所以你可以像这样使用:

C:\Path\to\somewhere>php cli.php

You can do it like this

你可以这样做

#3


1  

you can for example: set your environment variable path with php.exe folder e.g c:\program files\php

你可以举例:用php.exe文件夹设置你的环境变量路径,例如c:\ program files \ php

create a script file in d:\ with filename as a.php

在d:\中创建一个脚本文件,文件名为a.php

open cmd: go to d: drive using d: command

open cmd:使用d:命令转到d:drive

type following command

键入以下命令

php -f a.php

php -f a.php

you will see the output

你会看到输出

#1


34  

If running Windows 10:

如果运行Windows 10:

  1. Open the start menu
  2. 打开开始菜单

  3. Type path
  4. Click Edit the system environment variables (usually, it's the top search result) and continue on step 6 below.
  5. 单击编辑系统环境变量(通常是*搜索结果),然后继续执行下面的步骤6。

If on older Windows:

如果在较旧的Windows上:

  1. Show Desktop.

  2. Right Click My Computer shortcut in the desktop.

    在桌面右键单击“我的电脑”快捷方式。

  3. Click Properties.

  4. You should see a section of control Panel - Control Panel\System and Security\System.

    您应该看到控制面板的一部分 - 控制面板\系统和安全\系统。

  5. Click Advanced System Settings on the Left menu.

    单击左侧菜单上的高级系统设置。

  6. Click Enviornment Variables towards the bottom of the System Properties window.

    单击“系统属性”窗口底部的“环境变量”。

  7. Select PATH in the user variables list.

    在用户变量列表中选择PATH。

  8. Append your PHP Path (C:\myfolder\php) to your PATH variable, separated from the already existing string by a semi colon.

    将PHP路径(C:\ myfolder \ php)附加到PATH变量,通过分号与现有字符串分隔。

  9. Click OK

  10. Open your "cmd"

    打开你的“cmd”

  11. Type PATH, press enter

    输入PATH,按enter键

  12. Make sure that you see your PHP folder among the list.

    确保在列表中看到PHP文件夹。

That should work.

这应该工作。

Note: Make sure that your PHP folder has the php.exe. It should have the file type CLI. If you do not have the php.exe, go ahead and check the installation guidelines at - http://www.php.net/manual/en/install.windows.manual.php - and download the installation file from there.

注意:确保您的PHP文件夹具有php.exe。它应该具有文件类型CLI。如果您没有php.exe,请继续查看安装指南 - http://www.php.net/manual/en/install.windows.manual.php - 并从那里下载安装文件。

#2


1  

You should declare Environment Variable for PHP in path, so you could use like this:

你应该在路径中声明PHP的环境变量,所以你可以像这样使用:

C:\Path\to\somewhere>php cli.php

You can do it like this

你可以这样做

#3


1  

you can for example: set your environment variable path with php.exe folder e.g c:\program files\php

你可以举例:用php.exe文件夹设置你的环境变量路径,例如c:\ program files \ php

create a script file in d:\ with filename as a.php

在d:\中创建一个脚本文件,文件名为a.php

open cmd: go to d: drive using d: command

open cmd:使用d:命令转到d:drive

type following command

键入以下命令

php -f a.php

php -f a.php

you will see the output

你会看到输出