Hướng dẫn php validate executablepath docker

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 "[email protected]"
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.

asked Nov 27, 2018 at 14:28

Stillmatic1985Stillmatic1985

1,7226 gold badges20 silver badges37 bronze badges

I came up with a solution on Linux for multiple laravel sail projects.

Create a file named 'php' on /usr/local/bin

sudo touch /usr/local/bin/php

Make it executable:

sudo chmod +x /usr/local/bin/php

Edit the file (with sudo) and paste this code:

path=$(printf '%s\n' "${PWD##*/}")
command="docker exec ${path}_laravel.test_1 php "[email protected]""
echo "Running php on docker ${path}_laravel.test_1"
$command

Now just run, example, 'php -v' inside the laravel sail project.

answered Feb 25, 2021 at 21:02

6

If you are running Docker on Windows and WSL2 you should replace the underscores for dash like this:

path=$(printf '%s\n' "${PWD##*/}")
command="docker exec ${path}-laravel.test-1 php "[email protected]""
echo "Running php on docker ${path}-laravel.test-1"
$command

It took me a while to find out, i hope this can help someone.

answered Jul 18 at 0:13

Hướng dẫn php validate executablepath docker

0

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

docker exec -i your_container_name php %*

into a .bat file; looking at what you've already done, the difference appears to be using exec instead of run

answered Jul 22, 2020 at 21:44

1

Skip to content

I Love VSCode and I am sure you do too which is probably the reason why you are reading this. I have been an avid user of VSCode for several years now and I love the flexibility it provides with third party extensions and plugins.

I have to wirte a lot of PHP code for a bunch of different projects and I like to use docker for local development environment. Docker makes it very easy to emulate production environments on your local machine which is the primary reason I have ditched VirtualBox completely for the past couple of years and switched to docker completely.

After moving to docker I could not find a proper way to add the PHP support to VSCode as it requires an executablePath to the php executable to work.

To overcome this issue all you need to do is to create a file in you project directory by the name of `php` and add the following code to it

#!/bin/bash
docker exec -it web_app php [email protected]

`web_app` is the name of the container that has PHP installled in it. Now we need to make this file executable if you are on linux or mac using this command `chmod +x /path/to/project/php`.

Now you can update the `executablePath` and set its value to this new file that you have just created

"php.validate.executablePath": "./php"

Now you should have the PHP support in VSCode without installing PHP on your local machine.

If you know of a better way to do this, Please share in comments.

Copyright © 2022 Web Developer Pal

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.

asked Nov 27, 2018 at 14:28

Stillmatic1985Stillmatic1985

1,7226 gold badges20 silver badges37 bronze badges

I came up with a solution on Linux for multiple laravel sail projects.

Create a file named 'php' on /usr/local/bin

sudo touch /usr/local/bin/php

Make it executable:

sudo chmod +x /usr/local/bin/php

Edit the file (with sudo) and paste this code:

path=$(printf '%s\n' "${PWD##*/}")
command="docker exec ${path}_laravel.test_1 php "$@""
echo "Running php on docker ${path}_laravel.test_1"
$command

Now just run, example, 'php -v' inside the laravel sail project.

answered Feb 25, 2021 at 21:02

6

If you are running Docker on Windows and WSL2 you should replace the underscores for dash like this:

path=$(printf '%s\n' "${PWD##*/}")
command="docker exec ${path}-laravel.test-1 php "$@""
echo "Running php on docker ${path}-laravel.test-1"
$command

It took me a while to find out, i hope this can help someone.

answered Jul 18 at 0:13

Hướng dẫn php validate executablepath docker

0

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

docker exec -i your_container_name php %*

into a .bat file; looking at what you've already done, the difference appears to be using exec instead of run

answered Jul 22, 2020 at 21:44

1