Execute PHP Script From Command Line in Windows (OR) How to Set a Environment Variable for PHP in Microsoft Windows

I would like to post a solution for the following queries which are important for the programmer to execute the PHP script from command line.

Execute PHP Script From Command Line in Windows

How to Set a Environment Variable for PHP in Microsoft Windows

Setting Environment variables in Windows 7 PHP

Environment Variable windows7

Follow the steps to set Environment Variable

My OS: Windows 7

  • Go to properties of My Computer
  • Click on Advanced System Settings in Left side
  • Select Advanced tab and click on Environment Variables
  • In the System Variables search for Path Variable, select that one and click edit
  • Add the semicolon(;) at the end of the line, and paste the PHP¬†path C:\wamp\bin\php\php5.4.16
  • Save all changes by clicking OK.
  • open command prompt and go the folder where the PHP file exists, then execute by using the following command.
  • D:\>php file-name.php (press Enter)