How to set php executable path php.validate.executablePath in vscode when php is set inside docker container?

PhpValidationVisual Studio-CodeVscode Settings

Php Problem Overview


I have a development environment based in docker.

Everytime that I open VSCode I get this message:

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

Somebody know how to set php.validate.executablePath in this case?

I have no idea how to do it.

Php Solutions


Solution 1 - Php

Here is a screenshot.

  • Don't forget to escape \
  • You don't have to add it to the Path

set php.validate.executablePath snapshot

Solution 2 - Php

For linux users: if you don't have PHP installed then first download,
then in terminal type

$ whereis php

and it will show path for php executable (It will be either in /usr/bin/php or usr/local/bin/php) which you can copy from terminal.

In VScode goto settings.json file and paste

php.validate.executablePath: /usr/bin/php

Solution 3 - Php

In my case using XAMPP is like this

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

hope that answer your question

Solution 4 - Php

Sure, easy. Just follow what it's says.

Go to File> Preferences > Settings ... it will open the settings.json file.

add the following code:

{"php.validate.executablePath": "Here you put your PHP.exe path"}

You have to know where te PHP.exe file is in your computer, search in the php>bin folder.

Hope it works for you

Solution 5 - Php

I had the same problem but found the fix here.

In Windows:

  1. Go To System Properties
  2. Go To Advanced Tab
  3. Click "Environment Variables"
  4. Select Path
  5. Add a new path that points to your php 7 executable:

enter image description here

Solution 6 - Php

My case, I'm using Laragon, so you should search where is your php.exe.

By VSCode just add.

"php.executablePath": "C:\\laragon\\bin\\php\\php-7.2.19-Win32-VC15-x64\\php.exe"

on settings.json.

Solution 7 - Php

VSCode Linux Users:

Step 1: In your terminal type

whereis php

In my case "php: /opt/lampp/bin/php"

Step 2:

{
  "php.validate.executablePath": "/opt/lampp/bin/php"
}

Solution 8 - Php

I have ubuntu and XAMPP. The following worked for me.

Press CTRL + P Type settings.json and hit ENTER.

Add the following line in settings.json

{
...
"php.validate.executablePath": "/opt/lampp/bin/php",
...
}

Make sure to proper syntax.

Solution 9 - Php

Download PHP, in my case, I downloaded from here: http://windows.php.net/download/

Copy and paste the files to a location on your computer, and set the path:

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

Solution 10 - Php

"php.validate.executablePath": "C:/php/php.exe" wont work due to incorect escaping

try this;

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

Solution 11 - Php

If you get this on windows in VS code click on the blue 'open settings' button. Near the bottom of the screen this opens there's a link to enter the settings, click this to open the settings.json file. Edit the file to look like this:

{
    "php.executablePath" : "C:/php-7.4.2-nts-Win32-vc15-x64/php.exe",
    "php.validate.executablePath" : "C:/php-7.4.2-nts-Win32-vc15-x64/php.exe"
}

where C:/php-7.4.2-nts-Win32-vc15-x64 is the path to your PHP dir

Solution 12 - Php

I simply used double forward slashes and it worked, like so:

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

Solution 13 - Php

I don't know if this helps but 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. I'm new to PHP too, let me know if this is the correct way of solving this problem with PHP Intelephense.

Solution 14 - Php

If you're using VScode and have installed Php through MAMP, the default path should be:

C:/MAMP/bin/php/php7.4.1/php.exe

/ not \

Solution 15 - Php

Regarding the docker-specific revision of the question, I found this thread in the VS Code PHP Intellisense git repo issue that explains how to create a wrapper script. It will involve mapping volumes, though, so take that into account.

https://github.com/felixfbecker/vscode-php-intellisense/issues/150#issuecomment-330374124

Solution 16 - Php

I also had this error. I have installed Laragon and this addition in setting.json worked for me.

> "php.executablePath":"C:/laragon/bin/php/php-7.2.19-Win32-VC15-x64/php.exe"

