Run php file in windows CMD

2019-01-17 07:54发布

I wanna run a .php file in windows cmd. i have follow this suggestion : php is not recognized as an internal command (in 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 ?

标签: php cmd
4条回答
虎瘦雄心在
2楼-- · 2019-01-17 08:22

It seems your question is very much older. But I just saw it. I searched(not in google) and found My Answer.

So I am writing its solution so that others may get help from it.

Here is my solution.

Unlike the other answers, you don't need to setup environments.

all you need is just to write php index.php if index.php is your file name.

then you will see that, the file compiled and showing it's desired output.

查看更多
SAY GOODBYE
3楼-- · 2019-01-17 08:23

If running Windows 10:

  1. Open the start menu
  2. Type path
  3. Click Edit the system environment variables (usually, it's the top search result) and continue on step 6 below.

If on older 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.

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

  9. Click OK

  10. Open your "cmd"

  11. Type PATH, press enter

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

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.

查看更多
Evening l夕情丶
4楼-- · 2019-01-17 08:27

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

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

You can do it like this

查看更多
走好不送
5楼-- · 2019-01-17 08:39

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

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

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

type following command

php -f a.php

you will see the output

查看更多
登录 后发表回答