Nifal Nizar
Nifal Nizar

Reputation: 963

PHP executable not found. Install PHP 7 and add it to your PATH or set the php.executablePath setting

I'm running windows 10 fresh copy and I just installed visual studio code. I was trying to develop a PHP project using VS Code. But I'm having trouble in setting up the environment.

I saw a blog post and I downloaded the binary file of PHP 7 and place it in the "C" drive. Then I set path variable too.

But still, I'm getting this issue.

enter image description here

Upvotes: 63

Views: 276786

Answers (14)

louisik1
louisik1

Reputation: 161

Well I'll throw my variation in. The error VS Code was showing says

'php' binary could not be either found or executed. Make sure PHP is installed, and add path to "php.executables" setting.

I misunderstood the place to add the settings and had it like this:

"php.executables": {    
    "php.executablePath": "/Program Files/PHP/php.exe",
    "php.validate.executablePath": "/Program Files/PHP/php.exe",
    "v8.3": "/Program Files/PHP/php.exe"
},

I looked at the other answers here and other places and realized I might have overthunk it. I changed it to

"php.executablePath": "/Program Files/PHP/php.exe",
"php.validate.executablePath": "/Program Files/PHP/php.exe",
"php.executables": {    
    "v8.3": "/Program Files/PHP/php.exe"
},

And then it started working. Hope this helps someone!

Upvotes: 0

Christopher S.
Christopher S.

Reputation: 91

macOS users

Extending pableiros's answer here's bit more in-depth explanation for macOS beginner users.

For macOS users who do not have homebrew installed install with homebrew's installation instructions then follow along below.

For macOS users who do not have homebrew's php formulae installed follow pableiros's answer or brew's command here then follow along below.

For macOS users that now have or had brew's php formulae already installed and the notification error persists, open terminal app find your brew install executable application path: by running terminal command which php:

returns

/opt/homebrew/bin/php

Now add that path to your json settings

{
    "php.executablePath": "/opt/homebrew/bin/php"
}

Upvotes: 0

mhermano
mhermano

Reputation: 99

Update (for xampp):

This one worked for me at settings.json add this code:

{
"php.validate.executablePath": "C:\\xampp\\php\\php.exe",
 // "php.executablePath": "C:\\xampp\\php\\php.exe",
 "phpserver.phpPath": "C:\\xampp\\php\\php.exe",
}

doesn't really need the executablePath as other's have mentioned so I omitted it and I added the phpserver.phpPath

Upvotes: 0

Lucifer
Lucifer

Reputation: 147

Well , Everyone has added their answer but I will add one more thing that the chosen answer didn't update.
You can add multiple php executables now ( if code runner extension installed )
A similar issue was pointed out in vscode's github repo #128098 and in #131534 and it was addressed after

VS Code version: 1.59.1 [3866c35]
Release Date : 19th August 2021 or 2021-08-19T11:57:20.140Z

Anyway, so you can now :

  • add your multiple versions/installations of php by clicking on the bottom status bar of vscode, specifically on the version of php you are running ( in this example it is 7.4.3)
    bottom bar of vscode

  • or by editing the code runner extension settings in settings.json(both point to the same file)

settings.json File path in windows and samplecontents:
C:\Users\{Your Name}\AppData\Roaming\Code\User\settings.json

"[html]": {
        "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "vsicons.dontShowNewVersionMessage": true,
    "debug.onTaskErrors": "showErrors",
    "redhat.telemetry.enabled": false,
    "[cpp]": {
        "editor.wordBasedSuggestions": true,
        "editor.suggest.insertMode": "replace",
        "editor.semanticHighlighting.enabled": true
    },
    "security.workspace.trust.untrustedFiles": "open",
    "totalTypeScript.hideAllTips": false,
    "totalTypeScript.hideBasicTips": false,
    "files.associations": {
        "*.inc": "php"
    },
    "php.executables": {
        "7.4.3":"C:\\xampp\\php\\php.exe",
        "8.1":"C:\\xampp\\php8\\php.exe"
    }
}

Just add

    "php.executables": {
            "7.4.3":"C:\\xampp\\php\\php.exe"
        }

Or

"php.executables": {
            "7.4.3":"C:\\xampp\\php\\php.exe",
            "8.1":"C:\\xampp\\php8\\php.exe"
        }

at the bottom of your settings.json file in vs code

Upvotes: 0

noseve
noseve

Reputation: 11

in 2022, I had the same issue - my solution was to set the php.executablePath and php.validate.executablePath to use the folder only (with a trailing slash), omitting the actual executable 'php.exe'.

Upvotes: 0

pableiros
pableiros

Reputation: 16090

If you are using macOS, you need to install php. You can install it via brew executing the following commands on the terminal:

brew tap homebrew/core

brew install php

After that, you can open VS Code and the error will disappear

Upvotes: 4

Bartek
Bartek

Reputation: 1310

On Ubuntu 20.04 the path to executable php is

List all available paths: $ whereis php

One of the paths is: /usr/bin/php

More details on where to add this path: https://code.visualstudio.com/docs/languages/php

Upvotes: 3

Competo
Competo

Reputation: 143

For me this setting was working.
In my windows 8.1 the path for php7 is

C:\user\test\tools\php7\php.exe

settings.json

 {  
 "php.executablePath":"/user/test/tools/php7/php.exe",
 "php.validate.executablePath": "/user/test/tools/php7/php.exe"
 }

see also https://github.com/microsoft/vscode/issues/533

Upvotes: 0

Sahin Erbay
Sahin Erbay

Reputation: 1014

For those who are using xampp:

File -> Preferences -> Settings

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

Upvotes: 51

Kusal Kithmal
Kusal Kithmal

Reputation: 1313

Try this !!!. This will solve your problem for sure!

Method 1 -

Step 1 - Go to 'Environmental Variables'.

Step 2 - Find PATH variable and add the path to your PHP folder.

Step 3 - For 'XAMPP' users put 'C:\xampp\php' and 'WAMP' users put 'C:\wamp64\bin\php\php7.1.9' ) and save.

Method 2-

In VS Code

File -> Preferences -> Settings.

enter image description here

Open 'settings.json' file and put the below codes.

If you are using WAMP put this code and Save.

  "php.validate.executablePath": "C:\\wamp64\\bin\\php\\php7.1.9\\php.exe",
  "php.executablePath": "C:\\wamp64\\bin\\php\\php7.1.9\\php.exe"

If you are using XAMPP put this code and Save.

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

Note - Replace php7.1.9 with your PHP version.

Upvotes: 4

Radosław Andraszyk
Radosław Andraszyk

Reputation: 460

For me it was important to delete the "php.executablePath" path from the VS code settings and leave only the path to PHP in the Path variable.

When I had the Path variable together with php.executablePath, an irritating error still occurred (despite the fact that the path to php was correct).

Upvotes: 2

ops
ops

Reputation: 2049

You installed PHP IntelliSense extension, and this error because of it.
So if you want to fix this problem go to this menu:
File -> Preferences -> Settings
Now you can see 2 window. In the right window add below codes:

{
    "php.validate.executablePath": "C:\\wamp64\\bin\\php\\php7.0.4\\php.exe",
    "php.executablePath": "C:\\wamp64\\bin\\php\\php7.0.4\\php.exe"
}

Just like below image.

enter image description here

NOTICE: This address C:\\wamp64\\bin\\php\\php7.0.4\\php.exe is my php7.exe file address. Replace this address with own php7.exe.

Upvotes: 99

Arosha De Silva
Arosha De Silva

Reputation: 597

This one also works

  1. Remove the "php.executablePath" line from the VS code settings.

  2. Then add the xampp php path to the System variables

enter image description here

enter image description here

After that restart the Visual Studio Code

Upvotes: 13

rcperso
rcperso

Reputation: 500

After adding php directory in User Settings,

{
    "php.validate.executablePath": "C:/phpdirectory/php7.1.8/php.exe",
    "php.executablePath": "C:/phpdirectory/php7.1.8/php.exe"
}

If you still have this error, please verify you have installed :

To test if you PHP exe is ok, open cmd.exe :

c:/prog/php-7.1.8-Win32-VC14-x64/php.exe --version

If PHP fails, a message will be prompted with the error (missing dll for example).

Upvotes: 6

Related Questions