Gregg Seipp
Gregg Seipp

Reputation: 173

Unable to get XDebug working in Visual Studio Code

I am trying to get XDebug working with Visual Studio Code on Windows 10. I have Apache/PHP server running on my local machine (Apache/2.4.41 (Win64) PHP/7.3.9RC1). It works without any problem. I have Visual Studio Code running on the same machine. I've installed PHP XDebug 1.13 in it. I have a small test script in the htdocs directory. I set a couple of breakpoints and launch the debugger and get this in the Debug Console...

<- launchResponse
Response {
  seq: 0,
  type: 'response',
  request_seq: 2,
  command: 'launch',
  success: true }

I then switch to Chrome which, at that moment, has an arrow-hourglass so I can tell something is trying to work. I refresh the page and the debugger does not stop at the breakpoints.

I've read through a bunch of posts already. Here's the relevant entries in my php.ini file...

[XDebug]
xdebug.stopOnEntry = true
xdebug.remote_host = "127.0.0.1"
xdebug.remote_port=9001
xdebug.remote_connect_back=1
xdebug.remote_enable = 1
xdebug.remote_autorestart = 1
zend_extension = "d:/php/ext/php_xdebug-2.7.2-7.3-vc15-x86_64.dll"

Here's my current launch.json file...

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [

        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9001,
            "hostname": "127.0.0.1",
            "log": true,
         },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9001,


        }
    ]
}

I've tried:

Here's my test script...

<?php
$a = 3;
$b = 19;
$c = $a + $b;
echo "Answer: $c";
?>

I, obviously, expect the debugger to stop at the first breakpoint (which is on the line "$a = 3;" It doesn't. I've tried adding more breakpoints. The browser goes straight to the answer "Answer: 22"

One other thing, I tried entering echo "1" in the prompt at the bottom of the Debug Console and got this:

echo "1"
Cannot evaluate code without a connection
-> evaluateRequest
{ command: 'evaluate',
  arguments: { expression: 'echo "1"', context: 'repl' },
  type: 'request',
  seq: 3 }

So I'm guessing that the web server is not connecting. I've checked the error.log file but there are no errors...no indications of anything related to debugging or connections.

NOTE: I opened inbound and outbound ports on the firewall and ran netstat -ano and verified that port 9001 is being listened on...

 TCP    127.0.0.1:9001         0.0.0.0:0              LISTENING       16144

Any help would be MUCH appreciated!!

Upvotes: 2

Views: 6897

Answers (1)

Silas Palmer
Silas Palmer

Reputation: 2985

Here's the launch.json I used to get this working on my Windows + Windows Linux Subsystem (Ubuntu) setup.

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [

        
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9000,                
            "stopOnEntry": true, // Once working, comment out this line
            "pathMappings": {
                // eg your web files in C:\Path\To\Code
                "/mnt/c/Path/To/Code": "${workspaceFolder}"
            },
            "log": true            
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9000
        }
    ]
} 

and my xdebug.ini is:

zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_autostart=1

Upvotes: 4

Related Questions