I'm a PHP Developer by profession.
I'm using a Lenovo Ideapad laptop that runs on Windows 10 Home Single Language 64-bit Operating System
I've also installed XAMPP Control Panel v3.2.2 at location "C:\xampp" to execute PHP programs in a web browser on my machine.
The "php.exe" file is present at the location "C:\xampp\php".
The document root directory to save the PHP files is at the location "C:\xampp\htdocs".
I'm able to run the PHP programs that I created and saved in a directory C:\xampp\htdocs\html_playground by starting the XAMPP software(by double clicking on XAMPP shortcut present on my desktop) and entering the URL of a program file like this "http://localhost/html_playground/sample.php" in a browser's address bar.
This way I'm able to run the PHP programs finely but I want to run the same program from Windows Command Prompt
For it I done following steps :
- Went to Went to Advanced System Settings (Control Panel\System and Security\System\Advanced System Settings)
- Then clicked on Environment Variables
- Then selected the variable Path
- Then clicked Edit... button
- Then after the ending semicolon of existing string I added the string "C:\xampp\php" by adding a blank space after the semicolon.
The final new string was looking like below :
%USERPROFILE%\AppData\Local\Microsoft\WindowsApps; C:\xampp\php
- Then clicked on Ok
- Opened command prompt
- Went to the path C:\xampp\htdocs\html_playground on command prompt using cd command
- Typed in sample.php(The file contaning my PHP program)
Then instead of showing the output of the program it opened the same file in Sublime Text(The editor I'm using to write the code)
The sample.php file has got the following PHP executable code :
<?php
echo 'Hello World!';
?>
For your reference I'm also attaching the screen-shot of the command prompt window :
Now my question is
- Why I'm not able to see the output at command prompt or in a web browser?
- Am I doing any mistake or what?
- Is it necessary to start the XAMPP server like I normally do to run the program in a web browser for executing the program from command prompt too?
- Did I make any mistake in setting environment variables?
- Is there really a need to set environment variables? If yes why? If no why?
- As PHP is supposed to be the suitable language for web development then I think it's always good to run the program in web developer's software i.e. a Web Browser. But I'm not understanding the reason why people do insist for running the PHP programs from Command Line rather than running the same program from web browser only?
Please somebody help me out by answering my queries and helping me in running the program from command prompt.
Even I tried restarting the PC and run the php -v command but it also didn't work out. Following is the screen-shot of the same :