Find PHP version on windows command line

Find PHP version on windows command line

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Why php -v Fails on Windows and How to Actually Check Your Version

When you type php -v in the Windows Command Prompt and receive the error "php is not recognized as internal or external command," it rarely means your PHP installation is broken. It almost always indicates a configuration issue where the system cannot locate the executable. This specific error message originates from the Windows Shell, which searches for executables by consulting the PATH environment variable before attempting to load anything.

If you are following tutorials that suggest running commands in a standard Command Prompt (cmd.exe) on Windows without first modifying your environment variables, this error is guaranteed to appear. The most common scenario involves developers who have installed PHP via XAMPP or WAMP but fail to add the installation directory to their system's PATH variable. Without this step, the command line has no idea where to find the php.exe binary, even if it sits perfectly fine in your project root or within an Apache environment.

To resolve this immediately without altering global system settings, you can rely on the full path to the executable. Navigate to the directory containing PHP and run the version check directly. For example, if XAMPP is installed in C:\xampp, you can execute:

"C:\xampp\php\php.exe" -v

This approach bypasses the need for environment variable changes entirely. It is a reliable fallback that confirms your installation is functional and returns the expected version string, such as PHP 8.x.x (cli). However, relying solely on full paths in every session is inefficient. If you intend to run PHP commands frequently from any directory, updating the PATH environment variable is the superior long-term solution.

Updating the PATH requires accessing the System Properties dialog, selecting "Environment Variables," and appending your PHP installation folder (e.g., C:\xampp\php) to the system-wide or user-specific PATH. Once this is done, a restart of the terminal session is required for changes to take effect. This method ensures that php -v works universally across all your projects, mirroring the behavior found on Linux distributions where PHP is typically installed globally by default.

For Laravel developers specifically, there are additional considerations regarding how PHP interacts with web servers versus the command line. While php -v verifies the CLI version, the version running in your production environment might be managed by a reverse proxy or a container orchestration tool like Docker. If you are deploying a Laravel application using Swoole for asynchronous processing, you must ensure that the Swoole extension is compiled against the exact same PHP binary that php -v reports. Mismatched versions can lead to runtime errors where Swoole fails to initialize despite the core PHP version appearing correct.

Furthermore, when working with Laravel Forge or Vapor, these tools often install specific PHP versions within a managed environment. In those contexts, you might not have direct access to the system PATH, but the platform handles the binary location. If you are troubleshooting build failures where scripts claim "command not found," verifying that your local development environment matches the production configuration is critical. Tools like phpenv or choco install php can manage multiple versions, allowing you to switch between them seamlessly using commands like phpenv global 8.2.

Ultimately, the error "php is not recognized" is a navigation problem, not an application failure. By understanding how Windows resolves executable paths and knowing when to rely on full paths versus environment variables, you can diagnose issues quickly. If you need further assistance with configuring your PHP environment for a specific framework or deployment strategy, resources like https://laravelcompany.com provide valuable guidance on setting up robust development pipelines that minimize these friction points.

Our network