52

I'm a beginner in PHP and want to use the VS Code editor. However, when I first save my php file I get this message:

Cannot validate the php file. The php program was not found. Use the 'php.validate.executablePath' setting to configure the location of 'php'

What is the problem?

miken32
  • 42,008
  • 16
  • 111
  • 154
  • I don't use VS Code (I don't even know how it looks like) but the error message seems pretty clear: find the `php.validate.executablePath` in the settings (file or window) of VS Code and set it with the location of your PHP interpreter. – axiac Jan 02 '16 at 17:17

16 Answers16

77

First, go to File->Preferences->User settings, A window will come like below image.

enter image description here

Now change the setting.json file like below image and save:

enter image description here

If PHP is not installed in your system, download php from here: windows.php.net/download, unzip to C: drive, set "php.validate.executablePath": "C://path.to.your.php.folder//php.exe"

If php is installed in your system simply set the path of your php.exe file like below:

"php.validate.executablePath": "C://path.to.your.php.folder//php.exe"

hint: In my case I use XAMPP which is installed in the D: drive, so my setting is below

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

Mind the double forward slashes.

Marc.2377
  • 7,807
  • 7
  • 51
  • 95
Ari4
  • 860
  • 7
  • 12
15

picture of error

How you can fix this:

If you have installed xampp for making a localhost database this is for if your new to php and are getting the error in the picture and this is how to fix it. I am using visual studio code.

How to get rid of error:

1) Get to settings:

Method 1:

  • Click the button that says settings on the error (bottom right corner of the error)

image of where to click method 1

Method 2:

  • Click the shortcut for settings (ctrl + ,) ( if doesn't work resort to method 3 or 4 )

Method 3:

file > preferences > settings

Method 4:


Now you should be in settings and it should look like this:

image of what you should see on settings if you did any other method than 1

UNLESS you did method 1 in how to get to settings, And you clicked on the button that said settings on the error message, I cannot include anymore pictures, read carefully.

2) Get to JSON file to resolve error:

Method 1:

  • Click the underlined text that says edit in settings.json (it should be right in front of you nearly in the centre of the screen)

Method 2:

  • Click the {} or paper with the arrow suggesting turning over the paper, When hovering over it, it will say open settings (JSON) (you will find it under the minimize screen button in the top right corner of the screen)

enter image description here

3) Enter this code:

Method 1:

You should be using xampp because this tutorial is for that specific control panel.

Inside the main JSON brackets ({})

Add this to the end:

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

Method 2:

  • If using a different drive simply change the C: to whatever drive it is e.g. D:

  • If still getting the error change the path so it works for you, you want to locate the php.exe or just PHP and the file class will be "application",

Then route the exe to the PHP using the path you took to locate the php.exe "application"

Remember you start at your drive so it should always start with C: (the drive you saved the xampp in)

4) Now save and close Visual Studio Code and re-open it


I hoped this helped if not I am sorry but this worked for me after looking around for a bit.

lejlun
  • 4,140
  • 2
  • 15
  • 31
x10djkid
  • 151
  • 1
  • 2
9

I solved it by adding lines

"php.executablePath": "C:/wamp64/bin/php/php7.1.9/php.exe",
"php.validate.executablePath": "C:/wamp64/bin/php/php7.1.9/php.exe"
akinuri
  • 10,690
  • 10
  • 65
  • 102
Nidhin
  • 166
  • 3
  • 8
7

For Mac users with MAMP

"php.validate.executablePath": "/Applications/MAMP/bin/php/php7.4.16/bin/php"

Change php7.4.16 to your PHP version of choice.

Mohamed Surour
  • 125
  • 2
  • 6
3

Perhaps it is a syntaxis issue. After many tries I found that the command had to be written

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

(with 2 backslashes). I noticed that many answers said that a normal slash (/) or just one back slash worked as well. I have the Visual Studio Code version 1.17.0-insider x64.

The solution worked independently of the location of the executable file. Which in my case was located in C:\xampp\php\php.exe and ‪C:\Program Files\PHP\v7.1\php.exe.

eliasmaxil
  • 530
  • 4
  • 13
3

this is work for me.

if you have installed php, please add path of installation php on path windows enviroment variable.

if you not install php yet, please follow this step:

  1. Install php and copy path installation. ex : C:\XAMPP\php
  2. go to System > Advanced System setting > Enviroment Variable > User Variable > Path > Edit > New > paste the path

restart vscode

Sigit
  • 728
  • 7
  • 12
3

First, go to File->Preferences->settings->User settings tab->extensions->from the drop down select php->on the right pane under PHP › Validate: Executable Path select edit in settings.json.

Then set the path as your case may be e.g for a xamp user who installed xammp on c drive you will have:

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

If php is installed in your system independently or by other means simply set the path of your php.exe file like below:

"php.validate.executablePath": "C://path.to.your.php.folder//php.exe"

Marcel
  • 139
  • 2
  • 6
2

there is a fast way for fixing this, just

  1. Search in Cortana : web
  2. Open Microsoft Web Platform Installer
  3. Search in Microsoft Web for "php"
  4. install one of php versions like php 7.0.5 or php 5.6
  5. if your install be successful, now your system have php and you won't see php error in visual code.
user3617558
  • 45
  • 1
  • 5
1

VS Code is looking to validate your code using php, and it is not finding php installed on your system.

