16

I am trying to debug on my XAMPP using VSCode and didn't worked. I know there are tons of questions about this and I've tried everything I can but still won't work.

There is really 1 thing weird thou about my xdebug extension.I am currently using PHP v7.4.12 and Xdebug version 3.

I know my Xdebug works on PHP because I viewed phpinfo() and it shows just how I set it. The weird part is among the many of the tutorials out there normally zend_extension = path..,xdebug.remote_enable = 1 and xdebug.remote_autostart = 1 should be enough but when I viewed phpinfo it is as follows below:

enter image description here

I tried to set it with xdebug.remote_port = 9000 and xdebug.remote_host = "localhost" but still won't work. I even have read about changing localhost to 127.0.0.1 but still didn't work.

Any help would be appreciated. Here is my launch.json file and php ini file.

php.ini

zend_extension = "C:\xampp\php\ext\php_xdebug.dll"
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_log = "C:\xampp\tmp\xdebug\xdebug.log"
xdebug.remote_port = 9000
xdebug.remote_host = "127.0.0.1"
xdebug.idekey=VSCODE

launch.json

{
    // 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": "Launch current script in console",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "externalConsole": false,
            "port": 9000
        },
        {
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "port": 9000
        }
    ]
}

If it is caused maybe due to not setting "pathMappings", anyone can teach me how to use this?

By the way the xdebug.log also doesn't work

kenjiro jaucian
  • 391
  • 1
  • 3
  • 10

2 Answers2

50

You are using Xdebug v3 but keep using Xdebug v2 config parameters. You need to go through Upgrading from Xdebug 2 to 3 Guide and adjust your settings.

Xdebug v3 uses different config params than Xdebug v2 (your phpinfo() output tells you exactly that on your screenshot). 5 out of 6 "xdebug." params from your current php.ini do nothing in Xdebug v3.

For Xdebug 3 it should be like this (based on your original config -- better start using new 9003 default port):

zend_extension = "C:\xampp\php\ext\php_xdebug.dll"
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_port = 9000
xdebug.client_host = "127.0.0.1"
xdebug.log = "C:\xampp\tmp\xdebug\xdebug.log"
xdebug.idekey = VSCODE
LazyOne
  • 158,824
  • 45
  • 388
  • 391
  • 7
    THANK YOU VERY MUCH. I was doing this for 2days now and still can't do it. cause of this it's now working. THANK YOU! – kenjiro jaucian Dec 07 '20 at 00:34
  • Thank you very much – ariful Islam Dec 18 '20 at 20:25
  • Thank you, ppa:ondrej/php changed xdebug from V2 to V3 without notice and everything was broken – Vladimir Hidalgo Dec 22 '20 at 01:34
  • change the above port to 9003 for VSCODE to work out of the box I believe. – Eric Sebasta Aug 20 '21 at 10:16
  • 1
    @EricSebasta This answer is for that specific question -- especially since it says "based on your original config". I'm sure you and others do not do StackOverflow programming when something gets copied without reading what it actually does and how it can be adjusted to your particular situation. **But yes, changing the port to `9003` (or simply removing that line since it's a default port now) will be a more suitable for new setups/new users** – LazyOne Aug 20 '21 at 10:25
  • I understand - and I agree completely- but since lots of people will be led here for the answer, I wanted to make a note that the default for VSCODE is 9003 so simply slapping that code in vscode will fail unless they change that port number to 9003.. – Eric Sebasta Aug 23 '21 at 02:37
  • @EricSebasta I though about removing that line, and actually did it .. but then had to put it back. The reason is the original question -- it has `9000` there, in the VSCode config. So seeing `9000` there and assuming default or seeing actual `9003` here in Xdebug config will be more confusing for such "do not know how it all works" folks. So I will have to leave as is with old 9000 ports – LazyOne Aug 23 '21 at 09:15
  • I know this is off topic but don't forget SELinux can block php from connecting by default, use `setsebool -P httpd_can_network_connect on`. (I'm setting up PHP dev after reinstalling Fedora and it's now defaulting to xdebug 3, so the above was helpful, but also needed this config tweak) – Neek Nov 18 '21 at 06:54
  • @Neek That's depends on a distro/OS used. Have not seen the mention of this for a while. Bu yes, it's a known (to me) issue that needs to be checked when you do not see any outgoing connections (Xdebug may not even try to make one). I remember it since 2014 thread... https://intellij-support.jetbrains.com/hc/en-us/community/posts/206339279-Xdebug-can-not-connect-to-PhpStorm-on-OS-X-Mavericks?page=1#community_comment_206899645 – LazyOne Nov 18 '21 at 08:57
  • you the xdebug king! – Rok Sprogar Jan 06 '22 at 12:20
  • I have to add "stopOnEntry":true in the launch.json file. Thank you – m50 May 20 '22 at 09:50
  • I was about to go crazy – Bruno Polo May 30 '22 at 15:38
  • Thank you very much. now xdebug 3 has worked. Mator Skalangkog – Ahmad Sayadi Oct 04 '22 at 09:32
  • xdebug.start_with_request = yes – itsoft3g Oct 11 '22 at 12:49
  • IMPORTANT!! => Be sure to edit the correct `php.ini` file, or nothing will make a difference! In my case, I was struggling for 2 days editing the `/etc/php/8.2/cli/php.ini` file, when it should be `/etc/php/8.2/apache2/php.ini`!! Credits to LazyOne in a comment here: https://stackoverflow.com/questions/66178152/xdebug-is-ignoring-breakpoints-in-vscode-trying-to-debug-php-file – Borjovsky Mar 27 '23 at 16:39
6

OS: Windows 10

VS Code marks the breakpoints as "unverified breakpoint".

In my case, i had to add "pathMappings":

"configurations": [{
    ...,
    "pathMappings": {
        "remote/path/to/webroot/": "${workspaceFolder}",
    }
}]

Sidenote when you are working with docker: The remote path is the path inside the docker container.

BenJ1337
  • 109
  • 1
  • 3