The issue is that my source and xdebug (along with php, apache) is in my Vagrant box. I've exposed port 9000 on my vagrant however, when I try to browse the application, the debugger isn't breaking in my code.
PHP version: 5.5
XDebug version: 2.5.0
Adapter version: 0.2.0
Your launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"serverSourceRoot": "/home/vagrant/code/web",
"localSourceRoot": "/Users/deanclarke/vagrant/sammedia/code/web",
"log": true
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"serverSourceRoot": "/home/vagrant/code/web",
"localSourceRoot": "/Users/deanclarke/vagrant/sammedia/code/web",
"port": 9000,
"stopOnEntry":true
}
]
}
XDebug php.ini config:
Version 2.5.0
IDE Key vagrant
Supported protocols Revision
DBGp - Common DeBuGger Protocol $Revision: 1.145 $
Directive Local Value Master Value
xdebug.auto_trace Off Off
xdebug.cli_color 0 0
xdebug.collect_assignments Off Off
xdebug.collect_includes On On
xdebug.collect_params 0 0
xdebug.collect_return Off Off
xdebug.collect_vars Off Off
xdebug.coverage_enable On On
xdebug.default_enable On On
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.extended_info On On
xdebug.file_link_format no value no value
xdebug.force_display_errors Off Off
xdebug.force_error_reporting 0 0
xdebug.halt_level 0 0
xdebug.idekey vagrant vagrant
xdebug.max_nesting_level 256 256
xdebug.max_stack_frames -1 -1
xdebug.overload_var_dump 2 2
xdebug.profiler_aggregate Off Off
xdebug.profiler_append Off Off
xdebug.profiler_enable Off Off
xdebug.profiler_enable_trigger Off Off
xdebug.profiler_enable_trigger_value no value no value
xdebug.profiler_output_dir /tmp /tmp
xdebug.profiler_output_name cachegrind.out.%p cachegrind.out.%p
xdebug.remote_addr_header no value no value
xdebug.remote_autostart On On
xdebug.remote_connect_back Off Off
xdebug.remote_cookie_expire_time 3600 3600
xdebug.remote_enable On On
xdebug.remote_handler dbgp dbgp
xdebug.remote_host localhost localhost
xdebug.remote_log /var/log/xdebug/xdebug.log /var/log/xdebug/xdebug.log
xdebug.remote_mode req req
xdebug.remote_port 9000 9000
xdebug.scream Off Off
xdebug.show_error_trace Off Off
xdebug.show_exception_trace Off Off
xdebug.show_local_vars Off Off
xdebug.show_mem_delta Off Off
xdebug.trace_enable_trigger Off Off
xdebug.trace_enable_trigger_value no value no value
xdebug.trace_format 0 0
xdebug.trace_options 0 0
xdebug.trace_output_dir /tmp /tmp
xdebug.trace_output_name trace.%c trace.%c
xdebug.var_display_max_children 128 128
xdebug.var_display_max_data 512 512
xdebug.var_display_max_depth 3 3
XDebug logfile (from setting xdebug.remote_log in php.ini):
No log file generated.
Adapter logfile (from setting "log": true in launch.json):
<- launchResponse
Response {
seq: 0,
type: 'response',
request_seq: 2,
command: 'launch',
success: true
}
-> disconnectRequest
{
command: 'disconnect',
arguments: { restart: false },
type: 'request',
seq: 3
}
Code snippet to reproduce:
<?php
/**
* @copyright Copyright (C) 2012 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Define required paths
define('JPATH_ROOT', dirname(__DIR__));
define('JPATH_CONFIGURATION', JPATH_ROOT . '/App/Config');
define('JPATH_SETUP', JPATH_ROOT . '/App/Setup');
define('JPATH_TEMPLATES', JPATH_ROOT . '/App/Templates');
// Load the Composer autoloader
require JPATH_ROOT . '/vendor/autoload.php';
$container = new \Joomla\DI\Container;
$container->registerServiceProvider(new \App\Service\ConfigServiceProvider(JPATH_CONFIGURATION . '/config.json'))
->registerServiceProvider(new \App\Service\DatabaseServiceProvider);
// Instantiate the application.
$application = new \App\App($container);
// Execute the application.
$application->execute();
I need the XDebug log
+1
Try xdebug.remote_connect_back = 1
I have the same issue and "xdebug.remote_connect_back = 1" didn't help either
FWIW, I found that passing the parameter XDEBUG_SESSION_START=vscode seems to get the ball rolling. From that point on it just started working for me (for that session).
@tedmasterweb how are you passing that parameter?
As a query string param, e.g.: http://localhost/myproject/?XDEBUG_SESSION_START=vscode
I've even managed to get it to break when using ScotchBox as the server (remote debugging) but I had to modify the json for vscode a bit (but I also have my doubts about how necessary that was).
Figured I could add to this, I'm having trouble getting it to break on breakpoints in vagrant as well. It seems as though it's connecting to xdebug, but when I load a page that has a breakpoint in it it doesn't break, or do much of anything.
PHP version: 5.6
XDebug version: 2.5.1
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9001,
"localSourceRoot": "/usr/src/projects/home/code/",
"serverSourceRoot": "/code/",
"log": true
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
Xdebug .ini config:
[XDebug]
xdebug.default_enable=1
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_port=9001
xdebug.remote_connect_back=1
xdebug.remote_host=10.1.10.209
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
zend_extension = /usr/lib/php5/20131226/xdebug.so
xdebug.remote_log = /tmp/xdebug.log
Xdebug log:
Log opened at 2017-03-27 21:10:48
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: 10.1.10.209:9001. :-|
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///code/scripts/work" language="PHP" xdebug:language_version="5.6.14-1+deb.sury.org~precise+1" protocol_version="1.0" appid="4977"><engine version="2.5.1"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2017 by Derick Rethans]]></copyright></init>
<- breakpoint_list -i 1
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="1"></response>
<- breakpoint_set -i 2 -t line -f file:///code/src/App/Action/Admin/ReportBuilder.php -n 12
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="2" id="49770001"></response>
<- breakpoint_list -i 3
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="3"><breakpoint type="line" filename="file:///code/src/App/Action/Admin/ReportBuilder.php" lineno="12" state="enabled" hit_count="0" hit_value="0" id="49770001"></breakpoint></response>
<- breakpoint_list -i 4
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="4"><breakpoint type="line" filename="file:///code/src/App/Action/Admin/ReportBuilder.php" lineno="12" state="enabled" hit_count="0" hit_value="0" id="49770001"></breakpoint></response>
<- breakpoint_set -i 5 -t exception -x *
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="5" id="49770002"></response>
<- run -i 6
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="run" transaction_id="6" status="stopping" reason="ok"></response>
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="run" transaction_id="6" status="stopping" reason="ok"></response>
Log closed at 2017-03-27 21:21:51
Adapter logfile:
<- launchResponse
Response {
seq: 0,
type: 'response',
request_seq: 2,
command: 'launch',
success: true }
new connection 1
<- threadEvent
ThreadEvent {
seq: 0,
type: 'event',
event: 'thread',
body: { reason: 'started', threadId: 1 } }
<- initializedEvent
InitializedEvent { seq: 0, type: 'event', event: 'initialized' }
-> threadsRequest
{ command: 'threads', type: 'request', seq: 3 }
<- threadsResponse
Response {
seq: 0,
type: 'response',
request_seq: 3,
command: 'threads',
success: true,
body: { threads: [ Thread { id: 1, name: 'Request 1 (5:31:01 PM)' } ] } }
-> setBreakpointsRequest
{ command: 'setBreakpoints',
arguments:
{ source:
{ path: '/usr/src/projects/home/code/src/App/Action/Admin/ReportBuilder.php',
name: 'ReportBuilder.php' },
lines: [ 12 ],
breakpoints: [ { line: 12 } ],
sourceModified: false },
type: 'request',
seq: 4 }
<- setBreakpointsResponse
Response {
seq: 0,
type: 'response',
request_seq: 4,
command: 'setBreakpoints',
success: true,
body: { breakpoints: [ { verified: true, line: 12 } ] } }
-> setFunctionBreakpointsRequest
{ command: 'setFunctionBreakpoints',
arguments: { breakpoints: [] },
type: 'request',
seq: 5 }
<- setFunctionBreakpointsResponse
Response {
seq: 0,
type: 'response',
request_seq: 5,
command: 'setFunctionBreakpoints',
success: true,
body: { breakpoints: [] } }
-> setExceptionBreakpointsRequest
{ command: 'setExceptionBreakpoints',
arguments: { filters: [ '*' ] },
type: 'request',
seq: 6 }
<- setExceptionBreakpointsResponse
Response {
seq: 0,
type: 'response',
request_seq: 6,
command: 'setExceptionBreakpoints',
success: true }
-> configurationDoneRequest
{ command: 'configurationDone', type: 'request', seq: 7 }
The code to reproduce is just any php code in my project, nothing will break on any breakpoints any time I load a page in my browser. It's code for the company I work for though so I can't post it.
I can verify that with these settings for homestead (vagrant), I was able to get breakpoints working:
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"serverSourceRoot": "/home/vagrant/[PROJECT_ROOT]",
"localSourceRoot": "absolute/local/path/to/[PROJECT_ROOT]"
}
]
}
Please note that your localSourceRoot and serverSourceRoot may be different depending on how you set up your mappings.
I'll start Listen for XDebug, then go to any page with the query ?XDEBUG_SESSION_START=vscode, and then I'm able to get breakpoints to work (both with the red dot breakpoint and xdebug_break().
Something the issue reporter has confused, port 9000 is on the localhost where VSCODE is running, not the vagrant guest. XDEBUG in Vagrant needs to connect to host machine, not the other way around. The ip address 10.0.2.2 in vagrant (Virtual Box) will connect to the host machine. https://stackoverflow.com/a/1262143/637783
@jbtule I've always suspected this to be true and yet I'm able to get it to work without specifying the IP address. Could possibly provide an example of your config files to help us understand? TIA.
@tedmasterweb sure.
This is a working config from one of my projects using (XDebug 2.4.1 in my vagrant guest). BTW if the localSourceRoot, and serverSourceRoot aren't correct, XDebug will connect, but the the breakpoints will never break.
VSCode config
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"localSourceRoot": "${workspaceRoot}/src",
"serverSourceRoot": "/my/mapped/directory/in/vagrant/"
}
]
}
Relevant XDebug Config
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 0
xdebug.remote_host = 10.0.2.2
Relevant Vagrant Config
config.vm.synced_folder "src/", "/my/mapped/directory/in/vagrant/"
It sounds like this is just an XDebug configuration issue and not a bug/feature request in the adapter. Any objection to close this?
Could a delta be adding more documentation to the readme specifically about setting up with vagrant?
Sure, feel free to do a PR
Most helpful comment
@tedmasterweb sure.
This is a working config from one of my projects using (XDebug 2.4.1 in my vagrant guest). BTW if the
localSourceRoot, andserverSourceRootaren't correct, XDebug will connect, but the the breakpoints will never break.VSCode config
Relevant XDebug Config
Relevant Vagrant Config