Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Niush's avatar
Level 50

Laravel Sail: How to add executablePath in VSCode Settings

So, I just setup a fresh project with Laravel Sail. (Windows 10, WSL2, Docker)

Everything are running perfectly. But, in VSCode the PHP Language Feature requires php.validate.executablePath in settings. How to put the PHP path from Docker in this settings.

And, also PHP is not installed in WSL. When, I run php -v in WSL it throws Command not found. But, sail up works fine. (It Seems to be running standalone, so how to get the executable path???)

0 likes
26 replies
Niush's avatar
Level 50

@sinnbeck

I created a php.bat file in root of my project with this in it.

@echo off
sail php %*

And this in the VSCode settings.json I have:

{
  "php.validate.executablePath": "./php.bat"
}

It then shows Notification with spawn ./php.bat EACCES, I cannot verify if it worked or not. It does not validate the PHP code at all.

1 like
Sinnbeck's avatar

Try giving it the full path to the bat file on your machine

Niush's avatar
Level 50

This is what the Reveal in Explorer gives: wsl$/Ubuntu/home/username/example-app/php.bat. It does not work either.

Kedo2k's avatar

VSCode is not allowed to run that .bat file. Try sudo chmod 777 php.bat.

Niush's avatar
Level 50

Yep, I have installed Remote-WSL as well as Docker extension. Everything else is good and working.

It is just the php.validate.executablePath that I want to use from wsl/docker. For now, the only solution seems to be is install PHP in local system and use it for this specific settings. (Plus PHP Intelephense)

Niush's avatar
Level 50

Nope. Have not found any solution yet. I instead installed multiple PHP Versions (7 & 8) in Local System with Chocolatey. And, switch executablePath between them per project as required.

1 like
roscoegray's avatar

Tried for far too long to get this to work but failed. Tring to pass commands using a .bat file either gives me "Error: No such container: php7-vscode" which I don't understand, or other issues around the environment. Going to go back to using php locally instead for now.

patake's avatar
patake
Best Answer
Level 2

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.

14 likes
thisisjeffsnow's avatar

The underscores in the docker container name were hyphens in the current version of Docker Desktop on Windows 10 for me, but otherwise this worked like a charm!

1 like
ahmedamin1700's avatar

What should I add then to php validate executablePath in vscode for php formatter to work

mefofaf487's avatar

This video worked for me: youtu.be/0KjyubRdtvA?t=316

From minute 5:16 to 6:39

1 like
pepebec's avatar

@mefofaf487 Thank you so much this video helped me a lot.

FYI I had to change the gist code a little bit accordingly with the container name, in the video example was {_laravel.test_1} y changed to {-laravel.test-1}

1 like
paweld's avatar

@andrew_rybachuk Have you maybe solved this problem with Spawn Error? I don't know why, but if I type php -v in console it seems working. But vscode gets error.

bongzki01's avatar

I still get a Spawn Error using the solution of @patake. I solved it by getting the container name using the wildcard *-laravel.test-1.

containerName=$(docker ps -a --format '{{.Names}}' | awk '/.*-laravel\.test-1$/')
echo "Container name: $containerName"

command="docker exec $containerName php "$@""
echo "Running php on Docker container: $containerName"

# Debugging information
docker ps -a

# Execute the command
$command
JosephNC's avatar

To accommodate my custom container name defined in docker-compose.yml, I made some code modifications. This might be helpful if you're using a custom name as well.

image=$(docker ps -a --format '{{.Image}}' | awk '/^sail-/')
containerName=$(docker ps -a --filter "ancestor=$image" --format '{{.Names}}')
command="docker exec $containerName php "$@""
echo "Running php on Docker container: $containerName"
$command
puklipo's avatar

Just install php, composer and nodejs on WSL2 as well.

You don't have to stick to using Docker.

WSL2 for Windows. Homebrew for Mac. Install php on the host.

Please or to participate in this conversation.