Debugging Laravel with VSCode on Docker container using Xdebug as debugger

后端 未结 1 949
花落未央
花落未央 2021-01-15 14:38

I am trying to debug Laravel code on Visual Studio Code using Xdebug. I am using Docker container that works as server.

But I am getting this error when try to debug

相关标签:
1条回答
  • 2021-01-15 15:22

    You can use PHP Debug VS Code extension to connect with XDebug. PHP-FPM are run at port 9000 by default, so it's best to change the xdebug.remote_port settings to another port (e.g. 9001):

    // launch.json
    
    "version": "0.2.0",
    "configurations": [
      {
        "name": "Listen for XDebug",
        "type": "php",
        "request": "launch",
        "pathMappings": { "/": "${workspaceRoot}/" },
        "port": 9001
      },
      {
        "name": "Launch currently open script",
        "type": "php",
        "request": "launch",
        "program": "${file}",
        "cwd": "${fileDirname}",
        "port": 9001
      }
    ]
    

    If you are using Docker, Use these settings in your php.ini file :

    //php.ini
    
    [XDebug]
    xdebug.remote_enable = 1
    xdebug.remote_autostart = 1
    xdebug.remote_host = host.docker.internal
    xdebug.remote_port = 9001
    

    As of Docker version 18.03, host.docker.internal points to host IP address on Mac / Windows. For Linux, you can use this workaround.

    Once these settings are set, you are good to go.

    0 讨论(0)
提交回复
热议问题