Debug PHP with VSCode and Docker

后端 未结 2 1835
孤城傲影
孤城傲影 2020-12-13 19:29

I\'m trying to debug a PHP app running on Docker with VSCode, but without success.

In the past I was able to easily debug my PHP apps with VSCode running WAMP Server

相关标签:
2条回答
  • 2020-12-13 20:03

    you are missing port :9000 (or :9001) in the docker-compose.yml,

    which needs to be connectable, for the IDE to connect from the outside.

    for VSCode the PHP Debug extension might be required to interact with xdebug.

    the default launch.json only uses port: 9000 only once - and has log: true.

    {
      "configurations": [{
          "name": "Listen for XDebug",
          "type": "php",
          "request": "launch",
          "port": 9000,
          "log": true
        }, {
          "name": "Launch",
          "request": "launch",
          "type": "php",
          "program": "${file}",
          "cwd": "${workspaceRoot}",
          "externalConsole": false
        }
      ]
    }
    

    also see vscode-php-debug and starting the debugger.

    0 讨论(0)
  • 2020-12-13 20:18

    Managed to solve my issue with the following settings:

    launch.json

    {
        "version": "0.2.0",
        "configurations": [{
                "name": "Listen for XDebug",
                "type": "php",
                "request": "launch",
                "port": 9000,
                "log": true,
                "externalConsole": false,
                "pathMappings": {
                    "/srv/app/cms": "${workspaceRoot}/cms",
                },
                "ignore": [
                    "**/vendor/**/*.php"
                ]
            },
        ]
    }
    

    xdebug.ini

    zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so
    xdebug.default_enable=1
    xdebug.remote_enable=1
    xdebug.remote_port=9000
    xdebug.remote_handler=dbgp
    xdebug.remote_connect_back=0
    xdebug.remote_host=host.docker.internal
    xdebug.idekey=VSCODE
    xdebug.remote_autostart=1
    xdebug.remote_log=/usr/local/etc/php/xdebug.log
    
    0 讨论(0)
提交回复
热议问题