How to run a PHP program from command prompt on a Windows Machine? -


i'm php developer profession.

i'm using lenovo ideapad laptop runs on windows 10 home single language 64-bit operating system

i've installed xampp control panel v3.2.2 @ location "c:\xampp" execute php programs in web browser on machine.

the "php.exe" file present @ location "c:\xampp\php".

the document root directory save php files @ location "c:\xampp\htdocs".

i'm able run php programs created , saved in directory c:\xampp\htdocs\html_playground starting xampp software(by double clicking on xampp shortcut present on desktop) , entering url of program file "http://localhost/html_playground/sample.php" in browser's address bar.

this way i'm able run php programs finely want run same program windows command prompt

for done following steps :

  • went went advanced system settings (control panel\system , security\system\advanced system settings)
  • then clicked on environment variables
  • then selected variable path
  • then clicked edit... button
  • then after ending semicolon of existing string added string "c:\xampp\php" adding blank space after semicolon.

the final new string looking below :

%userprofile%\appdata\local\microsoft\windowsapps; c:\xampp\php

  • then clicked on ok
  • opened command prompt
  • went path c:\xampp\htdocs\html_playground on command prompt using cd command
  • typed in sample.php(the file contaning php program)

then instead of showing output of program opened same file in sublime text(the editor i'm using write code)

the sample.php file has got following php executable code :

<?php     echo 'hello world!'; ?> 

for reference i'm attaching screen-shot of command prompt window :

command prompt window

now question

  • why i'm not able see output @ command prompt or in web browser?
  • am doing mistake or what?
  • is necessary start xampp server run program in web browser executing program command prompt too?
  • did make mistake in setting environment variables?
  • is there need set environment variables? if yes why? if no why?
  • as php supposed suitable language web development think it's run program in web developer's software i.e. web browser. i'm not understanding reason why people insist running php programs command line rather running same program web browser only?

please me out answering queries , helping me in running program command prompt.

even tried restarting pc , run php -v command didn't work out. following screen-shot of same :

command prompt output after system restart

if you're wanting run cli php highly suggest installing vanilla php found on windows.php.net. let install c:\php reason recommend if ever want use composer (and there's chance want to), natively find there.

now can open command prompt , run scripts follows

c:\php\php.exe c:\path\to\php\script.php 

to specifics

  1. why i'm not able see output @ command prompt or web browser? because output sent command line. browser requests sent via web server browser
  2. is necessary start xampp server run program command prompt too? cli requests, no. php executable , can run on own. if want browser requests xampp needs running.
  3. is there need set environment variables? if yes why? if no why? not really. cli pay attention php.ini xampp configs apache, mostly.
  4. but i'm not understanding reason why people insist running php programs command line main reason automated tasks. have several processes @ work run on cron job.

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -