How to check PHP in VS code using WSL php

In VS code, you can check php using php executable. But is there a way to use php installed on WSL instead?

+4
source share
2 answers

This is possible using the old school batch file.

php.bat

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

setting.json

"php.validate.executablePath": "c:\\PATH_TO\\php.bat"
+1
source

Another answer did not help me either: after some work, I came up with these two scenarios:

This is called php.bat, and I put it 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 is called windows-php and is placed somewhere in the WSL path (I selected /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

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

Note

, pull, , , .

+1

Source: https://habr.com/ru/post/1655703/


All Articles