Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot validate the php file. #251

Closed
rudnev-dm opened this issue Nov 19, 2015 · 46 comments
Closed

Cannot validate the php file. #251

rudnev-dm opened this issue Nov 19, 2015 · 46 comments

Comments

@rudnev-dm
Copy link

I do not know how to fix this error - Cannot validate the php file. The php program was not found. Use the 'php.validate.executablePath' setting to configure the location of 'php'

@Morgy93
Copy link

Morgy93 commented Nov 19, 2015

Just read what it says: "Use the 'php.validate.executablePath' setting to configure the location of 'php'"
And maybe have a look at the release notes:

Language - PHP

VS Code is now using the official PHP linter (php -l) for PHP language diagnostics. VS Code will now stay current with PHP linter improvements.

There are two new settings to control the PHP linter:

  • php.validate.executablePath: points to the PHP executable on disk. Set this if the PHP executable is not on the system path.
  • php.validate.run: controls whether the validation is triggered on save (value: "onSave") or on type (value: "onType"). Default is on save.

@kc9eye
Copy link

kc9eye commented Nov 19, 2015

This is how I solved it on Windows 7:
download php from here: http://windows.php.net/download,
unzip to C: drive,
set "php.validate.executablePath" : "C:/{folder php unzipped to}/php.exe"

Mind the forward slashes.

@DerTolleEmil
Copy link

The php.validate.executablePath does not have to be set if php.exe is located in a directory which is listed in your %PATH% variable. If that's not the case you need to set it manually like mentioned above.

@rudnev-dm
Copy link
Author

kc9eye, DerTolleEmil - Thank you very much, you cool.

@ooKriangsaKoo
Copy link

kc9eye, Thank you

@ghost
Copy link

ghost commented Nov 26, 2015

@kc9eye is right, set "php.validate.executablePath" : "DiskName:/{folder php unzipped to}/php.exe", String 'php.exe' is required, but php7 is not required.

@animanoir
Copy link

is this important? Do I need to fix that issue to properly use PHP on Code? I'm just using it with XAMPP and it seems to work.

@DerTolleEmil
Copy link

You will not get any red squiggly lines if you have errors in your code if you do not have the php executable set. You will still get syntax highlight and autocomplete information but if you are missing say a semicolon the editor will not tell you so; You will only notice the error when you actually run the code.

I haven't used XAMPP in quite a while but if I remember correctly XAMPP has the php binary included, probably in C:\xampp\php\php.exe (if you have it installed there). Might also be C:\xampp\bin\php\php.exe or C:\xampp\bin\php\php-5.x.x\php.exe

I'm sure you'll be able to find it and it is highly recommended that you do set the value, it will make your life a lot easier if you get syntax errors highlighted when editing your files.

@animanoir
Copy link

Thanks. Just done it.

@boloindia
Copy link

Thanks File > Preferences > Workspace Settings and added in settings.json
"php.validate.executablePath":"C:/wamp/bin/php/php5.4.3/php.exe"

@kennethjfalbous
Copy link

And if you are using xampp, then follow the snippet shared by @boloindia above and just change the path too: "D:/xampp/php/php.exe"

This will work as I have done it the same way.

@Monax111
Copy link

I spent 20 minutes on this error)
I copied the way from explorer :
"D:\xampp\php\php.exe"
But the right way is:
"D:/xampp/php/php.exe"

@hudzax
Copy link

hudzax commented Mar 23, 2016

Thank you. I am using xampp, it works by overwrite the default setting of php.validate.executablePath with "D:/xampp/php/php.exe".

@hkmekala
Copy link

hkmekala commented Apr 14, 2016

Changing the to front slash works Fine

@bobdonkey
Copy link

On Linux use whereis in bash:
whereis php
This will then give you the path e.g. /opt/lampp/bin/php
Then put that in your settings.json:
"php.validate.executablePath":"/opt/lampp/bin/php"

@Marcif
Copy link

Marcif commented Apr 15, 2016

How configure php.validate.executablePath for docker container?

@SHarieprasadh
Copy link

It not getting saved. unable to edit preferences

@hkmekala
Copy link

What is the error you are getting

Run with Root it will work fine.

@SHarieprasadh
Copy link

I need to add php path for validation. I have to add path to C:\xampp\php\php.exe but its not getting edited in user settings under preferences

@fusionplanet
Copy link

@SHarieprasadh when you open the workspace setting file, VS opens an empty settings.json file. Add the following code as show below (change "C:/xampp/php/php.exe" to your php.exe location)

// Place your settings in this file to overwrite default and user settings.
{
    // Points to the php executable.
    "php.validate.executablePath": "C:/xampp/php/php.exe"
}

@doomtoo
Copy link

doomtoo commented Jan 6, 2017

Still doesn't work in the current version.

