Home > Article > Backend Development > How to Run PHP Scripts from the Command Line on Windows?
How to Execute PHP Scripts from Command Line on Windows
Access PHP scripts via the Command Line Interface (CLI) presents a challenge, especially on Windows. To resolve this issue, you need to modify your system settings.
Solution:
To execute PHP scripts from the CLI:
Update the %PATH% Environment Variable:
Navigate to "Advanced System Settings" under "Computer Properties" and select the "Advanced" tab. Click the "Environment Variables" button and locate the "System Variables" section. Edit the "Path" variable and append the full path to your PHP installation directory, separated by a semicolon (;). For example: C:Program FilesPHP.
Execute from PHP Installation Directory:
An alternative approach is to work directly from the PHP installation directory. Open a command prompt and change the directory to the PHP installation path using the cd command.
Call PHP with Full Path:
If the previous methods do not work, you can call the PHP script directly by specifying the full path of the PHP executable followed by the script's path. For instance: C:Program FilesPHPphp.exe C:pathtoscript.php.
Remember to close and reopen your command prompt after making these changes.
The above is the detailed content of How to Run PHP Scripts from the Command Line on Windows?. For more information, please follow other related articles on the PHP Chinese website!