132

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.

7

27 Answers 27

66

Here is a screenshot.

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

set php.validate.executablePath snapshot

Sign up to request clarification or add additional context in comments.

3 Comments

@Elrashid sorry am late. Question is How to set php executable path php.validate.executablePath in vscode when php is set inside docker container? My understanding is that docker runs containerized applications (like guest/virtual machine but with less resources. Readmore hub.docker.com ). Therefore it means you docker php environment (this can be Ubuntu) is different from your local desktop where vscode is installed (this can be windows). How to you get path to php.validate.executablePath of a guest/containerized OS from your local/development machine where vscode is installed???
Why is this being upvoted? It doesn't even attempt to answer the original question.
This does not answer the question, which is how to use PHP inside of a Docker container, not inside of windows!
38

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

2 Comments

Like other answers mention: don't forget to escape the slashes in path!
This does not answer the question.
35

In my case using XAMPP is like this

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

3 Comments

on windows 10 it's got to be in yout path vars also. search for environment variables in the start menu and add it to the path. just the dir, not the exe. eg.: C:\php
Thank you very much for this. Also depending on your installation you might have an additional folder between xampp and php.
XAMPP is not docker. While this answer is clearly useful to some, it does not answer the question.
14

Just follow what it 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.

1 Comment

But the PHP are inside a Docker Container not is my local machine
9

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

Comments

8

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.

1 Comment

Still doesn't work.
4

I've used such solution:

First, create a php file inside /usr/local/bin/ and make it executable:

sudo touch /usr/local/bin/php
sudo chmod +x /usr/local/bin/php

Update content of it with:

docker exec $(docker ps --filter name=-app --format '{{.ID}}') php "$@"

So this will find a container with the name -app at the end. I'm using it along with the docker compose where I have php inside some container which has -app at the end of the name. You can check more about filter here.

And then update php.validate.executablePath with /usr/local/bin/php:

{
    "php.validate.executablePath": "/usr/local/bin/php"
}

1 Comment

Sounds like this is heading in the right direction but I get an error: spawn Unknown system error -8
3

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"
}

Comments

3

Following on from @Scofield's solution for docker, here is a solution for ddev (assuming linux/macOS/WSL):

First, as before create an executable file

sudo touch /usr/local/bin/php
sudo chmod +x /usr/local/bin/php

Second, modify the contents of that file, inserting the following and save:

#!/bin/bash

ddev php $@

Third, add a reference to this newly created file to your settings.json as follows:

"php.validate.executablePath": "/usr/local/bin/php",

This key may already exist with an empty value, in which case, update it to match the above.

When complete the built-in PHP validation and debugging within VS Code should be possible without errors.

(Presumably in Windows the file path will have to be in the C:\\... format with double back slashes, but the concept should be the same)

3 Comments

After doing this, Xdebug stopped working. I had to revert these changes so I could step-debug my script...
Which OS are you using?
Windows 11 Pro Version 24H2
2

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",

Comments

1

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"

1 Comment

op specifically asked when the php runtime is inside a docker container, not how to install php in host machine and use it in vscode.
1

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

try this;

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

Comments

1

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

Comments

1

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.

Comments

1

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 \

Comments

1

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.

Comments

1

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

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

Comments

1

I am using Laragon and have 2 PHP versions PHP 7.4 and 8.1, so I configured my visual studio settings.json like this:

"php.validate.executablePath": [
    "D:/laragon/bin/php/php-7.4.33-Win32-vc15-x64/php.exe",
    "D:/laragon/bin/php/php-8.1.10-Win32-vs16-x64/php.exe"
],

Comments

0
  • 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.

Comments

0

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

Comments

0

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"

Comments

0

"php.validate.executablePath": "C:\xamp\php\php.exe" this is working for this case

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
0

For Wampserver:

Inside settings.json

"php.validate.executablePath": "C:/wamp64/bin/php/php7.4.26/php.exe"

Comments

0

I have tried all the suggestions, but for me, I needed to add the path of the php.exe and php.ini file to the settings of fiveserver: see attached

Basically, open settings in vs code, then go to extensions > Five Server and then look for PHP:Executable and PHP:Ini Add the path of your php.exe and php.ini (they are in the same folder), and it should be good to go.

Comments

-1

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

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

Comments

-1
  1. Go to settings.json file in Visual Studio Code.
  2. Copy this code into your json file:
"php.executables": {
    "v8.1": "C:\\xampp\\php"
 }
  1. Now save it...

Please remember that, the "v8.1" is the version of the php compiler.

Comments

-3

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.