Fix ‘Cannot Validate Since No PHP Executable Is Set’ in VS Code

Recently, I’ve started taking some PHP courses.

In the beginning, I’ve used Brackets, which is simple and beginner-friendly but doesn’t have the extra useful features that Visual Studio Code has.

Also, Brackets is used more for web design and front-end development.

Anyway, I installed VS Code, and the first thing I bumped into is this error:

Cannot validate since no PHP executable is set. Use the setting ‘.php.validate.executablePath’ to configure the PHP executable.

php validate error vs code

After some digging around, I’ve found the solution, and I’ll share it with you ladies and gentlemen because it’s pretty hard to find comprehensive guidance in their documentation or on forums.

VS Code is not for beginners, so they won’t spoon-feed anyone, unfortunately. 🙂

Fix the Validate PHP Error in Visual Studio Code

Note that I’m using Windows. If you’re on a Mac, the UI might be a little different.

Here’s what you need to do:

Step 1

You need to find out where your PHP executable (php.exe) is.

That depends on what kind of system you use (XAMPP, WAMP, MAMP, and so on).

I’m using XAMPP, which is installed on my C: drive, therefore the php.exe file is found in C:/xampp/php/php.exe.

Step 2

Once you’ve found out where your PHP executable is, open Visual Studio Code and go to File > Preferences > Settings.

visual studio code settings

Step 3

In the Search Settings bar, type settings.json.

Then, click on the Edit in settings.json link.

settings.json visual studio code

Step 4

Add a comma after the last line of code, whatever it might be, then add this:

"php.validate.executablePath": "C:/xampp/php/php.exe"
add php path in vs code

Of course, your path to the php.exe file can be different, as I mentioned at step 1, so make sure you replace C:/xampp/php/php.exe with your correct path.

Don’t add a comma after it if it will be the last line of code!

Note

Some people said that it only worked for them when they added two forward slashes for the path, like this:

C://xampp//php//php.exe

So, if you’re sure that you got the path right, but it still doesn’t work after you save the file and reopen VS Code, try adding two forward slashes.

Step 5

Save the file by going to File > Save or pressing CTRL+S (for Windows).

I think it’s CMD+S for macOS.

Final step

Close Visual Studio Code and open it again in order for the warning to go away.

If you don’t set the path to the PHP executable, Visual Studio Code will still work fine, but it won’t validate the PHP code, meaning that you won’t get curly red lines whenever you have an error in your code.

Related: VS Code Fix for “End of line character is invalid” PHPCS Error

That’s a Wrap

I hope you found this guide useful and you fixed the PHP validation error in Visual Studio Code!

If you have questions or thoughts, please leave a comment or send me a message using the contact page.

Don’t forget to share the post to help out others!

2 thoughts on “Fix ‘Cannot Validate Since No PHP Executable Is Set’ in VS Code”

  1. Thank you for sharing this information. It exactly solved my problem. I have to point out to regular users of the windows operating system that even though the path in windows is delineated by “\” between elements of the path, you must change this to “/” when editing the settings.json file since json uses web paths throughout.

    I attended a microsoft security conference several years ago where a presenter, apparently because of avoiding an infringement for the use of the word “slash” kept saying “whack” for the “/” as in www.microsoft.com “whack” secure “whack” files. I approached him after the presentation and asked: “So, how to you get the root of your system drive, “C colon backwhack”?

    • I’m glad to see that it solved your problem! “Whack” instead of “slash” sounds pretty funny :)). I might start using it along with “backwhack” :D.

Leave a Comment

Tweet
Share