Using PHP installed in WSL with VScode

I was looking for a way to get the applications already installed on WSL(Windows Subsystem LInux), while working on a PHP app.

I wanted to use the PHP formatter but VScode wanted me to install PHP executable on windows, but I had already done that in WSL(so installing it on windows again, violates the DRY principle 🙂 )

Using something like this, in user settings

"phpformatter.phpPath": "wsp php",

unfortunately didn’t work.

A workaround is to create a bat file(let’s call it php.bat):

@echo off
set v_params=%*
set v_params=%v_params:\=/%
set v_params=%v_params:c:=/mnt/c%
set v_params=%v_params:"=\"%
bash.exe -c "php %v_params%"

and in your user settings file add:

"phpformatter.phpPath": "X:\\Path\\to_bat_file\\php.bat",

Replace X: with your drive letter like  C: or D:

That’s it! PHP formatter should now work, atleast untill VScode makes some official update, allowing easy inter-operations with the wsl environment.

You can find more details for better wsl setup at this link(source of this post).

https://gist.github.com/Voronoff/059c50f9fd354386c305c55af1f3a61f#install-and-set-up-python-to-work-with-vscode-and-wsl

Leave a Reply

Your email address will not be published. Required fields are marked *