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

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.

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 for Windows, macOS or Linux

Note that I’m a Windows (10, to be more specific) user, so I’m not familiar with Linux or macOS. Therefore, I might not be so accurate when it comes to those operating systems.

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 OS and development environment you use (XAMPP, WAMP, custom installation, and so on).

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

For macOS or Linux users, the usual path is /usr/bin/php.

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"

or this for macOS and Linux users:

"php.validate.executablePath": "/usr/bin/php"
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!

Step 5

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

I think it’s CMD+S for macOS.

Step 6

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

Step 7For Windows users

Make sure you have PHP added to your environment’s PATH. I think XAMPP adds it automatically but check anyway.

Search for “environment” on Windows.

edit system environment variables

In the Advanced tab, click on Environment Variables…

environment variables windows 10

Click on the Path row to select it, then click on Edit…

edit path windows

Edit or add a new PHP path (e.g. C:\XAMPP\php).

php path windows 10 environment

Don’t add the executable file (.exe) as you did in the .json file. Only add the directory.

If using a Virtual Machine on Windows

For example, for Laravel development, I’m using the Homestead environment on Windows 10, which is using Ubuntu as a server. It also comes with prepackaged software, such as PHP.

If I want to found out where PHP is on the server, I use the which php command, which will point out that PHP is found in /usr/bin/php.

which php ubuntu

Now, if I use that path in VS Code, it won’t work because it’s not on my disk. VS Code can’t look into my server.

So, if you’re running something similar for your dev environment, you’ll need to install PHP locally, on your disk, and then set the path as I showed you above.

I don’t know if there’s a workaround. If you do, let me know in the comments.

Other things to try if it doesn’t work

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

"php.validate.executablePath": "C://xampp//php//php.exe"

For some people, it worked with backslashes (one or two):

"php.validate.executablePath": "C:\xampp\php\php.exe"

Adding this in addition to the php.validate.executablePath line might also fix it:

"php.executablePath": "C:/xampp/php/php.exe"
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!

61 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 “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.

  2. Hi,
    Thanks for the information. I got the same error, but In my case Im connected to a Centors Linux server and I running my code directly from there. How can I fix it?
    Thanks again

    • Hello!

      Unfortunately, I don’t know first-hand how to do that, but you can create a .php file with this code <php phpinfo(); ?>, and then access it. You should find out some paths and useful info there that can help you spot where PHP is located.

  3. This post is still very useful, thanks a lot, others I checked did not work but this worked perfectly thanks once again

  4. I have recently started developing website & don’t have much experience. It would have taken long time for me to get the solution! You saved me 🙂
    Thank you so much! It was really helpful..

    • 🙁 Unfortunately, I have no other ideas other than the ones mentioned here. You might have an issue that’s specific to your setup.

  5. Thank you so much, Radu! I fix the problem.
    Very well explained.
    Regards from an argentinian living in Brazil.

  6. Hi, I am from Iran and thank you for your training in solving this problem. If I wrote a little badly, as you know, I am from Iran and it is not good for me to speak English.

  7. This is not really the right answer, because I have no php installed on my Linux Desktop and I’ll not install it just for editor. I do most of my coding remotely (remote server where the files are located).

    • Unfortunately, VS Code needs a path to PHP, and it can’t search inside your virtual machine/server. The PHP files on your server don’t have a path on your local disk as well, unless you use something like XAMPP which adds a PHP folder within its files when you install it.

  8. Hi.

    I have php installed on my system and it has been added to my path and I also added the executable path to my settings.json, but despite all that I still got the cannot validate error message. Then I installed xampp and added it to my path and then I manually added it to my settings.json but still the same error. I am at the point of tearing out my hair. Help me please.

  9. Here is what I had to enter in my json file.

    “C:/Program files/ampps/php-7.3/php.exe”

    It took me a long time to figure this one out…it was the default installation for ampps for Windows 7.

  10. “php.validate.executablePath”: “C:/laragon/bin/php/php-7.2.19-Win32-VC15-x64/php.exe”,

    it’s when im install my laragon quite confusing at 1st looking for php.exe. Sorry i accidently push post comment when im not done commenting lol

  11. Hi Radu, I had the same problem because I moved from Dreamweaver to Visual Studio Code.

    I have to validate PHP code from a remote server so I installed (unzip) “PHP 7.4.10 VC15 x64 Thread Safe” downloaded from just to have the php.exe file, but “php.validate.executablePath”: “C:/php/php.exe” in settings.json didn’t work, not until I installed Visual C++ Redistributable for Visual Studio 2015-2019, PHP web says “The VC15 and VS16 builds require to have the Visual C++ Redistributable for Visual Studio 2015-2019 x64 or x86 installed”. Well, this is just for others in the same situation with this kind of PHP installation.

    Windows 7 Ultimate SP1 64bits
    Visual Studio Code 1.48.2

    Sorry for my bad english.


Leave a Comment