I try to configure VSCode to use our php executable inside a docker container. Firstly i tried it on a macintosh and everything works as expected. At work we use windows pc´s and i cant get it to work.
Workspace Settings
"php.suggest.basic": false,
"php.executablePath": "C:\\Source\\stack\\.bin\\php.bat",
"php.validate.executablePath": "C:\\Source\\stack\\.bin\\php.bat",
"php.validate.run": "onSave",
"php.validate.enable": true
I tried to set a .sh
, .exe
or .bat
file but none of them seemed to work.
php.bat
@echo off
docker run -i stack_php php %*
php.sh
#!/bin/sh
docker run stack_php php "$@"
return $?
Anybody of you can help me get this to work? We would like to change our IDE from PHPStorm to VSCode but we arent able to so because everything a developer needs is stored in docker containers.
5条答案
按热度按时间b4qexyjb1#
I came up with a solution on Linux for multiple laravel sail projects.
Create a file named 'php' on /usr/local/bin
Make it executable:
Edit the file (with sudo) and paste this code:
Now just run, example, 'php -v' inside the laravel sail project.
egdjgwm82#
Or you can use plugin for that: https://marketplace.visualstudio.com/items?itemName=henriiik.docker-linter
Example how to configure it correctly could be found in their repository https://github.com/henriiik/vscode-docker-linter/blob/master/playground-php/.vscode/settings.json
You will need to modify the existing settings to look like this example below...
velaa5lx3#
If you are running Docker on Windows and WSL2 you should replace the underscores for dash like this:
It took me a while to find out, i hope this can help someone.
qyyhg6bp4#
I had the exact same issue, and just found a solution, but in my case I'm working under the Windows Subsystem for Linux, not straight Windows, so I'm not sure if/how it would be adapted. You can read more about it here: set PHP path from host to docker container
For me, the part that seemed to resolve the problem was moving the "wrapper" to
/usr/local/bin
, and then setting that as my php.validate.executablePath for the Workspace (you could also set it at the Remote WSL level, but in my case, I might develop with multiple versions of PHP)I hope that might help you!
Update: I just saw someone in the comments was working in Windows! They suggested putting
into a .bat file; looking at what you've already done, the difference appears to be using
exec
instead ofrun
pftdvrlh5#
微软现在有一个扩展,允许你在容器上下文中打开一个vscode项目。这允许你使用在Docker容器中加载的PHP可执行文件来实现intellisense和其他功能。
https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers
https://github.com/Microsoft/vscode-remote-release#readme