How to Run PHP Scripts from the Command Prompt in Any Folder
Download a "Thread Safe" version of PHP that corresponds to your computer., Navigate to "Downloads" folders, right click on the downloaded folder and select Extract All. , Select Browse and choose the folder where you would like the extracted files...
Step-by-Step Guide
-
Step 1: Download a "Thread Safe" version of PHP that corresponds to your computer.
For example, if you have a 64-bit computer, download:
Zip VC14 x64 Thread Safe (pictured above). ,, Note that in this scenario, we are extracting the files to a new folder we have created on the desktop titled “PHP” for ease of access. ,,, When the search results populate, select Edit environment variables for your account. , If the variable “Path” does not exist, click New under “User variables”, and in “variable name”, type “Path”. , You should now see the file address in the variable value section.
If a variable value already exists, scroll the end of the existing value, input a semicolon, and paste the file address to the right of the semicolon ,, Notice that you should now be able to run PHP from Command Prompt in any folder.
The above picture is an example of a simple .php file which displays the message "Hello, World!"
In this scenario, we have placed “helloworld.php” file on the desktop to test its functionality.,, If everything worked as it should, your .php file should run.
In this case, Command Prompt displayed "Hello, World!" -
Step 2: Navigate to "Downloads" folders
-
Step 3: right click on the downloaded folder and select Extract All.
-
Step 4: Select Browse and choose the folder where you would like the extracted files to be nested.
-
Step 5: Navigate to the folder with the extracted files and single left click on the file titled “php”.
-
Step 6: Right click on the navigation bar and select Copy address as text.
-
Step 7: Open Control Panel and type "environment" in the search bar.
-
Step 8: Under “User variables”
-
Step 9: select “Path” and click Edit.
-
Step 10: Right click under the variable name and click Paste.
-
Step 11: Select OK in the “Edit User Variable” window and then select OK in the “Environment Variables” window.
-
Step 12: Locate a .php file to test that everything is functioning correctly.
-
Step 13: Open Command Prompt.
-
Step 14: Open Command Prompt and navigate to wherever you have placed your test .php file.
-
Step 15: Type “php {Insert your test file name here}.php”.
Detailed Guide
For example, if you have a 64-bit computer, download:
Zip VC14 x64 Thread Safe (pictured above). ,, Note that in this scenario, we are extracting the files to a new folder we have created on the desktop titled “PHP” for ease of access. ,,, When the search results populate, select Edit environment variables for your account. , If the variable “Path” does not exist, click New under “User variables”, and in “variable name”, type “Path”. , You should now see the file address in the variable value section.
If a variable value already exists, scroll the end of the existing value, input a semicolon, and paste the file address to the right of the semicolon ,, Notice that you should now be able to run PHP from Command Prompt in any folder.
The above picture is an example of a simple .php file which displays the message "Hello, World!"
In this scenario, we have placed “helloworld.php” file on the desktop to test its functionality.,, If everything worked as it should, your .php file should run.
In this case, Command Prompt displayed "Hello, World!"
About the Author
Emily Howard
Creates helpful guides on creative arts to inspire and educate readers.
Rate This Guide
How helpful was this guide? Click to rate: