skip to Main Content

Using VSCode, when I put a breakpoint in a PHP file, start the debugger and click the Run and Debug button, debugging works as expected. Execution stops on the breakpoint and information is shown in the left side bar. But when I initiate the same process using the "Listen for Xdebug" dropdown (after creating the launch.json file as described below) and then reload the PHP file in question in my browser, the breakpoint is ignored and the webpage loads. In the past when this was working, reloading the page would trigger debugging, but after I reinstalled VSCode and WinNMP, something has changed and I don’t know what.

I installed Xdebug using https://xdebug.org/wizard, and followed the instructions:

Download php_xdebug-3.1.5-8.0-vs16-nts-x86_64.dll
Move the downloaded file to ext, and rename it to php_xdebug.dll
Update D:winnmpconfphp.ini and add the line:
zend_extension = xdebug
Restart the webserver

My Xdebug PHP.INI is:

  zend_extension = xdebug
  xdebug.mode = debug

I added the xdebug.mode line since that’s what Xdebug instructs to get step debugging.

I deleted a prior launch.json file that was there, and For the launch.json, I clicked on Run > Add Configuration > PHP Listen for Xdebug, which generated this launch.json;

{
    "configurations": [
    {
        "name": "Listen for Xdebug",
        "type": "php",
        "request": "launch",
        "port": 9003
    }
    ]
}

I’m using Firefox Developer as my browser. Refreshing a webpage that I’ve opened in VSCode and with a breakpoint set has no effect on the debugging in VSCode. I’ve tried launching Firefox in the CMD window:

"C:Program FilesFirefox Developer Editionfirefox.exe" -start-debugger-server

and there is no difference. I changed the launch.json to:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Attach to Firefox",
            "type": "firefox",
            "request": "attach"
        }
    ]
}

and debugging isn’t affected.

I’ve installed several Firefox extensions, in turn, Xdebug-helper, Xdebug-ext, and Zend-debugger Toolbar. None of them had any effect. What DID have some effect was installing the VSCode extension, Debugger for Firefox. In the extension’s options I set the Port to 9003 and entered the absolute path for firefox.exe. After doing this, when I start the debugger, Firefox asks for permission to connect to the remote debugger. I click yes, but then the breakpoint becomes an open gray circle, and, if I refresh the webpage, debugging doesn’t occur.

Here is the print out from xdebug_info(). Debugger = Not Active seems wrong, but I don’t know what to do with that if it is actually something wrong.


Version     3.1.5
Support Xdebug on Patreon, GitHub, or as a business
Enabled Features
(through 'xdebug.mode' setting)
Feature Enabled/Disabled    Docs
Development Helpers ✘ disabled  🖹
Coverage    ✘ disabled  🖹
GC Stats    ✘ disabled  🖹
Profiler    ✘ disabled  🖹
Step Debugger   ✔ enabled   🖹
Tracing ✘ disabled  🖹
Optional Features
Compressed File Support     yes (gzip)
Clock Source    GetSystemTimePreciseAsFileTime
Diagnostic Log
No messages
Step Debugging  Docs
Debugger    Not Active  🖹
PHP
Build Configuration
Version (Run Time)  8.0.11
Version (Compile Time)  8.0.19
Debug Build     no
Thread Safety   disabled
Settings
Configuration File (php.ini) Path   no value
Loaded Configuration File   D:winnmpconfphp.ini
Scan this dir for additional .ini files     (none)
Additional .ini files parsed    (none)
Directive   Local Value Master Value    Docs
xdebug.mode debug   debug   🖹
xdebug.start_with_request   default default 🖹
xdebug.start_upon_error default default 🖹
xdebug.output_dir   C:WindowsTemp C:WindowsTemp 🖹
xdebug.use_compression  1   1   🖹
xdebug.trigger_value    no value    no value    🖹
xdebug.file_link_format no value    no value    🖹
xdebug.filename_format  no value    no value    🖹
xdebug.log  no value    no value    🖹
xdebug.log_level    7   7   🖹
xdebug.var_display_max_children 128 128 🖹
xdebug.var_display_max_data 512 512 🖹
xdebug.var_display_max_depth    3   3   🖹
xdebug.max_nesting_level    256 256 🖹
xdebug.cli_color    0   0   🖹
xdebug.force_display_errors Off Off 🖹
xdebug.force_error_reporting    0   0   🖹
xdebug.halt_level   0   0   🖹
xdebug.max_stack_frames -1  -1  🖹
xdebug.show_error_trace Off Off 🖹
xdebug.show_exception_trace Off Off 🖹
xdebug.show_local_vars  Off Off 🖹
xdebug.dump.COOKIE  no value    no value    🖹
xdebug.dump.ENV no value    no value    🖹
xdebug.dump.FILES   no value    no value    🖹
xdebug.dump.GET no value    no value    🖹
xdebug.dump.POST    no value    no value    🖹
xdebug.dump.REQUEST no value    no value    🖹
xdebug.dump.SERVER  no value    no value    🖹
xdebug.dump.SESSION no value    no value    🖹
xdebug.dump_globals On  On  🖹
xdebug.dump_once    On  On  🖹
xdebug.dump_undefined   Off Off 🖹
xdebug.profiler_output_name cachegrind.out.%p   cachegrind.out.%p   🖹
xdebug.profiler_append  Off Off 🖹
xdebug.cloud_id no value    no value    🖹
xdebug.client_host  localhost   localhost   🖹
xdebug.client_port  9003    9003    🖹
xdebug.discover_client_host Off Off 🖹
xdebug.client_discovery_header  no value    no value    🖹
xdebug.idekey   no value    no value    🖹
xdebug.connect_timeout_ms   200 200 🖹
xdebug.scream   Off Off 🖹
xdebug.gc_stats_output_name gcstats.%p  gcstats.%p  🖹
xdebug.trace_output_name    trace.%c    trace.%c    🖹
xdebug.trace_format 0   0   🖹
xdebug.trace_options    0   0   🖹
xdebug.collect_assignments  Off Off 🖹
xdebug.collect_return   Off Off 🖹

