Home  >  Article  >  Backend Development  >  How to Run PHP Scripts from the Command Line on Windows?

How to Run PHP Scripts from the Command Line on Windows?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-10-30 18:55:30794browse

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:

  1. 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.

  2. 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.

  3. 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn