You type php -v and Windows answers with “php is not recognized as an internal or external command”. PHP is on the machine; Windows just can’t find it. This DevAnswers guide adds PHP (and Composer) to your PATH properly, via the GUI or PowerShell, including the step almost everyone misses.
Quick Fix: Put php.exe’s Folder on Your PATH
Add the folder that contains php.exe (for example C:\php) to your user Path under System Properties › Environment Variables, or from PowerShell:
$userPath = [Environment]::GetEnvironmentVariable('Path', 'User')
[Environment]::SetEnvironmentVariable('Path', "$userPath;C:\php", 'User')
Then open a new terminal and run php -v. The new terminal is the step almost everyone misses; the sections below cover finding PHP, the GUI route, and the traps.
What the Error Actually Means
When you run a command, Windows walks every folder listed in the PATH environment variable looking for a matching executable (classic cmd.exe also checks the current directory first; PowerShell deliberately skips it). If php.exe’s folder isn’t on that list, the search comes up empty and you get the error. PowerShell phrases it differently (“The term ‘php’ is not recognized as the name of a cmdlet, function, script file, or operable program”), but it’s the same missing PATH entry.
Find Where PHP Actually Is
Before you can add the folder to PATH you need to know where it is. PHP installed from a ZIP archive doesn’t register itself anywhere, so the folder is wherever you extracted it. The usual suspects:
- Manual ZIP install:
C:\php(or wherever you extracted it) - XAMPP:
C:\xampp\php - Laragon:
C:\laragon\bin\php\php-8.3.x(version in the folder name)
If none of those match, search for php.exe in File Explorer, or from PowerShell:
Get-ChildItem -Path C:\ -Filter php.exe -Recurse -ErrorAction SilentlyContinue | Select-Object -First 5 FullName
Note the folder that contains php.exe itself, for example C:\php. That exact folder, not its parent, is what goes on PATH.
Add PHP to PATH (Settings GUI)
- Press Start, type environment variables, and open Edit the system environment variables, then click Environment Variables.
- Under User variables, select Path and click Edit. (Use System variables › Path instead if every account on the machine needs PHP; that requires admin rights.)
- Click New and paste the folder, e.g.
C:\php. - Click OK on each dialog to save.
Add PHP to PATH from PowerShell
The same change, scriptable. This appends to your user PATH persistently:
$userPath = [Environment]::GetEnvironmentVariable('Path', 'User')
[Environment]::SetEnvironmentVariable('Path', "$userPath;C:\php", 'User')
Two traps to avoid here. Setting $env:Path only changes the current process and evaporates when the window closes. And skip the old setx command for this job entirely:
setx has a hard 1,024-character limit and crops anything longer; it does print a truncation warning, but by then the cropped value is already saved. Applied to an existing long Path value, it can permanently truncate entries you still need. Open a New Terminal and Verify
This is the step that costs people an hour: PATH is read when a terminal starts, so every window you already had open still has the old value. Close the terminal, open a new one, and check:
php -v
A working setup prints the PHP version and build information. To see exactly which executable Windows resolved (useful when more than one PHP is installed), run:
where.exe php
Using VS Code? Its integrated terminal doesn’t pick up environment changes until the application restarts; use Reload Window from the command palette (or fully restart VS Code) before testing there.
Composer: Same Error, Same Fix
“composer is not recognized” is the identical problem one tool over. If you used Composer-Setup.exe, the installer sets up PATH for you and even reminds you to test from a new terminal, so a stale window is the likely culprit. A manual composer.phar download, on the other hand, isn’t on PATH at all: either place it in a folder that already is, or run the installer instead. New to Composer on Windows? The full PHP and Composer install walkthrough covers the setup end to end.
Still Not Recognized?
- Stale terminal. The fix in nine cases out of ten: open a genuinely new window, and restart your IDE, not just its terminal tab.
- Wrong folder on PATH. The entry must be the folder holding
php.exe(C:\php), not a parent directory or the .zip you downloaded. - Two PHP installs fighting. Windows uses the first match it finds in PATH order.
where.exe phplists every match; the top one wins. - User vs system scope. If you added the entry under System variables but the error persists in your session, confirm it saved (admin prompt approved) and start a new terminal; user entries append after system ones.
Next Steps
With php -v answering in any terminal, the command line is yours. Next stop for most setups is configuration: find and edit the right php.ini to enable extensions. And if you’re building out the rest of a Windows dev toolchain, Node.js and npm follow exactly the same PATH rules you just learned.
Comments