This is a fix for the following error when opening PHP files in VSCode or VSCodium:
Cannot validate since no PHP executable is set. Use the setting 'php.validate.executablePath' to configure the PHP executable.
This error means that VSCode does not know how to validate the contents of a PHP file and can’t show errors in the file if any. To fix this, open the settings.json file in VSCode, either by clicking on the error message or using Ctrl+Shift+P > Open settings.json. In this file, you need to add the following lines and replace
[pathToPHP] with the path in your system:
Code language: JSON / JSON with Comments (json)
"php.validate.executablePath":[pathToPHP] "php.executablePath": [pathToPHP]
To find php’s path, in your Linux Terminal run
Copy the path and paste it into
settings.json i.e., replace
[pathToPHP] in the above lines with the output of the
whereis command. There may be multiple results for the command. To pick the correct one:
- If you’ve installed PHP as part of XAMPP, the location of PHP will be in a subfolder of
- Otherwise PHP will be under the
/usr/binfolder, for example,
Restart VSCode and the error should be fixed.