Search code examples
phpvisual-studio-codexamppxdebug

Xdebug not stopping at breakpoints


Xdebug does not stop at breakpoints.

I tried different versions of Xdebug. (current v1.32.1, v1.32.0, v1.31.1, v1.31.0, v1.30.0)

This is my configuration at the 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": 9003
    },
    {
        "name": "Launch currently open script",
        "type": "php",
        "request": "launch",
        "program": "${file}",
        "cwd": "${fileDirname}",
        "port": 0,
        "runtimeArgs": [
            "-dxdebug.start_with_request=yes"
        ],
        "env": {
            "XDEBUG_MODE": "debug,develop",
            "XDEBUG_CONFIG": "client_port=${port}"
        }
    },
    {
        "name": "Launch Built-in web server",
        "type": "php",
        "request": "launch",
        "runtimeArgs": [
            "-dxdebug.mode=debug",
            "-dxdebug.start_with_request=yes",
            "-S",
            "localhost:0"
        ],
        "program": "",
        "cwd": "${workspaceRoot}",
        "port": 9003,
        "serverReadyAction": {
            "pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
            "uriFormat": "http://localhost:%s",
            "action": "openExternally"
        }
    }
]}

Could there be a conflict with the web server?

This is my configuration in the php.ini (all the way at the bottom of the file):

[xdebug]
zend_extension=C:\xampp\php\ext\php_xdebug.dll
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_port = 9003        // it also doesnt work without this line.

Installation Wizard

Summary from <https://xdebug.org/wizard> 

    • Xdebug installed: 3.2.1
    • Server API: Apache 2.0 Handler
    • Windows: yes 
    • Compiler: MS VS16
    • Architecture: x64
    • Zend Server: no 
    • PHP Version: 8.2.4
    • Zend API nr: 420220829
    • PHP API nr: 20220829
    • Debug Build: no
    • Thread Safe Build: yes
    • OPcache Loaded: no
    • Configuration File Path: no value
    • Configuration File: C:\xampp\php\php.ini
    • Extensions directory: C:\xampp\php\ext

enter image description here

enter image description here

enter image description here

enter image description here

I've downloaded the file from the wizard and renamed it correctly.

Port 9003 is correct according to the documentation. But I also tried port 9000 as well.

If I go to https://portchecker.co/checking and check for Port 9000 or 9003 they are closed.

  • I reinstalled XAMPP
  • I reinstalled VS Code

I also went to Settings -> Features -> Debug -> Allow Breakpoints Everywhere.


Solution

  • I went ahead and installed xampp and xdebug.

    Our launch.json files and wizard output are identical and it seems to work ok for me.

    My php.ini doesn't include the last line with the port number or the apostrophe after the xdebug closing brace that you have.

    [xDebug]
    zend_extension = xdebug
    xdebug.mode = debug
    xdebug.start_with_request = yes
    

    You shouldn't need the entire file path for your zend_extension considering that the extensions directory is already mapped for you.

    I would double check that you've defined your "php.debug.executablePath": in vscode settings as well.

    Here's what mine looks like after

    1. Running Listen for Xdebug in vscode
    2. Navigating to the file I used here at http://localhost/info/index.php in the browser

    Xdebug Running

    If making those changes still doesn't work, maybe double check that the breakpoint is actually reachable.