Tried both
"D:/xampp/php/php.exe"
"D:\xampp\php\php.exe"

and even downloaded the most recent version of php, and referred to that folder as well
"D:/php/php.exe"

but restarting, clicking on the php file, it still claims it can't find php. I can copy and paste it in my command line and it runs php: D:/php/php.exe, but visual studio code refuses to acknowledge it is there.

Changed it in both the settings file it pops up with the error, and File->Preferences-> workspace settings, but makes no difference- won't acknowledge it's there.

Even tried reinstalling Visual code, no change.

About an hour of that, and switching to Atom.

(After switching to atom, it told me that it wanted a newer version of php. I upgraded xampp to the last listed version/ newest, and Atom was fine. Reinstalled VS code, and VS code finally worked. So VS Code reports 'can't find php' when it really means 'the php version found is older than expected')

@sivasankars
Copy link

sivasankars commented Jan 15, 2017

For WampServer

PHP v7 :
C:/wamp64/bin/php/php7.0.10/php.exe

PHP v5.6 :
C:/wamp64/bin/php/php5.6.25/php.exe

Also refer @boloindia for settings

@ghost
Copy link

ghost commented Mar 2, 2017

@doomtoo having same issues on Windows 10 here. :( Tried everything, but it still won't work.

Currently I've set it to "php.validate.executablePath": "D:/Webserver/bin/php/php-7.0.9-x64/php.exe" but it still won't work.

Perhaps VSCode doesn't like the D: disk?

@CiprianHanga
Copy link

I have tried every combination and it still won't work with the php.validate.executablePath. It only works if you add the PHP folder path to your PATH.
This is rubbish.

@cretace
Copy link

cretace commented Apr 25, 2017

I get the same error - cannot get it to acknowledge PHP.
They should make some examples and STATE DEFINITIVELY if it is two slashes or one. There's contradictory comments above.

Addng both these seems to have fixed it:
"php.validate.executablePath": "C://xampp//php//php.exe",
"php.executablePath": "C://xampp//php//php.exe"

@habyphael
Copy link

This is an example with Wamp64

// Place your settings in this file to overwrite the default settings { "files.autoSave": "afterDelay", // Points to the PHP executable. "php.validate.executablePath": "C:/wamp64/bin/php/php7.0.0/php.exe" }

@SHarieprasadh
Copy link

Still not working for me and also for others
Can Any one make a video on you tube and share with us ?

@DerTolleEmil
Copy link

DerTolleEmil commented Apr 26, 2017

No offense but are you sure you should be tackling code if you don't even understand simple file paths and config files?

The syntax is:

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

"php.executablePath" (as mentioned earlier) does not exist (according to autocomplete) and does not have to be set. You can use either standard forward slashes as the path separator ("C:/php/php.exe") or double blackslashes ("C:\\php\\php.exe"), both are correct.

Here is a complete settings.json from my installation:

// Place your settings in this file to overwrite the default settings
{
	"files.autoSave": "off",
	//"files.autoSaveDelay": 1000,
	"editor.renderWhitespace": "all",
	"python.pythonPath": "c:/python27/python.exe",
	"python.linting.pep8Enabled": true,
	"python.linting.pylintEnabled": false,
	"editor.insertSpaces": false,
	//"editor.formatOnType": true,
	"editor.cursorBlinking": "phase",
	"editor.renderControlCharacters": true,
	"editor.renderIndentGuides": true,
	"editor.renderLineHighlight": "all",
	"editor.detectIndentation": false,
	"workbench.iconTheme": "vs-seti",
	"editor.minimap.enabled": true,
	"editor.cursorStyle": "line",
	"powershell.codeFormatting.openBraceOnSameLine": false,
	"php.validate.executablePath": "C:/php/php.exe"
}

If you have no idea where your php.exe file is, open a command prompt and paste the following code:

dir C:\ /S /A /B | find "php.exe"

Replace C:\ with D:\ or any other drive if you have PHP installed somewhere else. It will output lines like

C:\laragon\bin\php\php-5.6.27-Win32-VC11-x86\php.exe
C:\PHP\php.exe

if you have PHP installed multiple times you will get multiple results, pick the one you want and put it into your config file. Remember to either replace the backslashes with two backslashes or replace them with a forward slash.

@cretace
Copy link

cretace commented Apr 26, 2017

No offense?
If you're going to start your comment with a passive aggressive phrase then you know what you can do.

It didn't work for me without "php.executablePath": "C://xampp//php//php.exe"
.. and it only worked with double slashes.

@DerTolleEmil
Copy link

The no offense wasn't aimed at you. And I know that it sounds incredibly passive aggressive, which isn't my point (if it was I wouldn't have posted any other details). It's just that people are probably a few steps ahead of themselves when learning to code if they can't even get the editor running (although admittedly if I still was a beginner a json config file would throw me off quite a bit as well).

Anyway: Would you mind posting your entire config file? I just searched through the source code, there is not a single mention of any "php.executablePath" setting. The amount of additional forward slashes shouldn't matter either as they are ignored anyway. I'd like to see what happens on my installation using your config file. Do you know if you have the path of your PHP installation set in your PATH environment variable as well?

@grm3
Copy link

grm3 commented Apr 26, 2017

The only way I could get php linting to work properly was by doing exactly what creatace said -- set both php.validate.executablePath AND php.executablePath like below (on Win10, brand new machine).

"php.validate.enable": true, "php.validate.executablePath": "C:\\Users\\uname\\Desktop\\php7\\php.exe", "php.executablePath": "C:\\Users\\uname\\Desktop\\php7\\php.exe", "php.validate.run": "onType"

@cretace
Copy link

cretace commented Apr 26, 2017

Sadly I can't carry on with VS code until PHP support moves on - I need old style self-defined function hinting with 'go to' / show definition. Why do people think functions are dead and they only need to support classes etc. ?
I also need mixed PHP-HTML highlighting and completions
The search continues.

@doomtoo
Copy link

doomtoo commented Apr 26, 2017 via email

@cretace
Copy link

cretace commented Apr 26, 2017

Re. the PHP 7 requirement:
It seems that's due to the Felix Becker Intellisense plug in - the Crane Intellisense doesn't require 7

@dastani
Copy link

dastani commented May 2, 2017

hi,
open file setting.json
{
"php.validate.executablePath": "C:\xampp\php\php.exe",
"php.executablePath": "C:\php7.1\php.exe"
}
:)

@sudoforge
Copy link

sudoforge commented May 14, 2017

Some notes:

  • Be courteous to each other. Everyone learns at a different pace, and learning how to learn is indeed one of the greatest challenges in learning how to program (and use programming tools).

  • Double backward slashes are necessary on machines running Windows, because \ within a double-quoted string is an escape character. Because Windows paths use \ as a separator, you need to escape that value (or use single quotes). One thing to note, however, is that Windows will also correctly parse forward slashes, so a path like C:/my-dir/my-subdir/my-script.exe should work just fine. @DerTolleEmil explained this above.

@aldomolina
Copy link

aldomolina commented Jun 14, 2017

Hi, how can I solve this same problem, using bitnami lamp.
I'm in the fedora distribution 25. I've tried the following:

"php.validate.executablePath": "/home/myname/lampstack-7.1.4-0/php/bin",

Thanks.

@ousid
Copy link

ousid commented Jul 13, 2017

@bobdonkey
Thank You For Help

@ghost
Copy link

ghost commented Jul 18, 2017

Ubuntu 17.04 Xampp VS Code Settings "php.validate.executablePath": "/opt/lampp/bin/php",

@SHarieprasadh
Copy link

Still not working Can any one make a video and share us ?

@tsghosh
Copy link

tsghosh commented Jul 28, 2017

For Xamp ,

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

@enmcewan
Copy link

enmcewan commented Aug 13, 2017

On Windows 10, VS Code 1.14.2 with WAMPServer, the following settings worked for me. Note that you should search for the actual path to your local php.exe:

File > Preferences > Settings > search for php. Mouse over the settings then click edit.

"php.validate.executablePath": "C:\\wamp64\\bin\\php\\php7.0.10\\php.exe",
"php.validate.run": "onType"

"onType" gets you validation as you type. If you don't set that, it looks like validation is still not working. Not sure why the default would be onSave but once you see it's running OK you can set this however you like.

@Firegarden
Copy link

Firegarden commented Sep 24, 2017

On Windows the issue can be resolved by adding your php location to the Window System Environment variable known as the Path variable. This is a list of paths that are checked.

@tecnauta
Copy link

My configuration is below, and its working!! Windows 10 + Visual Studio Code 1.16.1 + xampp 7.0.23
No need to add php.exe to the PATH.
You can check de documantation here: https://code.visualstudio.com/docs/languages/php
{
"php.suggest.basic": false,
"php.executablePath": "C:/xampp/php/php.exe",
"php.validate.executablePath": "C:/xampp/php/php.exe"
}

@akaFlem
Copy link

akaFlem commented Sep 25, 2017

Hey !
In my case, php.exe file was empty ( c:/php/php.exe => 0ko ) ....
I think a conflict bug with multiples extensions for php ...
Just redownload the php package and works fine.
Sorry for my bad english.

WINDOWS 10 - VAGRANT

@TrieBr
Copy link

TrieBr commented Sep 28, 2017

No matter what I set php.validate.executablePath to, I could not get it working. Tried forward and backwards slashes as well as leaving out/including php.exe.

The only thing that worked for me was adding the php directory C:\php7 to the PATH variable in Windows.

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests