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.
- First you will need download the latest version of PHP and extract it to your C:\ directory.
- 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.
Note: Use semicolon to delimit between System Variables.
- Open the CMD and enter PATH. Verify your PHP System Variable has been added. (Optional)
- Type “cd C:\[folder name]” in CMD to enter your PHP directory. Replace [folder name] with the name of your extracted PHP download.
- Type “php -v” to confirm version is correct.
- Enter “php c:\[directory]\[folder]\[php function].php”. Replace [php function] with your file.