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

Is it possible to use wsl bash php for php.validate.executablePath #22391

Closed
g0ld3lux opened this issue Mar 10, 2017 · 28 comments
Closed

Is it possible to use wsl bash php for php.validate.executablePath #22391

g0ld3lux opened this issue Mar 10, 2017 · 28 comments
Assignees
Labels
feature-request Request for new features or functionality on-testplan php PHP support issues WSL Issue when using WSL
Milestone

Comments

@g0ld3lux
Copy link

Can Someone Clarify to me if i can use my php in WSL ?

@ramya-rao-a ramya-rao-a assigned mousetraps and dbaeumer and unassigned mousetraps Mar 10, 2017
@dbaeumer dbaeumer added php PHP support issues *question Issue represents a question, should be posted to StackOverflow (VS Code) labels Mar 13, 2017
@dbaeumer
Copy link
Member

In principal yes. However you need to use the c:\windows\sysnative\bash.exe as the php.validate.executablePath and then use the php executable as a command line argument to bash. You might also want to consider passing -c so that the shell exists when the php executable has finished.

@codeguy
Copy link

codeguy commented Apr 26, 2017

Following up on this since I cannot get it to work here using Windows Creators Update, WSL enabled, with latest VSCode. I have set php.validate.executablePath to C:\\Windows\\sysnative\\bash.exe, to C:\\Windows\\sysnative\\bash.exe -c, to C:\\Windows\\sysnative\\bash.exe -c php, and it does not work in VSCode. It either does not recognize the executable path, or it simply does not work. Do you have any further thoughts on this? I'd love to integrate VSCode with WSL php, but there seems to be a translation issue when VSCode tries to find binaries or tries to supply Windows C:\ style file paths into WSL.

@codeguy
Copy link

codeguy commented Apr 26, 2017

I also tried using C:\\Users\\josh\\bin\\RunInBash.exe php, and that did not work. See:

https://neosmart.net/blog/2017/meet-your-new-best-friend-for-wsl/

@dbaeumer
Copy link
Member

@codeguy you are right. It doesn't work. I forgot to consider that we besides the pure executable pass additional command line arguments to the executable. These arguments make the bash start fail. To fix this we need to add an additional property to the configuration to request validation in a shell. Something like php.validate.inShell: Boolean | { executable: string; shellArgs: string[] }

@dbaeumer dbaeumer reopened this Apr 27, 2017
@dbaeumer dbaeumer added feature-request Request for new features or functionality help wanted Issues identified as good community contribution opportunities and removed *question Issue represents a question, should be posted to StackOverflow (VS Code) labels Apr 27, 2017
@dbaeumer
Copy link
Member

@codeguy would you be willing to work on a PR for this. The code is here: https://github.com/Microsoft/vscode/blob/master/extensions/php/src/features/validationProvider.ts#L248

@codeguy
Copy link

codeguy commented Apr 27, 2017

For sure! I'll fork and work on it later today.

@codeguy
Copy link

codeguy commented Apr 27, 2017

See #25576

@dbaeumer
Copy link
Member

@codeguy Great. Will look at the PR.

@kieferrm kieferrm assigned roblourens and unassigned mousetraps May 1, 2017
@tooy
Copy link

tooy commented Jun 23, 2017

This is possible with an old school .bat :
php.bat

@echo off
c:\windows\sysnative\bash.exe -c "php %*"

setting.json
"php.validate.executablePath": "c:\\PATH_TO\\php.bat"

@GioBonvi
Copy link

While I am happy to see that this problem is being addressed I managed to put together two workaround scripts as I could not get any of the scripts found online to work (like the one posted by @tooy).

This one is called php.bat and is placed in C:\wsl-tools\:

@echo OFF
setlocal ENABLEDELAYEDEXPANSION

rem Collect the arguments and replace:
rem  '\' with '/'
rem  'c:' with 'mnt/c'
rem  '"' with '\"'
set v_params=%*
set v_params=%v_params:\=/%
set v_params=%v_params:C:=/mnt/c%
set v_params=%v_params%
set v_params=%v_params:"=\"%

rem Call the windows-php inside WSL.
rem windows-php is just a script which passes the arguments onto
rem the original php executable and converts its output from UNIX
rem syntax to Windows syntax.
C:\Windows\sysnative\bash.exe -l -c "windows-php %v_params%"

This one is called windows-php and is placed somewhere in the WSL path (i chose /usr/local/bin).

# Pass all the arguments to PHP.
output=$(php "$@")
# Perform UNIX->WINDOWS syntax replacements.
output="${output//$'\n'/$'\r'$'\n'}"
output="${output//\/mnt\/c/C:}"
output="${output//\//\\}"
# Echo corrected output.
echo $output

Setting "php.validate.executablePath": "c:\\wsl-tools\\php.bat" works for me.

@weinand weinand added the WSL Issue when using WSL label Aug 16, 2017
@roblourens
Copy link
Member

@dbaeumer Is this still needed? Did you look at the PR?

@dbaeumer
Copy link
Member

@roblourens that slipped through the cracks. I will look at the PR but in general we should look into a more generic solution to WSL than this.

And what is about the PHP language server. Does that report errors and might make the start of the php executable obsolete ?

@roblourens
Copy link
Member

I don't believe any of the PHP intellisense extensions have done any work in particular to support WSL.

If this is hard to land, I won't push for it. I'd rather see the extensions implement it, but I don't see anyone filing issues on them for it.

@erdemece
Copy link

Any news about this? Thanks.

@dbaeumer
Copy link
Member

No news yet on this particular item. But we started thinking about how we could better support WSL to make these errors be handled more generically than on a extension by extension base.

@jochenstu
Copy link

Any update? :)

@neyronius
Copy link

@GioBonvi i've replaced the last line with
C:\Windows\System32\wsl.exe php %v_params%
So we can avoid using the second file.

@edwinhuish
Copy link

edwinhuish commented Sep 8, 2018

@neyronius It works, thank you.

@roblourens roblourens removed the help wanted Issues identified as good community contribution opportunities label Oct 6, 2018
@sachieldvangel
Copy link

"php.validate.executablePath": "wsl php"

@resonancedesigns
Copy link

I was excited about @GioBonvi & @neyronius batch script fix for this until I tried it and god "Error spawning PHP: Command failed: C:\Dev\Scripts\wsl\php.bat --version zsh:1: command not found: php" so I guess if you have zsh or something similar installed, this work-around won't work... Any news on official wsl php support?

@tanmancan
Copy link

tanmancan commented Feb 27, 2019

@resonancedesigns
I was able to get @GioBonvi script working by using C:\Windows\System32\wsl.exe as @neyronius suggested. But I kept the second file. I am using zsh, but I do not get any errors.

I also added #!/bin/bash to the top of the windows-php script. Just one thing to note - I did change the path from C:\ to D:\ in the replacements.

The scripts are in D:\wsl-tools\ and windows-php is symlinked inside my /usr/local/bin.

windows-php -> /mnt/d/wsl-tools/windows-php

php.bat

@echo OFF
setlocal ENABLEDELAYEDEXPANSION

rem Collect the arguments and replace:
rem  '\' with '/'
rem  'd:' with 'mnt/d'
rem  '"' with '\"'
set v_params=%*
set v_params=%v_params:\=/%
set v_params=%v_params:D:=/mnt/d%
set v_params=%v_params%
set v_params=%v_params:"=\"%

rem Call the windows-php inside WSL.
rem windows-php is just a script which passes the arguments onto
rem the original php executable and converts its output from UNIX
rem syntax to Windows syntax.
C:\Windows\system32\bash.exe -l -c "windows-php %v_params%"

windows-php

#!/bin/bash
# Pass all the arguments to PHP.
output=$(php "$@")
# Perform UNIX->WINDOWS syntax replacements.
output="${output//$'\n'/$'\r'$'\n'}"
output="${output//\/mnt\/d/D:}"
output="${output//\//\\}"
# Echo corrected output.
echo $output

And here are the settings inside VSCode:

"php.validate.executablePath": "d:\\wsl-tools\\php.bat",

@edwinhuish
Copy link

这么久了,也没有官方的解决方案么。。。

@ianzhi 请看清楚 @GioBonvi@tanmancan 的解决方案。。。

@ianzhi
Copy link

ianzhi commented Apr 19, 2019

这么久了,也没有官方的解决方案么。。。

@ianzhi 请看清楚 @GioBonvi@tanmancan 的解决方案。。。

ok,tks

@RMacfarlane
Copy link
Contributor

We just announced remote development with VS Code, check out the blog post for details https://code.visualstudio.com/blogs/2019/05/02/remote-development

@RMacfarlane RMacfarlane added this to the April 2019 milestone May 2, 2019
@erdemece
Copy link

How does remote development solve this issue? What is the setting for php.validateexecutablePath now?

@roblourens
Copy link
Member

See some details about developing in WSL here: https://code.visualstudio.com/docs/remote/wsl

In that scenario, that setting would be the path to PHP on the WSL side.

@erdemece
Copy link

See some details about developing in WSL here: https://code.visualstudio.com/docs/remote/wsl

In that scenario, that setting would be the path to PHP on the WSL side.

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

This doesn't work. Im sorry I am not very good at these things.

I run code-insiders from wsl and I have all the remote development extensions installed.

@edwinhuish
Copy link

See some details about developing in WSL here: https://code.visualstudio.com/docs/remote/wsl
In that scenario, that setting would be the path to PHP on the WSL side.

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

This doesn't work. Im sorry I am not very good at these things.

I run code-insiders from wsl and I have all the remote development extensions installed.

I don't know why the people like to wrote very short words with link which is very long history.

The solution correctly is:

  1. Install Visual Studio Code Insiders, (NOT THE NORMAL ONE)
  2. Install Remote - WSL for Visual Studio Code Insiders (NOT THE NORMAL ONE)
  3. Open Visual Studio Code Insiders by $ code-insiders <path> in the WSL bash

NOW YOU CAN ENJOY YOUR VSCODE IN WSL

@vscodebot vscodebot bot locked and limited conversation to collaborators Jun 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality on-testplan php PHP support issues WSL Issue when using WSL
Projects
None yet
Development

No branches or pull requests