How to run PHP in command line ?

  • PHP is a server side scripting language, a lot of development using PHP is done on a live web environment. However, PHP does allow you to install it and run scripts on your local machine with no web access needed.
  • Running PHP from Windows command line can be especially useful when trying to rapidly develop custom scripts, or to read and modify local files.

Step 1

  • First you will need download the latest version of PHP and extract it to your C:\ directory.
  • https://windows.php.net/download#php-5.6
how to run php in command line

Step 2

  • Navigate to Control Panel > System and Security > System > Advanced system settings. In the System variables panel click, find and edit the Path variable and append the path to your extracted PHP folder.
C:\[php folder]

Note: Use semicolon to delimit between System Variables.

how to run php in command line

Step 3

  • Open the CMD and enter PATH. Verify your PHP System Variable has been added. (Optional)

how to run php in command line

Step 4

  • Type “cd C:\[folder name]” in CMD to enter your PHP directory. Replace [folder name] with the name of your extracted PHP download.

Step 5

  • Type “php -v” to confirm version is correct.
how to run php in command line

Step 6

  • Enter “php c:\[directory]\[folder]\[php function].php”. Replace [php function] with your file.

Categorized in:

Tagged in:

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,