Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

VS Code cannot validate PHP files because it cannot find the php program

ErrorCannot 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.

  • Applies to VS Code, PHP 8.3, Windows 11, macOS, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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        # Windows
  2. 2Match what you see, then jump to its fix

    1. 1which php or where php prints nothing.php is not on the system pathFix
    2. 2The setting is present, but the message stays after a reload.The setting points at a folder or at a wrong fileFix

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 -v

2Fix

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.php

Confirmed by code.visualstudio.com

Did this fix it?

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/php

2Fix

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.php

Confirmed by code.visualstudio.com

Did this fix it?

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

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 fix

Back 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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.