Diagnosing and Fixing "PHP Command Not Found" on Windows 10
When you type php into a command prompt or Git Bash on Windows 10 and receive the error 'php' is not recognized as an internal or external command, the issue is almost always environmental, not a missing installation. You might have XAMPP installed, but that does not automatically make the PHP binary available to your shell sessions. The PATH environment variable controls which directories the operating system searches for executable files, and if the directory containing php.exe is absent from this list, the shell simply cannot locate it.
Understanding XAMPP's Default Installation Path
XAMPP installs PHP in a specific location, typically C:\xampp\php. However, the default Windows environment does not include this path automatically. Unlike macOS or Linux distributions where /usr/bin is standard, Windows requires manual configuration for third-party tools. Even if you haven't edited your php.ini fileâwhich handles runtime behavior like error reporting and extensionsâthe shell's ability to invoke the CLI depends entirely on the system PATH.
To resolve this, you must add the installation path to your environment variables. Open your System Properties by right-clicking the Start button and selecting "System," then clicking "Advanced system settings." Under the Environment Variables section, edit the Path variable for both System and User variables. Add C:\xampp\php to the list. After saving, you must close and reopen your terminal (Command Prompt, PowerShell, or Git Bash) for changes to take effect.
Verifying the Installation with where and which
Once the path is updated, verify that the shell detects the binary correctly. In Command Prompt, run:
where php
This command lists all directories in your PATH where a file named php.exe exists. If it returns a path like C:\xampp\php, you are ready to proceed. If it returns nothing, the environment variable update did not apply correctly, or multiple PHP versions exist elsewhere on the system causing ambiguity.
In Git Bash, use the equivalent command:
which php
If Git Bash still fails to recognize the command even after updating Windows PATH variables, check if Git has its own isolated environment variables that need updating via git config. This is a common pitfall for developers who configure their main terminal but neglect their development shell.
Addressing Laravel Composer and Development Workflows
The primary blocker in your scenario is likely setting up the local environment for Laravel development. When you run composer install, Composer attempts to execute the PHP binary to download dependencies and generate autoload files. If the CLI tool is missing, the process halts immediately.
Ensure that you are running Composer via the same shell where PHP is now recognized. Avoid relying solely on the XAMPP Control Panel's built-in terminal if it behaves differently from your standard command prompt; stick to your preferred IDE or terminal for consistency. Additionally, check if a conflicting PHP version exists in system directories like C:\Windows\System32. If an older version of PHP is present there, Windows might prioritize it over the XAMPP installation, potentially leading to missing modules or incorrect behavior.
If you are working on a Laravel project specifically, ensure that your composer.json file does not rely on specific extensions that are commented out in your php.ini. While adding the path fixes the "command not found" error, runtime errors regarding missing extensions (like pdo_mysql or mbstring) will still occur if they are disabled in configuration.
Final Steps for Consistency
After confirming the command works, test your Laravel setup by navigating to the project directory and running:
php artisan serve
This confirms that both the CLI tool and the web server (Apache within XAMPP) are communicating correctly. If you encounter issues where the shell works but the web server doesn't, inspect the Apache error logs in C:\xampp\apache\logs for specific PHP warnings regarding loaded extensions. Keeping your environment variables consistent across different shells is the most reliable way to avoid these interruptions.
