3

PHP debugging in vscode using xdebug and xampp is not working even after all configurations.

here is my php.ini file config:

zend_extension = D:\Xampp\php\ext\php_xdebug-3.0.0-7.3-vc15-x86_64.dll
[XDebug]
xdebug.remote_enable = 1
xdebug.remote_autostart = 1

this is json file

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9000
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}"
        }

    ]
}
pallavi-gope
  • 31
  • 1
  • 6

6 Answers6

6

xDebug 3 has changed several default values, so be sure your code is ready to work with new ones.

Here is my configuration set, which allowed me to use PHP breakpoints as always:

.vscode\launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "port": 9000
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9000
        }
    ]
}

php.ini (lines manually inserted in the end of a file)

    [xdebug]
    zend_extension = "php_xdebug-3.0.4.dll"
    xdebug.mode = debug
    xdebug.discover_client_host = 1
    xdebug.start_with_request = yes
    xdebug.client_port = 9000

Note: above zend_extension option would try to find your xdebug library in a .../modules/php/PHP_%your_php_version%/ext/ folder

Roman Peniaz
  • 535
  • 5
  • 10
  • 1
    +1 for the discover and start with request settings. Those did the job for me when VS Code was ignoring everything else – misteraidan Jul 23 '21 at 06:20
  • 1
    Note the port in both the vscode settings and the php.ini. The default changed from 9000 in xdebug 2 to 9003 in xdebug 3. So you either need to set them both to 9000 or change your settings to 9033 and leave php.ini silent. – Dan Chadwick Nov 23 '21 at 17:28
4

I just got satisfaction with XDebug 3. I found a good response here :https://github.com/felixfbecker/vscode-php-debug/issues/411 by jason-nabooki. I do the same :

Json file :

    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9003,
            "stopOnEntry": true,
            "log": true,
            "pathMappings": {"/var/wwww/ammac":"${workspaceRoot}"}
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9003
 

PHP.ini :

    xdebug.mode= debug
    xdebug.start_with_request = yes
    xdebug.discover_client_host = true

To use the debugger (I didn't find immediatly due to my precedent use of Eclipse !),

first : click on the green triangle near "Listen for XDebug

second : refresh the web page in Firefox (or other)

For me it works i got the variables. Not yet test the breakpoints.

Remark : no need of the XDEbug helper in Firefox (surprise!)

AC24
  • 53
  • 4
  • This works only because it is designed to stop at first line but it don't stop on breakpoints. If removed stopOnEntry it don't works at all anymore. – AC24 Dec 09 '20 at 14:16
  • Suite: the problem is with the path mapping. ${workspaceroot} do not match "/var/www/ammac". Where is the "workspaceroot" ? To find it just do : File -> Open Folder : it shows you the workspace root, In my case :"/var/www". So I change "${worspaceRoot}" to "${workspaceRoot}/ammac" and it works definitively fine : F5 and it stops to breakpoint. – AC24 Dec 09 '20 at 14:24
4

In VSCode, I went to Settings -> Features -> Debug -> Allow Breakpoints Everywhere.

I check marked "Allow Breakpoints Everywhere" and I was able to debug again.

Garrett
  • 55
  • 4
0

Struggled with this myself. Apparently XDebug 3.x doesn't work as outlined above. I found that even the equates under [XDebug] are no longer compatible. Download XDebug 2.x (I think 2.98 is the latest in the 2.x series). After I switched to 2.x, I'm no longer having any issue (so far).

0

https://xdebug.org/wizard - This tool helped me to find the reason why debuger didn't work.

Igor Semkiv
  • 251
  • 2
  • 11
0

Your are using xdebug version 3:

zend_extension = ... php_xdebug-3....

but in configuration you listen port 9000:

"port": 9000

The default Xdebug port changed between Xdebug v2 to v3 from 9000 to 9003.

Just change "port": 9000 => "port": 9003