1

I'm trying to debug my app in a remote server.

The remote server is a QNAP NAS, runs Apache and has Xdebug installed.

99-xdebug.ini

[xDebug]
extension = xdebug
xdebug.mode = debug,develop
xdebug.remote_handler = "dbgp"
xdebug.remote_cookie_expire_time = 36000
xdebug.start_with_request=trigger
xdebug.client_host = 192.168.1.29
xdebug.client_port = 9003
xdebug.show_exception_trace=false
xdebug.log = /tmp/xdebug.log
xdebug.log_level=10
xdebug.trigger_value=DavidDebugando
xdebug.idekey=vsc

This is my 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": "Local listen for Xdebug",
      "type": "php",
      "request": "launch",
      "port": 9003,
      "xdebugSettings": {
        "max_children": 128,
        "max_data": -1,
        "max_depth": 3
      },
    },
    {
      "name": "Remote listen for Xdebug",
      "type": "php",
      "request": "launch",
      "port": 9003,
      "xdebugSettings": {
        "max_children": 128,
        "max_data": -1,
        "max_depth": 3
      },
      "pathMappings": {
        // "file:///share/ZFS2_DATA/Web/dolibarr-pruebas": "${workspaceFolder}",
        "/share/ZFS2_DATA/Web/dolibarr-pruebas": "${workspaceFolder}"
        },
    },
    {
      "name": "Launch currently open script",
      "type": "php",
      "request": "launch",
      "program": "${file}",
      "cwd": "${fileDirname}",
      "port": 9003,
      "xdebugSettings": {
        "max_children": 128,
        "max_data": -1,
        "max_depth": 3
      }
    }
  ]
}

And this is my /tmp/xdebug.log

[23080] Log opened at 2024-09-17 10:32:54.365243
[23080] [Config] DEBUG: Checking if trigger 'XDEBUG_TRIGGER' is enabled for mode 'debug'
[23080] [Config] DEBUG: The trigger value 'DavidDebugando' matched the shared secret 'DavidDebugando' for mode 'debug'
[23080] [Step Debug] INFO: Connecting to configured address/port: 192.168.1.29:9003.
[23080] [Step Debug] INFO: Connected to debugging client: 192.168.1.29:9003 (through xdebug.client_host/xdebug.client_port). :-)
[23080] [Step Debug] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///share/ZFS2_DATA/Web/dolibarr-pruebas/htdocs/custom/phpinfo.php" language="PHP" xdebug:language_version="7.4.30" protocol_version="1.0" appid="23080" idekey="DavidDebugando"><engine version="3.1.6"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2022 by Derick Rethans]]></copyright></init>

[23080] [Step Debug] <- feature_set -i 1 -n resolved_breakpoints -v 1
[23080] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="1" feature="resolved_breakpoints" success="1"></response>

[23080] [Step Debug] <- feature_set -i 2 -n notify_ok -v 1
[23080] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="2" feature="notify_ok" success="1"></response>

[23080] [Step Debug] <- feature_set -i 3 -n extended_properties -v 1
[23080] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="3" feature="extended_properties" success="1"></response>

[23080] [Step Debug] <- feature_get -i 4 -n breakpoint_include_return_value
[23080] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_get" transaction_id="4" feature_name="breakpoint_include_return_value" supported="0"><![CDATA[0]]></response>

[23080] [Step Debug] <- feature_set -i 5 -n max_children -v 128
[23080] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="5" feature="max_children" success="1"></response>

[23080] [Step Debug] <- feature_set -i 6 -n max_data -v -1
[23080] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="6" feature="max_data" success="1"></response>

[23080] [Step Debug] <- feature_set -i 7 -n max_depth -v 3
[23080] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="7" feature="max_depth" success="1"></response>

[23080] [Step Debug] <- breakpoint_set -i 8 -t line -f file:///share/ZFS2_DATA/Web/dolibarr-pruebas/htdocs/custom/phpinfo.php -n 3
[23080] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="8" id="230800002" resolved="unresolved"></response>

[23080] [Step Debug] <- run -i 9
[23080] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="run" transaction_id="9" status="stopping" reason="ok"></response>

[23080] [Step Debug] <- stop -i 10
[23080] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="stop" transaction_id="10" status="stopped" reason="ok"></response>

[23080] Log closed at 2024-09-17 10:32:54.415959

When I debug locally, after breakpoint_set, I see

[1040] [Step Debug] <- run -i 11
[1040] [Step Debug] DEBUG: Checking whether to break on C:\xampp7\htdocs\Dolibarr16.0.3\htdocs\custom\phpinfo.php:3.
[1040] [Step Debug] DEBUG: I: Current location: C:\xampp7\htdocs\Dolibarr16.0.3\htdocs\custom\phpinfo.php:3.
[1040] [Step Debug] DEBUG: I: Matching breakpoint 'C:\xampp7\htdocs\Dolibarr16.0.3\htdocs\custom\phpinfo.php:3' against location 'C:\xampp7\htdocs\Dolibarr16.0.3\htdocs\custom\phpinfo.php:3'.
[1040] [Step Debug] DEBUG: F: File names match (C:\xampp7\htdocs\Dolibarr16.0.3\htdocs\custom\phpinfo.php).
[1040] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="run" transaction_id="11" status="break" reason="ok"><xdebug:message filename="file:///C:/xampp7/htdocs/Dolibarr16.0.3/htdocs/custom/phpinfo.php" lineno="3"></xdebug:message></response>

But as you can see this doesn't happen in the remote log.

I have no idea why this is happening. Are my pathMappings correct?

'xdebug_info()' output

Version 3.1.6
Support Xdebug on Patreon, GitHub, or as a business
Enabled Features
(through 'xdebug.mode' setting)
Feature Enabled/Disabled    Docs
Development Helpers ✔ enabled   
Coverage    ✘ disabled  
GC Stats    ✘ disabled  
Profiler    ✘ disabled  
Step Debugger   ✔ enabled   
Tracing ✘ disabled  
Optional Features
Compressed File Support no
Clock Source    clock_gettime
Diagnostic Log
Message Docs
⚠️  [Step Debug] Debug client detached: "dbgpProxy has no IDE connected to it". 
Step Debugging  Docs
Debugger    Detached    
Connected Client    127.0.0.1:9003   
Detached    "dbgpProxy has no IDE connected to it"   
PHP
Build Configuration
Version (Run Time)  7.4.30
Version (Compile Time)  7.4.33
Debug Build no
Thread Safety   disabled
Settings
Configuration File (php.ini) Path   /usr/local/etc/php
Loaded Configuration File   /mnt/HDA_ROOT/.config/php.ini
Scan this dir for additional .ini files /etc/config/php.d
Additional .ini files parsed    /etc/config/php.d/99-xdebug.ini, /etc/config/php.d/ext.ini, /etc/config/php.d/php_ext.ini
Directive   Local Value Master Value    Docs
xdebug.cli_color    0   0   
xdebug.client_discovery_header  no value    no value    
xdebug.client_host  127.0.0.1   127.0.0.1   
xdebug.client_port  9003    9003    
xdebug.cloud_id no value    no value    
xdebug.collect_assignments  Off Off 
xdebug.collect_return   Off Off 
xdebug.connect_timeout_ms   200 200 
xdebug.discover_client_host 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.file_link_format no value    no value    
xdebug.filename_format  no value    no value    
xdebug.force_display_errors Off Off 
xdebug.force_error_reporting    0   0   
xdebug.gc_stats_output_name gcstats.%p  gcstats.%p  
xdebug.halt_level   0   0   
xdebug.idekey   vsc vsc 
xdebug.log  /tmp/xdebug.log /tmp/xdebug.log 
xdebug.log_level    10  10  
xdebug.max_nesting_level    256 256 
xdebug.max_stack_frames -1  -1  
xdebug.mode debug,develop   debug,develop   
xdebug.output_dir   /tmp    /tmp    
xdebug.profiler_append  Off Off 
xdebug.profiler_output_name cachegrind.out.%p   cachegrind.out.%p   
xdebug.scream   Off Off 
xdebug.show_error_trace Off Off 
xdebug.show_exception_trace Off Off 
xdebug.show_local_vars  Off Off 
xdebug.start_upon_error default default 
xdebug.start_with_request   trigger trigger 
xdebug.trace_format 0   0   
xdebug.trace_options    0   0   
xdebug.trace_output_name    trace.%c    trace.%c    
xdebug.trigger_value    DavidDebugando  DavidDebugando  
xdebug.use_compression  0   0   
xdebug.var_display_max_children 128 128 
xdebug.var_display_max_data 512 512 
xdebug.var_display_max_depth    3   3   

Switched to dbgpProxy thinking it would help since I'm WFH right now and using Wireguard.

2024-09-18 11:36:16.535 [info] [server] Start new client connection from 198.18.7.15:48472
2024-09-18 11:36:17.049 [info] [proxyinit] [DavidDebugando] Added connection for IDE Key 'DavidDebugando': 198.18.7.15:9003
2024-09-18 11:36:17.049 [info] [server] Closing client connection from 198.18.7.15:48472
2024-09-18 11:36:20.928 [info] [server] Start new server connection from 127.0.0.1:53470
2024-09-18 11:36:20.928 [info] [proxy-client] [DavidDebugando] Found connection for IDE Key 'DavidDebugando': 198.18.7.15:9003
2024-09-18 11:36:20.928 [info] [proxy-client] [DavidDebugando] Connecting to 198.18.7.15:9003
2024-09-18 11:38:32.590 [err ] [proxy-client] [DavidDebugando] IDE not connected: dial tcp 198.18.7.15:9003: connect: connection timed out
2024-09-18 11:38:32.590 [warn] [proxy-client] [DavidDebugando] Removed connection information for 'DavidDebugando': dial tcp 198.18.7.15:9003: connect: connection timed out
2024-09-18 11:38:32.590 [warn] [server] Handler response error: Error reading response: Error reading length: EOF
2024-09-18 11:38:32.590 [info] [server] Closing server connection from 127.0.0.1:53470
2024-09-18 11:40:07.288 [info] [server] Start new server connection from 127.0.0.1:53620
2024-09-18 11:40:07.289 [info] [proxy-client] [DavidDebugando] Could not find IDE connection for IDE Key 'DavidDebugando'
2024-09-18 11:40:07.289 [warn] [server] Handler response error: Error reading response: Error reading length: EOF
2024-09-18 11:40:07.289 [info] [server] Closing server connection from 127.0.0.1:53620

Testing back at the office

  • C:\xampp7\htdocs\Dolibarr16.0.3\htdocs\xdebug_test.php
  • /share/ZFS2_DATA/Web/dolibarr-pruebas/htdocs/xdebug_test.php
<?php
$a=1;
$b=3;
$c=$a + $b;
xdebug_break();
echo $c, "\n";

[16879] Log opened at 2024-09-20 06:48:16.731443
[16879] [Config] DEBUG: Checking if trigger 'XDEBUG_TRIGGER' is enabled for mode 'debug'
[16879] [Config] DEBUG: The trigger value 'DavidDebugando' matched the shared secret 'DavidDebugando' for mode 'debug'
[16879] [Step Debug] INFO: Checking remote connect back address.
[16879] [Step Debug] INFO: Checking header 'HTTP_X_FORWARDED_FOR'.
[16879] [Step Debug] INFO: Checking header 'REMOTE_ADDR'.
[16879] [Step Debug] INFO: Client host discovered through HTTP header, connecting to 192.168.1.29:9003.
[16879] [Step Debug] INFO: Connected to debugging client: 192.168.1.29:9003 (from REMOTE_ADDR HTTP header). :-)
[16879] [Step Debug] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///share/ZFS2_DATA/Web/dolibarr-pruebas/htdocs/xdebug_test.php" language="PHP" xdebug:language_version="7.4.30" protocol_version="1.0" appid="16879" idekey="DavidDebugando"><engine version="3.1.6"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2022 by Derick Rethans]]></copyright></init>

[16879] [Step Debug] <- feature_set -i 1 -n resolved_breakpoints -v 1
[16879] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="1" feature="resolved_breakpoints" success="1"></response>

[16879] [Step Debug] <- feature_set -i 2 -n notify_ok -v 1
[16879] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="2" feature="notify_ok" success="1"></response>