Solution 17 - Php

IF using Laragon...Dont forget to change \ to /

  "php.executablePath": "C:/laragon/bin/php/php-7.4.5-Win32-vc15-x64/php.exe",

Solution 18 - Php

  • Go to 'Preference' -> 'Settings'
  • Search for> php path
  • Then click Edit in settings.json
  • Then just put your directory with (DOUBLE Backslash).

Here is an example of mine:

C:\\php\\php.exe

Here is the format:

drive:\\folder_name\\php.exe

This should fix the problem.

Solution 19 - Php

php.validate.executablePath in laragon

In my case using laragon is like this

  "php.validate.executablePath": "C:\\laragon\\bin\\php\\php-7.4.19-Win32-vc15-x64\\php.exe"
  • php-7.4.19-Win32-vc15-x64 : Note that this part of your file name may be different

Solution 20 - Php

Unix / Linux / Mac / WSL ,


Step 1 : Find PHP path

whereis php

Response will show you where your php directories are.

user@User:~$ whereis php

php: /usr/bin/php /usr/bin/php8.0 /usr/bin/php8.1 /usr/lib/php /etc/php /usr/share/php8.0-opcache 
/usr/share/php8.0-xml /usr/share/php8.1-curl /usr/share/php8.1-opcache /usr/share/php8.0-gd 
/usr/share/php7.0-gd /usr/share/php7.0-common /usr/share/php8.0-readline /usr/share/php8.0-mysql 
/usr/share/php8.0-zip /usr/share/php8.1-mbstring /usr/share/php8.1-xml /usr/share/php8.0-mbstring 
/usr/share/php8.0-common /usr/share/php8.0-curl /usr/share/php8.1-readline /usr/share/php8.1-common 
/usr/share/man/man1/php.1.gz

Step 2 : Configure VS-Code

Go to -> "Preference -> Settings"
Search for -> "php path"
Then click -> "Edit in settings.json"


In my case I had multiple.
So I chose the one I wanted from the available versions and my VS-Code looked like this


"php.validate.executablePath": "/usr/bin/php8.1",

Solution 21 - Php

I also got this error message. The path to php.exe was already set in my System Environment Variables.

The error went away when I commented out "php.validate.executablePath": "c:/path/to/php7.2.10/php.exe", in the settings.json file in VSCode.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNicolas TakashiView Question on Stackoverflow
Solution 1 - PhpMohamed ElrashidView Answer on Stackoverflow
Solution 2 - PhpYugandharView Answer on Stackoverflow
Solution 3 - PhpSETIA1View Answer on Stackoverflow
Solution 4 - PhpJulianView Answer on Stackoverflow
Solution 5 - PhprayView Answer on Stackoverflow
Solution 6 - PhpCaique AndradeView Answer on Stackoverflow
Solution 7 - PhpO'seun IyadiView Answer on Stackoverflow
Solution 8 - PhpwebfaticView Answer on Stackoverflow
Solution 9 - PhpNuuuView Answer on Stackoverflow
Solution 10 - PhpIan CroasdellView Answer on Stackoverflow
Solution 11 - PhpR MacView Answer on Stackoverflow
Solution 12 - PhpRalph AnthonyView Answer on Stackoverflow
Solution 13 - PhpBryan OrellanaView Answer on Stackoverflow
Solution 14 - PhpJulien NANQUETTEView Answer on Stackoverflow
Solution 15 - PhphaliphaxView Answer on Stackoverflow
Solution 16 - PhpMuhammad Ahmed RazaView Answer on Stackoverflow
Solution 17 - PhpsamjcoView Answer on Stackoverflow
Solution 18 - PhpZeus G.View Answer on Stackoverflow
Solution 19 - PhpHadi AbdollahiView Answer on Stackoverflow
Solution 20 - Php13garthView Answer on Stackoverflow
Solution 21 - PhpSebastian Mansfield-BarryView Answer on Stackoverflow