Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access PHP with the Command Line on Windows?

I am trying to learn how to access PHP scripts from the command line (CLI)

Below is an image from my attempt, please help. I am running Windows 7

Cli

like image 609
JasonDavis Avatar asked Sep 05 '11 11:09

JasonDavis


People also ask

How do I open PHP on Windows?

Hence, you can open php files with Windows 10 supplied Notepad or Wordpad. Third party editors such as Notepad++ are generally used to code with these kind of files. You can start Notepad or Wordpad > File > Open > Select the php file and open.

What is PHP CLI command?

PHP's Command Line Interface (CLI) allows you to execute PHP scripts when logged in to your server through SSH. ServerPilot installs multiple versions of PHP on your server so there are multiple PHP executables available to run.


1 Answers

You need to add your PHP installation directory to the %PATH% environment variable, or work from the PHP installation directory.

To add it to path (The best approach - Edited for Windows 7):

  • Right-click on a My Computer icon
  • Click Properties
  • Click Advanced system settings from the left nav
  • Click Advanced tab
  • Click Environment Variables button
  • In the System Variables section, select Path (case-insensitive) and click Edit button
  • Add a semi-colon (;) to the end of the string, then add the full file system path of your PHP installation (e.g. C:\Program Files\PHP)
  • Keep clicking OK etc until all dialog boxes have disappeared
  • Close your command prompt and open it again
  • Sorted

Alternatively, you can run cd <PHP installation path> before you try and run you command, or call your script like <FULL file system path of php.exe> <path to script>

like image 191
DaveRandom Avatar answered Sep 18 '22 13:09

DaveRandom