[16879] [Step Debug] <- feature_set -i 3 -n extended_properties -v 1
[16879] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="3" feature="extended_properties" success="1"></response>

[16879] [Step Debug] <- feature_get -i 4 -n breakpoint_include_return_value
[16879] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_get" transaction_id="4" feature_name="breakpoint_include_return_value" supported="0"><![CDATA[0]]></response>

[16879] [Step Debug] <- feature_set -i 5 -n max_children -v 128
[16879] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="5" feature="max_children" success="1"></response>

[16879] [Step Debug] <- feature_set -i 6 -n max_data -v -1
[16879] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="6" feature="max_data" success="1"></response>

[16879] [Step Debug] <- feature_set -i 7 -n max_depth -v 3
[16879] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="7" feature="max_depth" success="1"></response>

[16879] [Step Debug] <- breakpoint_set -i 8 -t line -f file:///share/ZFS2_DATA/Web/dolibarr-pruebas/htdocs/xdebug_test.php -n 4
[16879] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="8" id="168790003" resolved="unresolved"></response>

[16879] [Step Debug] <- run -i 9
[16879] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="run" transaction_id="9" status="stopping" reason="ok"></response>

[16879] [Step Debug] <- stop -i 10
[16879] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="stop" transaction_id="10" status="stopped" reason="ok"></response>

[16879] Log closed at 2024-09-20 06:48:16.774053

Checked this, due to this opcache is loaded first, then xdebug, so it shouldn't be a problem.

12
  • 1) Sounds like path mappings issue to me TBH. What is the path for the project root, locally (the folder that VSCode opened)? 2) Are the files are the same (local and remote). Asking because the remote breakpoint states resolved="unresolved". Considering that the file path seems to be OK (as per your log, unless you have edited the file paths before posting it here), it could be that it simply has less than 3 lines .. or it is empty there. Commented Sep 18, 2024 at 9:14
  • workspaceFolder = 'C:\xampp7\htdocs\Dolibarr16.0.3' path mappings should point to the same root on local and remote (Excluding the mapping part both are left with /htdocs/custom/phpinfo.php) are line endings a problem if local OS is W11 and remote is linux? Commented Sep 18, 2024 at 11:16
  • 1) OK. So the path mappings looks OK to me at a quick glance (I see nothing obviously wrong here as per my experience). 2) Line ending should not matter -- PHP handles both Linux and Windows line endings just fine (especially if it runs on Windows). But it makes sense to stick to Linux endings (LF) regardless of the OS used -- definitely safer with VCS/diffs. So if the file uses CRLF, switch to LF and re-deploy. Commented Sep 18, 2024 at 11:44
  • Maybe it's something else... 1) Can you restart your remote server? 2) try another test file -- e.g. xdebug-test.php and have it directly in the website root; 3) Just a thought -- maybe your framework/web server interfere here somehow? try having a single test file on a website -- any difference? 4) post the whole output of the xdebug_info() -- maybe it will show some difference in the settings (captured in the same way you are trying to debug -- a web page or CLI) Commented Sep 18, 2024 at 11:47
  • 1
    The only idea that I can spot right now -- it should be zend_extension=xdebug while you have just extension. Double check that. Double-check with php -m -- where xdebug is listed (which group). Commented Sep 20, 2024 at 9:13

1 Answer 1

1

In phpinfo.php I saw the warning "XDEBUG NOT LOADED AS ZEND EXTENSION." I ignored it at first since it was just a warning and not an error.

Xdebug wasn't stopping at breakpoints because I had loaded Xdebug using extension=xdebug.so in my 99-xdebug.ini.

Xdebug needs to be loaded as a Zend extension, so the correct way to load it is with zend_extension=xdebug.so. Once I made that change, breakpoints started working.

Thanks to @LazyOne

Wrong: enter image description here enter image description here

Right: enter image description here enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

If anyone else is in Qnap like me, the php binary is on /mnt/ext/opt/apache/bin/php and /mnt/ext/opt/apache/bin/php -v does show the warning PHP Warning: Xdebug MUST be loaded as a Zend extension in Unknown on line 0, I wish it was an error and not a warning though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.