Run .php file in Windows Command Prompt (cmd)

run php from command line windows xampp
execute php file from command line linux
run php file from command line
run php file from command line ubuntu
run php code from command line
php command line arguments
run php function from command line
run command php windows

I want to run a .php file in windows cmd. I followed this (suggestion) php is not recognized as an internal command (in Windows)

But it did not work.

I tried this command prompt: C:\Windows\system32> cd \myfolder

And within myfolder I did as follows: C:..\myfolder> php file.php but I get an error "php is not recognized as internal or external"

But when I try without php command like this; C:..\myfolder> file.php it just opens in notepad, yet I want to run it in cmd. How can I do it?

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 - - and download the installation file from there.

Run .php file in Windows Command Prompt (cmd), If running Windows 10: Open the start menu; Type path; Click Edit the system environment variables (usually, it's the top search result) and  To open windows command line, Press (windows + R) and type “cmd” and hit enter. It will open windows command prompt shown as below. Now type “php -v” to check php version. If this command works fine and is not produce any error then we can assume that php is working in windows command line.

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

How to run any PHP Script as a Windows Service (8/2012/7/2008 , Start a command prompt (Start button > Run > cmd.exe). In the window that appears, type the full path to the PHP executable (php.exe)  Running PHP From Windows Command Line. Since PHP is a server side scripting language, a lot of website development using PHP is done on a live web environment. However, PHP does allow you to install it and run scripts on your local machine with no web access needed. Running PHP from Windows command line can be especially useful when trying to rapidly develop custom scripts, or to read and modify local files.

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

How to execute PHP code using command line ?, You just follow the steps to run PHP program using command line. Open terminal or command line window. Goto the specified folder or directory where php files  To run PHP from command line in windows you just have to add php executable file path to system variable correctly. If you have installed XAMPP, and want to use command line to run PHP on Windows, here is this helpful article for you. I have already installed XAMPP in my local pc having windows 7 OS.

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.

How to run php script in command prompt windows, The above program can be executed using the EditRocket Tools -> PHP -> Execute Program option, or you can execute it from a command prompt. To execute  How can I run a PHP script from the command line using the PHP interpreter which is used to parse web scripts? I have a phpinfo.php file which is accessed from the web shows that German is installed. However, if I run the phpinfo.php from the command line using - php phpinfo.php and grep for German, I don't find it. So both phps are different.

Running php program on command prompt using WAMP, [code]C:\xampp\htdocs>php test.php Hello Team ,test.php file execute here C:\​xampp\htdocs> <?php Is PHP merely a set of Perl commands? if you want to execute php scripts through windows command line, then that is simple and easy​. When I click the run button it has to open the command prompt and run the main.bat file, but whenever I click run it says nothing. php windows batch-file share | improve this question

PHP Command line: how to run PHP from command line in Windows, There are no user contributed notes for this page. Features · HTTP authentication with PHP · Cookies · Sessions · Dealing with XForms · Handling file uploads  Start a command prompt (Start button > Run > cmd.exe) In the window that appears, type the full path to the PHP executable ( php.exe ) followed by the full path to the script you wish to run as a windows service.

How to Install PHP and Run PHP Programs on Windows, Press Windows+R to open “Run” box. Type “cmd” and then click “OK” to open a regular Command Prompt. Type “cmd” and then press Ctrl+Shift+Enter to open an administrator Command Prompt. Open Command Prompt from the File Explorer Address Bar In File Explorer, click the address bar to select it (or press Alt+D). Type “cmd” into the address bar and hit Enter to open the Command Prompt with the path of the current folder already set.

  • Thanks i have done all of this. But what about the php.exe file. I havn't it. Is it need to convert php file as .exe ?
  • When you type "php file.php", the first php is actually the php.exe, command line tool. Just edited the answer. Please check
  • ok, what i have done. my path is C:\myfolder\file.php I edit variable path with another path like ( .;path;C:\myfolder ) And i typed in cmd C:\Windows\system32>cd \myfolder and get my folder and showing in cmd like C:\myfolder> and then i type C:\myfolder>php file.php then it just showing "php is not recognized as internal or external" what i need to do ?
  • Go to , download an installer first. Then, install PHP in your machine by clicking the installer. Then find out the path in which the PHP was installed. Follow my instructions and add the PHP path to the PATH variable
  • OK, I have just copied that php.exe from wamp folder. And now i can from my directory. Thanks.
  • Tired it but it just showing error "php is not recognized as internal or external"
  • Are you sure php was correctly installed?... Type 'php -v' on your terminal to confirm