How to Make PHP Commands Work on the Windows Command Line?

Mary-Kate Olsen
Release: 2024-10-31 00:55:30
Original
329 people have browsed it

How to Make PHP Commands Work on the Windows Command Line?

Accessing PHP through the Command Line on Windows

Accessing PHP scripts via the command line (CLI) on Windows can prove challenging. This article addresses this issue and provides solutions to help you navigate this process effectively.

One common error encountered, as depicted in the provided image, is the "php.exe" command not being recognized. This occurs when the PHP installation directory is not added to the Windows %PATH% environment variable.

Solution: Adding to %PATH% Environment Variable

To add PHP to the %PATH% variable:

  1. Right-click "My Computer" and select "Properties."
  2. Navigate to "Advanced system settings" in the left-hand menu.
  3. Click the "Advanced" tab and then "Environment Variables."
  4. Under "System Variables," select "Path" and click "Edit."
  5. Append the full file system path of your PHP installation (e.g., C:Program FilesPHP) to the string, separated by a semi-colon (;).

Alternative Approaches

If adding to the %PATH% variable is not preferred, you can also:

  • Navigate to the PHP installation directory before running PHP commands (e.g., cd C:Program FilesPHP).
  • Call your PHP script using the full file system path of the php.exe executable (e.g., "C:Program FilesPHPphp.exe" -f C:pathtomy_script.php).

Once you have completed one of these steps, you should be able to execute PHP commands from the command line seamlessly.

The above is the detailed content of How to Make PHP Commands Work on the Windows Command Line?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template