Skip to main content
run-php-file-from-windows-cmd-line

How To Run PHP File From Windows Command 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

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. 🙂

admin

HI, i am software developer having knowledge of PHP, C, C++ programming languages. I am very passionate about programming and ability to solve the programming problems. CodeandTuts is my blog where i like to put new tutorial and help new developer.

Leave a Reply

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