This post was last updated on 11/19/2019
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.
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:
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
For macOS or Linux users, the usual path is
Once you’ve found out where your PHP executable is, open Visual Studio Code and go to File > Preferences > Settings.
In the Search Settings bar, type settings.json.
Then, click on the Edit in settings.json link.
Add a comma after the last line of code, whatever it might be, then add this:
or this for macOS and Linux users:
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!
Save the file by going to File > Save or pressing CTRL+S (for Windows).
I think it’s CMD+S for macOS.
Close Visual Studio Code and open it again for the warning to go away.
Step 7 – For 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.
In the Advanced tab, click on Environment Variables…
Click on the Path row to select it, then click on Edit…
Edit or add a new PHP path (e.g. C:\XAMPP\php).
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
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:
For some people, it worked with backslashes (one or two):
Adding this in addition to the
php.validate.executablePath line might also fix it:
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!