How To Run PHP File From Windows Command Line

run-php-file-from-windows-cmd-line

To run PHP file from windows command line, you must have installed PHP in your windows system. Individually setup PHP environment is tedious and lengthy task in windows system. So we will use fully operational XAMPP environment which comes with PHP, MySQL and Perl. If you haven’t installed XAMPP web server then here is an article about how to install XAMPP in windows.

I assume that XAMPP environment is installed in your windows system. Now open windows command line and setup XAMPP path.

To open windows command line, Press (windows + R) and type “cmd” and hit enter. It will open windows command prompt shown as below.

run-php-using-command-line-1

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. If above command produce error like this “php is not recognized as an internal or external command” then you have to set your xampp php path in system environment variable.

run-php-using-command-line-2

Check this tutorial to fix “php is not recognized as an internal or external command” error.

After adding php path to environment variable, restart the command prompt and run again “php -v” command and it will give you version of PHP language.

run-php-using-command-line-3

Now create a simple PHP file with name “test.php” and put below code in it and save it in in “(Your Drive Name):/xampp/htdocs” folder.

<?php echo "I am John Doe."; ?>

To run test.php file, hit “php test.php” command. it will execute php file and show the result of php code. Check below screenshot

Related:  Laravel 5.8 Todo CRUD Example Step By Step

run-php-using-command-line-4

I hope that you have understand that how to run PHP file using command line. Still if you have any questions then please let me know in comment. I will try my best to give you satisfied answer. Thank you very much. 🙂

About Chintan Panchal

I am web developer having 4+ year of experience of web development. I have worked on codeigniter, symfony, laravel and wordpress.

View all posts by Chintan Panchal →

One Comment on “How To Run PHP File From Windows Command Line”

  1. hai,
    i run php file on my windows,but after it executed, my windows delete my php file (not php.exe)
    And i can’t create or copy in the same folder and the same name of that php file

Leave a Reply to fay Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.