3

Answers


  1. Chosen as BEST ANSWER

    Solved it! (in a way). I don't know why my XDebug configuration wouldn't work with PHP 8, but I was able to retrieve a configuration (thanks to recent cloud versioning backup software I installed) using PHP 7.4. So here are the settings that give me glorious step debugging in VSCode by refreshing the page in any browser. I'm going to experiment and see if I can make this apply to PHP 8, but for now all is good. I checked the php_xdebug.dll I had with file compare software and verified that it is the one listed here.

    XDebug DLL:

    php_xdebug-3.1.5-7.4-vc15-nts-x86_64.dll
    

    Php.ini:

    zend_extension = "php_xdebug.dll"
    xdebug.mode = debug
    xdebug.discover_client_host = 1
    xdebug.start_with_request = yes
    xdebug.client_port = 9000
    

    Launch.json:

    
        "version": "0.2.0",
        "configurations": [
    
            {
                "name": "Listen for Xdebug",
                "type": "php",
                "request": "launch",
                "port": 9000
            }
           
        ]
    }
    

    Installed VS Code Extensions (if it matters):

    Bookmarks, Live SAAS Compiler, Local History, PHP Debug, Prettier-Code formatter, Rainbow Brackets, Trailing Spaces.
    

    Settings.json (if it matters):

    {
    }
    

  2. The php.ini and launch.json settings noted above do work with PHP 8 (8.0.11) and the XDebug.dll:

    php_xdebug-3.1.5-8.0-vs16-nts-x86_64.dll
    

    Note that the instructions provided at https://xdebug.org/wizard say:

    Update D:winnmpconfphp.ini to have the line:
    zend_extension = xdebug
    

    This is quite different from the lines that were needed in my installation (WinNMP– https://winnmp.wtriple.com/) in order to have success.

    Login or Signup to reply.
  3. Nothing was working in my case because i have to change ports from default 9003.
    So, First i change my port in launch.json file

    "version": "0.2.0",
        "configurations": [
            {
                "name": "Listen for Xdebug",
                "type": "php",
                "request": "launch",
                "port": 11011
            },
    

    In php.ini file

    zend_extension = xdebug //Remember this is your file name which you downloaded
    xdebug.mode = debug,develop
    xdebug.discover_client_host = yes
    xdebug.log_level = 0
    xdebug.log = "C:WINDOWStemplog.txt"
    xdebug.client_port = 11011
    xdebug.start_with_request = yes
    xdebug.idekey = VSCODE
    

    Don’t forget to restart your server and verify all these configurations in your browser by phpinfo().

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search