skip to Main Content

I am using WSL2, Ubuntu 20.04 and running VSCode. I am using the Code Runner extension in VSCode and XAMPP on Windows

I set the path to php.exe in the Windows Environment Variables.

I have the following in the VSCode settings.json for code runner

 "code-runner.executorMap": {
        "javascript": "node",
        "php": "C:\xampp\php\php.exe",
        "python": "python",
        "perl": "perl",
        "ruby": "C:\Ruby23-x64\bin\ruby.exe",
        "go": "go run",
        "html": ""C:\Program Files\Mozilla Firefox\firefox.exe"",
        "java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
        "c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
    },

I have a program in the editor called index.php. I right click in the VSCode editor to select "Run Code"

In the VSCode terminal’s output window I get this error message:


[Running] C:xamppphpphp.exe "/home/johnr/xproj/index.php"
/bin/sh: 1: C:xamppphpphp.exe: not found

[Done] exited with code=127 in 0.039 seconds
  1. Why and I getting the error message?
  2. Why does the path in the bin statement not show the slashed between the directories (C:xamppphpphp instead of C:xamppphpphp.exe)?

I have tried various configuration changes based on Google search results but nothing has changed this error message.

Except when I changes sh dash to sh bash and got this message instead

[Running] C:xamppphpphp.exe "/home/johnr/xproj/index.php"
/bin/sh: C:xamppphpphp.exe: not found

[Done] exited with code=127 in 0.039 seconds

The only difference is the 1: was not present after the /bin/sh:

2

Answers


  1. I think WSL needs Unix-like paths, so for example your php path should be

    "php": "/mnt/c/xampp/php/php.exe",

    instead of

    "php": "C:\xampp\php\php.exe",

    Same would probably apply to ruby.

    Login or Signup to reply.
  2. While @Caellion is on the right track in the other answer, I don’t recommend this.

    In general, either use the Windows toolchain in Windows, or the Linux toolchain in WSL, but mixing the two isn’t a good idea.

    Since you are using the Windows XAMPP stack, just run VSCode from Windows without the WSL2 extension. This should allow it to pick up and run the Windows PHP interpreter correctly using the Windows path.

    The Windows version of PHP (and other development tools) is not going to understand Linux paths, processes, native code modules, etc.

    Conversely, the Linux/WSL version of these tools isn’t going to understand the Windows paths, processes, native code modules, etc.

    It’s sometimes possible, in a very simple project, to combine the two, but as a general rule it’s far better to keep to one architecture or the other.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search