If you install php to your path (That is to say, in a command prompt window you can type "php" in any folder and something will happen), everything should work.

Otherwise, you can do one of two things:

  1. Set the "php.validate.executablePath" setting in VS Code to point to the php executable on your system, wherever it may be.

OR

  1. Ignore the error, but you won't get proper error detection as you code.

For more information, see this: https://code.visualstudio.com/Updates#_language-php

Tobiah Zarlez
  • 1,680
  • 1
  • 12
  • 13
1

I was in the same situation. I'm using PHP through a docker (using Visual Studio Code). I didn't want to install PHP on my PC.

The solution that worked for me was to download a portable server that executes PHP (www.uwamp.com). You will download it as a zip file (no installation or configuration needed) and save it somewhere on your PC.

Follow these steps:

  • download zip file from: https://www.uwamp.com/file/UwAmp.zip
  • unzip and save to any folder on your PC like: C:\Data\UwAmp
  • get the url to the php.exe file inside UwAmp > C:\Data\UwAmp\bin\php\php-7.0.3\php.exe
  • open Visual Studio Code and go to: File > Preferences > Settings > Open Settings (JSON) (you will have to click the icon at the top right corner)
    List item
  • Add following reference to the bottom of the settings.json file:
    "php.validate.executablePath": "C:\Data\UwAmp\bin\php\php-7.0.3\php.exe"
  • save (you may possibly have to restart Visual Studio Code)

This is not the exact solution you (and myself) was aiming for, but no PHP was installed and configured on the PC and it's easy to clean up (just delete the UwAmp folder and remove the line at settings.json) when done.

Mohammad
  • 1,498
  • 2
  • 12
  • 15
1

I ran into the same problem with the extension PHP Intelephense in Visual Studio Code. What I did is read the instructions so the extension could work properly. So I disabled PHP Language Features by searching "@builtin PHP" in the extensions. Also, other (3rd party) PHP extensions that provide similar functionality should also be disabled for best results. Finally, I added glob patterns for non-standard PHP file extensions to the files.associations setting. For example: "files.associations": { "*.module": "PHP" }

Doing this made the error go away because I installed the PHP Intelephense extension. I'm new to PHP too, let me know if this is the correct way of solving this problem with PHP Intelephense.

0

Also, that only works if you open a folder in VS Code, you can't set it up to view a single file. Since VC creates a ".vscode" folder with a settins.json inside of it when you edit Preferences > Workspaces. This is where you could specify the php.validate.executablePath.

So keep that in mind, if you just open a single file, you can't use that functionality but it will still show the warning. Instead open the folder the file is in.

If you want to never have to worry about it, then modify your %path% environment variable to include the folder that php.exe is in.

Mastro
  • 1,477
  • 2
  • 22
  • 52
0

Apart from the answers above, for a Linux based system, do this-

In VSCode, Go to Files -> Preferences -> Settings
In User section, click Edit in settings.json
Add this code to the JSON file-

"php.validate.executablePath": "/opt/lampp/bin/php"
0

On VS Code

1° Go to File -> Preferences -> Settings -> Find "php.executablePath"

2° Open "PHP:Executable Path" [2° image]: https://i.stack.imgur.com/UDTud.png

3° On file "settings.json" add "php.executablePath": "pathtophp\php\php.exe",. And save all. [3° image]: https://i.stack.imgur.com/drWDL.png

4° On Windows 11 go to -> This PC -> Properties -> Advanced system settings [4° image]: https://i.stack.imgur.com/dZ0xi.png

On System Properties Windows 5° Advanced Options -> Environment Variables -> Add to Path Variable 'pathtophp\xampp\php'

6° Save all and restart VS Code.

G3TZO
  • 1
  • 2
0

This is in addition to the answer by @Ari4 - a separate answer because comments cannot include images. This may help some people who can't get the syntax right especially if there already an entry in the JSON file. Mine had two previous entries which can be confusing (yes, I spent a half hour figuring it out). First, here's what not to do:

enter image description here

which you might do (as I did) if you copy-paste or follow instructions verbatim. Also this and other such combinations are wrong:

enter image description here

The right way to do this is: enter image description here

Notice the "," at the end of the previous setting.

Chiwda
  • 1,233
  • 7
  • 30
  • 52
-1

For Debian-based os (like Ubuntu, Zorin OS, Linux Mint, Elementary OS, etc) users, use the "php.validate.executablePath": "/usr/bin/php".

To find the path of your PHP, execute which php command in the terminal.

More detail at - https://www.youtube.com/watch?v=VOfxRxTMPXQ

Shah Alom
  • 1,031
  • 1
  • 14
  • 26
  • That does not configure it: Cannot validate since /usr/bin/php is not a valid php executable. Use the setting 'php.validate.executablePath' to configure the PHP executable. – Yannick Mussche Apr 27 '23 at 08:02
  • @YannickMussche: Are you using vscode inside a container (i.e. flatpak)? If so: vscode can not access binaries on your host (easily). For more details check the issues in the github repo, for example https://github.com/flathub/com.visualstudio.code.oss/issues/22#issuecomment-485236774 – Felix Schwarz Jun 07 '23 at 14:34
  • with me it appeared to be an issue related to the visual studio code of the ubuntu software center. Downloading it straight from the commandline solved the issue – Yannick Mussche Jun 16 '23 at 13:50