1 year ago
#375525
atomey
Unable to run Xdebug from browser with Apache but works in PHP CLI
I am working in an old PHP 5.4.16 environment on CentOS 7.9. I am trying to run Xdebug 2.4.1 with the PHP Debug extension in VSCode. I was able to get debugs to run remotely to my VSCode with the following launch.json config:
{
"name": "Listen for Xdebug",
"type": "php",
"hostname": "dev-internal.contoso.com",
"request": "launch",
"stopOnEntry": true,
"port": 9000,
"log": true,
"pathMappings": {
"/var/www/html": "${workspaceRoot}/",
}
}
I am running under an SSL VPN to connect to the web server with PHP. For some reason I can get debug information when I run scripts directly on the server with CLI, like php index.php
. However if I initiate the request with a browser and use an extension, which sets the XDEBUG_SESSION
to XDEBUG_SESSION=XDEBUG_ECLIPSE
, I never get a response in the debugger.
This is what my PHP.ini looks like:
zend_extension="/opt/remi/php54/root/usr/lib64/php/modules/xdebug.so"
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_port = 9000
xdebug.remote_connect_back = 1
;Disable connect_back if using remote_host
;xdebug.remote_host = 10.212.129.201
xdebug.log = /var/log/httpd/xdebug.log
xdebug.remote_log = /var/log/httpd/xdebug_remote.log
I can't seem to get it to with or without remote_host
set. I also confirmed _SERVER["REMOTE_ADDR"]
is set to the remote network's (of the web server) gateway IP address. The VPN client I am making requests from should come from 10.212.129.201 but Apache sees it as 192.168.21.1. I can ping 10.212.129.201 from the Apache server.
Ideally I am trying to get remote_connect_back
to work so I can have two developers work on this over the VPN simultaneously. Also noticed that even when I can debug with the CLI, I can't step into functions.
Update: Per LazyOne, I ran your php script in the CLI and got the script to run in my local Vscode. The output for xdebug_remote.log
Log opened at 2022-04-05 14:14:11
I: Checking remote connect back address.
I: Checking header 'HTTP_X_FORWARDED_FOR'.
I: Checking header 'REMOTE_ADDR'.
W: Remote address not found, connecting to configured address/port: localhost:9000. :-|
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///var/www/html/test.php" language="PHP" xdebug:language_version="5.4.45" protocol_version="1.0" appid="21459" idekey="root"><engine version="2.4.1"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2016 by Derick Rethans]]></copyright></init>
<- feature_get -i 1 -n resolved_breakpoints
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="feature_get" transaction_id="1" feature_name="resolved_breakpoints" supported="0"><![CDATA[0]]></response>
<- feature_get -i 2 -n notify_ok
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="feature_get" transaction_id="2" feature_name="notify_ok" supported="0"><![CDATA[0]]></response>
<- feature_get -i 3 -n extended_properties
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="feature_get" transaction_id="3" feature_name="extended_properties" supported="0"><![CDATA[0]]></response>
<- step_into -i 4
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="step_into" transaction_id="4" status="break" reason="ok"><xdebug:message filename="file:///var/www/html/test.php" lineno="1"></xdebug:message></response>
<- stack_get -i 5
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="stack_get" transaction_id="5"><stack where="{main}" level="0" type="file" filename="file:///var/www/html/test.php" lineno="1"></stack></response>
<- context_names -i 6 -d 0
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="context_names" transaction_id="6"><context name="Locals" id="0"></context><context name="Superglobals" id="1"></context><context name="User defined constants" id="2"></context></response>
<- context_get -i 7 -d 0 -c 0
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="context_get" transaction_id="7" context="0"><property name="$a" fullname="$a" type="uninitialized"></property><property name="$b" fullname="$b" type="uninitialized"></property><property name="$c" fullname="$c" type="uninitialized"></property></response>
<- context_names -i 8 -d 0
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="context_names" transaction_id="8"><context name="Locals" id="0"></context><context name="Superglobals" id="1"></context><context name="User defined constants" id="2"></context></response>
<- property_get -i 9 -d 0 -c 0 -n "$a"
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="property_get" transaction_id="9" status="break" reason="ok"><error code="300"><message><![CDATA[can not get property]]></message></error></response>
This is the output from the debug console in VSCode:
-> evaluateRequest
{
command: 'evaluate',
arguments: { expression: '$a', frameId: 1, context: 'hover' },
type: 'request',
seq: 12
}
xd(1) <- context_names -i 8 -d 0
xd(1) -> <?xml version="1.0" encoding="iso-8859-1"?><response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="context_names" transaction_id="8"><context name="Locals" id="0"></context><context name="Superglobals" id="1"></context><context name="User defined constants" id="2"></context></response>
xd(1) <- property_get -i 9 -d 0 -c 0 -n "$a"
xd(1) -> <?xml version="1.0" encoding="iso-8859-1"?><response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="property_get" transaction_id="9" status="break" reason="ok"><error code="300"><message><![CDATA[can not get property]]></message></error></response>
<- evaluateResponse
Response {
seq: 0,
type: 'response',
request_seq: 12,
command: 'evaluate',
success: false,
message: 'can not get property'
}
Also to be clear VSCode PHPDebug plugin has a connection to the server, this is how it connects on "localhost", see log OUTPUT in VSCode:
[07:14:00.098] Remote server is listening on 40562
[07:14:00.098] Parsed server configuration: {"serverConfiguration":{"remoteListeningOn":{"port":40562},"osReleaseId":"centos","arch":"x86_64","webUiAccessToken":"","sshAuthSock":"","display":"","tmpDir":"/run/user/0","platform":"linux","connectionToken":"11aa11aa-1aa1-1aa1-a111-111a11aaa1a1"},"serverStartTime":118,"installUnpackCode":""}
[07:14:00.099] Starting forwarding server. localPort 65166 -> socksPort 65156 -> remotePort 40562
[07:14:00.100] Forwarding server listening on 65166
[07:14:00.100] Waiting for ssh tunnel to be ready
[07:14:00.101] [Forwarding server 65166] Got connection 0
[07:14:00.101] Tunneled 40562 to local port 65166
[07:14:00.101] Resolved "ssh-remote+spos-dev" to "127.0.0.1:65166"
[07:14:00.106] ------
[07:14:00.115] [Forwarding server 65166] Got connection 1
[07:14:00.123] >
[07:14:00.363] [Forwarding server 65166] Got connection 2
If you run a netstat on the Apache/PHP/Xdebug server you'll see:
tcp 0 0 127.0.0.1:37936 127.0.0.1:40562 ESTABLISHED 21108/sshd: root@no
tcp 0 0 127.0.0.1:37528 127.0.0.1:9000 TIME_WAIT -
tcp 0 0 127.0.0.1:37604 127.0.0.1:9000 ESTABLISHED 21602/php
tcp 0 0 192.168.21.249:22 192.168.21.1:65102 ESTABLISHED 20976/sshd: root@pt
tcp 0 0 127.0.0.1:40562 127.0.0.1:37936 ESTABLISHED 21182/node
tcp 0 0 127.0.0.1:40562 127.0.0.1:37938 ESTABLISHED 21262/node
tcp 0 0 192.168.21.249:22 192.168.21.1:65158 ESTABLISHED 21108/sshd: root@no
tcp 0 0 192.168.21.249:22 192.168.21.1:65101 ESTABLISHED 20974/sshd: root@pt
tcp 0 0 127.0.0.1:37938 127.0.0.1:40562 ESTABLISHED 21108/sshd: root@no
tcp 0 0 127.0.0.1:9000 127.0.0.1:37604 ESTABLISHED 21448/node
tcp6 0 0 192.168.21.249:443 192.168.21.1:59548 FIN_WAIT2 -
tcp6 0 0 192.168.21.249:443 192.168.21.1:59547 FIN_WAIT2 -
tcp6 0 0 192.168.21.249:443 192.168.21.1:59549 FIN_WAIT2 -
tcp6 0 0 192.168.21.249:443 192.168.21.1:59550 TIME_WAIT -
php
apache
visual-studio-code
xdebug
0 Answers
Your Answer