L00tz1ffer
L00tz1ffer

Reputation: 37

VSCode is not able to connect to Xdebug

I tried to setup the Xdebug step debugger in my docker container to be able to connect to my Docker container.

This is my configuration snippet from the launch.json in the .vscode directory in my project:

{
    "name": "Xdebug",
    "type": "php",
    "request": "launch",
    "hostname": "127.0.0.1",
    "port": 9000,
    "pathMappings": {
        "/var/www/html/": "${workspaceFolder}/code/",
    },
},

This is the Code Snippet of my docker-compose.yml:

services: 
  webserver:
    container_name: webserver_orderlinev3
    build: webserver
    ports: 
      - 8080:80
      - 9000:9000
    volumes: 
      - ./code:/var/www/html
      - ./webserver/php-ini-overrides.ini:/usr/local/etc/php/conf.d/php-ini-overrides.ini
      - ./webserver/phpsessions:/var/www/phpsessionfiles
      - ./xdebuglog:/tmp/xdbglog

    extra_hosts:
      - host.docker.internal:host-gateway
    environment:
      - XDEBUG_MODE=debug,develop,coverage,profile,trace

And those where my php.ini overrides


[session]
session.save_handler=files
session.save_path="/var/www/phpsessionfiles"

[xdebug]
xdebug.client_port=9000
xdebug.mode=off

xdebug.discover_client_host=on
xdebug.client_host = host.docker.internal

xdebug.remote_connect_back=0
xdebug.remote_enable=on
xdebug.remote_handler=dbgp

xdebug.start_with_request = yes
xdebug.log=/tmp/xdbglog/xdebug_remote.log

As this is the log output from the xdebug.log

[17] Log opened at 2022-10-25 16:22:46.248594
[17] [Step Debug] INFO: Checking remote connect back address.
[17] [Step Debug] INFO: Checking header 'HTTP_X_FORWARDED_FOR'.
[17] [Step Debug] INFO: Checking header 'REMOTE_ADDR'.
[17] [Step Debug] INFO: Client host discovered through HTTP header, connecting to 172.29.0.1:9000.
[17] [Step Debug] WARN: Creating socket for '172.29.0.1:9000', poll success, but error: Operation now in progress (29).
[17] [Step Debug] WARN: Could not connect to client host discovered through HTTP headers, connecting to configured address/port: host.docker.internal:9000. :-|
[17] [Step Debug] INFO: Connected to debugging client: 172.29.0.1:9000 (from REMOTE_ADDR HTTP header), host.docker.internal:9000 (fallback through xdebug.client_host/xdebug.client_port). :-)
[17] [Step Debug] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///var/www/html/orderline/api/index.php" language="PHP" xdebug:language_version="8.0.24" protocol_version="1.0" appid="17"><engine version="3.1.5"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2022 by Derick Rethans]]></copyright></init>

[17] [Step Debug] <- feature_set -i 1 -n max_children -v 100
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="1" feature="max_children" success="1"></response>

[17] [Step Debug] <- feature_set -i 2 -n max_data -v 8192
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="2" feature="max_data" success="1"></response>

[17] [Step Debug] <- breakpoint_set -i 3 -t exception -x "Notice"
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="3" id="170008"></response>

[17] [Step Debug] <- breakpoint_set -i 4 -t exception -x "Warning"
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="4" id="170009"></response>

[17] [Step Debug] <- breakpoint_set -i 5 -t exception -x "Error"
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="5" id="170010"></response>

[17] [Step Debug] <- breakpoint_set -i 6 -t exception -x "Exception"
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="6" id="170011"></response>

[17] [Step Debug] <- breakpoint_set -i 7 -t exception -x "Fatal error"
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="7" id="170012"></response>

[17] [Step Debug] <- breakpoint_set -i 8 -t exception -x "Parse error"
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="8" id="170013"></response>

[17] [Step Debug] <- breakpoint_set -i 9 -t exception -x "Unknown error"
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="9" id="170014"></response>

[17] [Step Debug] <- run -i 10
[17] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="run" transaction_id="10" status="stopping" reason="ok"></response>

[17] Log closed at 2022-10-25 16:22:46.308352


I do not get any clue out of this, why it is actually not working.

The Host port to Guest port Redirection seems to be working since I can connect to the webserver through localhost:8080 I watched now several YouTube tutorials to this topic but I have no clue what I'm doing wrong.

Xdebug seems to connect to docker.host.internal but the gateway seems to be blocking this - although I turned off my firewall even for testing (again turned it on).

May someone with experience in docker and Xdebug may help me? I would really appreciate.

P.S. I'm not using any VPN connection - its disabled for exactly that reason.

Upvotes: 0

Views: 1228

Answers (1)

L00tz1ffer
L00tz1ffer

Reputation: 37

thank you, its up and running now finally Without @LazyOne i would have been stuck here for some more time, special thanks to him <3

this is the config

[session]
session.save_handler=files
session.save_path="/var/www/phpsessionfiles"

[xdebug]
#xdebug.client_port=9003
#xdebug.mode=off

#xdebug.discover_client_host=on
xdebug.client_host = host.docker.internal

xdebug.start_with_request = yes
xdebug.log=/tmp/xdbglog/xdebug_remote.log

docker-compose.yml

version: "3.2"
 

 
services: 
  webserver:
    container_name: webserver_orderlinev3
    build: webserver
    ports: 
      - 8080:80

    volumes: 
    #setup virtual webroot
      - ./code:/var/www/html/
    # setup react
      - ./react_build:/var/www/html/orderline/
    #setup virtual webroot
      - ./code/orderline/api:/var/www/html/orderline/api

    #php.ini overrides
      - ./webserver/php-ini-overrides.ini:/usr/local/etc/php/conf.d/php-ini-overrides.ini
    #php sessions
      - ./webserver/phpsessions:/var/www/phpsessionfiles
    #xdebug
      - ./xdebuglog:/tmp/xdbglog

    extra_hosts:
      - host.docker.internal:host-gateway
    environment:
      - XDEBUG_MODE=debug,develop,coverage,profile,trace

{
    // Verwendet IntelliSense zum Ermitteln möglicher Attribute.
    // Zeigen Sie auf vorhandene Attribute, um die zugehörigen Beschreibungen anzuzeigen.
    // Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Xdebug",
            "type": "php",
            "request": "launch",
            "hostname": "127.0.0.1",
            "port": 9003,
            "pathMappings": {
                "/var/www/html": "${workspaceFolder}/code",
            },
        },
    ]
}

Upvotes: 1

Related Questions