How to run PHP on a command line

Posted by Damodar Bashyal on June 21, 2012

 

I wanted to run Magento's PHP Shell Scripts through Command Line on my Windows PC. So this is what i had to do to run PHP through windows cmd.

Find the folder where PHP is installed. As I am using WAMP, I found php.exe in folder:

C:\wamp\bin\php\php5.4.3

I copied the path and then followed these steps:

  • Click on Start Menu.
  • Right click on Computer link on the menu.
  • Click Properties.
  • Click on Advanced System Settings.
  • Click on Advanced tab.
  • Click on Environment Variables...
  • Under System variables, click under column Variable and press 'p' which will take you to 'Path' Variable.
  • Click Edit and then add copied PHP path separated with semi-colon (;C:\wamp\bin\php\php5.4.3) at the end of the line.
  • Restart your computer or close your previous command window.

Now, open your new command line window in windows and type php and hit enter, you shouldn't get any error like "'php' is not recognized as an internal or external command, operable program or batch file" anymore.

Now you can run Magento's Shell Commands as below.

php indexer.php reindexall
 
not published on website


QR Code: How to run PHP on a command line