VS Code cannot validate PHP files because it cannot find the php program
Cannot validate the php file. The php program was not found.Short answer
VS Code validates PHP files by running the php program. If php is not on your system path, it cannot find it. Set php.validate.executablePath in settings.json to the full path of the PHP executable, using forward slashes on Windows. Make sure the path ends at the php binary, not at its folder.
Fix it fast
1Find out which cause you have
Ask your shell where php is. If it prints nothing, the editor cannot find it either.
which php # macOS and Linux where php # Windows2Match what you see, then jump to its fix
What does the error look like?
Cannot validate the php file. The php program was not found.PHP syntax errors are not underlined when you save a file
Cause 1 of 2
php is not on the system path
1Check
The VS Code docs say to set php.validate.executablePath when PHP is not on the system path.
php -v2Fix
Open settings.json and point the setting at the PHP executable.
// Windows
{ "php.validate.executablePath": "c:/php/php.exe" }
// Linux or macOS
{ "php.validate.executablePath": "/usr/bin/php" }3Verify
Reload the window and open a PHP file. The message is gone and errors show on save.
php -l index.phpConfirmed by code.visualstudio.com
Cause 2 of 2
The setting points at a folder or at a wrong file
1Check
The setting must point to the PHP executable on disk. Compare it with the path that which php or where php prints.
which php
ls -l /usr/bin/php2Fix
Replace the value with the exact executable path from the command above. On Windows use forward slashes, as in the docs example.
{ "php.validate.executablePath": "/usr/local/bin/php" }3Verify
Save a PHP file with a deliberate syntax error. VS Code underlines it.
php -l broken.phpConfirmed by code.visualstudio.com
How do I stop it coming back?
- Add the PHP folder to the system PATH when you install PHP, then restart VS Code.
- Set php.validate.executablePath in user settings once, not per project.
- After switching PHP versions with a version manager, update the path.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Apache returns 503 or 504 because PHP-FPM did not answer in time
Error dispatching request
Apache sent the request to PHP-FPM and gave up waiting.
3 causes, each with a fixBack end
AWS SDK for PHP cannot get credentials from the instance profile metadata server
Error retrieving credentials from the instance profile metadata server.
The SDK tries the EC2 instance metadata service when it has no valid credentials from anywhere earlier in its chain.
4 causes, each with a fixBack end
AWS SDK for PHP rejects requests: the signature is from the future
Signature not yet current: {date} is still later than {date}
AWS compares the timestamp in your signed request with its own clock.
2 causes, each with a fixBack end
CodeIgniter 4 cannot write its cache files
CodeIgniter\Cache\Exceptions\CacheException: Cache unable to write to /var/www/app/writable/cache/
CodeIgniter 4's file cache needs a cache directory that the web server can really write to.
2 causes, each with a fixBack end
CodeIgniter 3 loads the model but the property is undefined
The model name you are loading is the name of a resource that is already being used: user
CodeIgniter 3 expects a model file named like its class, with the first letter capitalised, for example User_model.php holding class User_model.
2 causes, each with a fixBack end
CodeIgniter 3 stops with "Your system folder path does not appear to be set correctly"
503 Service Unavailable
CodeIgniter 3's front controller resolves $system_path and then checks that the result is a directory.
3 causes, each with a fix