Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Homestead Laravel Xdebug #220

Closed
alexalp opened this issue Dec 27, 2017 · 22 comments
Closed

Homestead Laravel Xdebug #220

alexalp opened this issue Dec 27, 2017 · 22 comments
Labels
remote debugging All issues related to debugging a remote host (server, VM, Docker container, ...)

Comments

@alexalp
Copy link

alexalp commented Dec 27, 2017

Hi there,

I can't figure out Xdebug to work with VSCode and Laravel/Homestead. I spent a lot of hours trying to fix it. What i'm doing wrong? Thanks for the help guys.

XDebug logfile:
Log opened at 2017-12-27 18:05:11
I: Checking remote connect back address.
I: Checking header 'HTTP_X_FORWARDED_FOR'.
I: Checking header 'REMOTE_ADDR'.
I: Remote address found, connecting to 192.168.10.1:9000.
E: Time-out connecting to client. :-(
Log closed at 2017-12-27 18:05:12

Log opened at 2017-12-27 18:05:13
I: Checking remote connect back address.
I: Checking header 'HTTP_X_FORWARDED_FOR'.
I: Checking header 'REMOTE_ADDR'.
I: Remote address found, connecting to 192.168.10.1:9000.
E: Time-out connecting to client. :-(
Log closed at 2017-12-27 18:05:13`

PHP version:
cattura

XDebug version: v2.5.5
Vagrant version: 2.0.1
Virtualbox version: 5.2.2
Laravel version: 5.5.26
vscode-php-debug version: 1.12.1
My PC: Windows 10
Index.php location on my PC: D:\Project\Project\public
Homestead config file:
cattura1

Your launch.json:
cattura2

XDebug php.ini(20-xdebug.ini) config, loaded as additional .ini in /etc/php/7.1/fpm/conf.d/20-xdebug.ini
cattura3
10.0.2.2 comes from this command: netstat -rn | grep "^0.0.0.0 " | cut -d " " -f10

Adapter logfile when debug start:
<- launchResponse
Response {
seq: 0,
type: 'response',
request_seq: 2,
command: 'launch',
success: true }

Adapter logfile when I stop manually the debug:
-> disconnectRequest
{ command: 'disconnect',
arguments: { restart: false },
type: 'request',
seq: 3 }
<- disconnectResponse
Response {
seq: 0,
type: 'response',
request_seq: 3,
command: 'disconnect',
success: true }

more details from phpinfo():
1
2
3
4

@sunehinz
Copy link

sunehinz commented Jan 7, 2018

I too have this issue and as far as I can see they problem is multiple connections. It spins up 2 connections which block each other.

I can't figure out if this is XDebug on the Vagrant box which causes the problem, or if it is standard behaviour the PHP Debugger in VSCode somehow is mishandling?

Starting PHP Debug in VSCode and launching PHPUnit on the vagrant box produces these logs:
VSCode log

<- 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 (14:29:18)' } ] } }

-> setBreakpointsRequest
{ command: 'setBreakpoints',
  arguments: 
   { source: 
      { name: 'UserModelTest.php',
        path: '/path-to-test/UserModelTest.php' },
     lines: [ 20 ],
     breakpoints: [ { line: 20 } ],
     sourceModified: false },
  type: 'request',
  seq: 4 }

<- setBreakpointsResponse
Response {
  seq: 0,
  type: 'response',
  request_seq: 4,
  command: 'setBreakpoints',
  success: true,
  body: { breakpoints: [ { verified: true, line: 20 } ] } }

-> 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 }

-> threadsRequest
{ command: 'threads', type: 'request', seq: 8 }

<- threadsResponse
Response {
  seq: 0,
  type: 'response',
  request_seq: 8,
  command: 'threads',
  success: true,
  body: { threads: [ Thread { id: 1, name: 'Request 1 (14:29:18)' } ] } }

new connection 2
<- threadEvent
ThreadEvent {
  seq: 0,
  type: 'event',
  event: 'thread',
  body: { reason: 'started', threadId: 2 } }

<- initializedEvent
InitializedEvent { seq: 0, type: 'event', event: 'initialized' }

-> threadsRequest
{ command: 'threads', type: 'request', seq: 9 }

<- threadsResponse
Response {
  seq: 0,
  type: 'response',
  request_seq: 9,
  command: 'threads',
  success: true,
  body: 
   { threads: 
      [ Thread { id: 1, name: 'Request 1 (14:29:18)' },
        Thread { id: 2, name: 'Request 2 (14:29:19)' } ] } }

-> setBreakpointsRequest
{ command: 'setBreakpoints',
  arguments: 
   { source: 
      { name: 'UserModelTest.php',
        path: '/path-to-test/UserModelTest.php' },
     lines: [ 20 ],
     breakpoints: [ { line: 20 } ],
     sourceModified: false },
  type: 'request',
  seq: 10 }

Vagrant XDebug (xdebug.remote_log)

Log opened at 2018-01-07 02:26:06
I: Connecting to configured address/port: 10.0.2.2:9888.
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///vagrant/vendor/phpunit/phpunit/phpunit" language="PHP" xdebug:language_version="7.1.7-1~ubuntu16.04.1+deb.sury.org+1" protocol_version="1.0" appid="6832" idekey="VSCODE"><engine version="2.5.5"><![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:///home/vagrant/code/tests/Unit/Models/UserModelTest.php -n 20
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="2" id="68320001"></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:///home/vagrant/code/tests/Unit/Models/UserModelTest.php" lineno="20" state="enabled" hit_count="0" hit_value="0" id="68320001"></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:///home/vagrant/code/tests/Unit/Models/UserModelTest.php" lineno="20" state="enabled" hit_count="0" hit_value="0" id="68320001"></breakpoint></response>

<- run -i 5
Log opened at 2018-01-07 02:26:07
I: Connecting to configured address/port: 10.0.2.2:9888.
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="dbgp://stdin" language="PHP" xdebug:language_version="7.1.7-1~ubuntu16.04.1+deb.sury.org+1" protocol_version="1.0" appid="6838" idekey="VSCODE"><engine version="2.5.5"><![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:///home/vagrant/code/tests/Unit/Models/UserModelTest.php -n 20
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="2" id="68380001"></response>

If I then hit the stop button in VSCode, thread 2 is closed and the first test completes (but then spins up a thread #3).

If I hit the stop again then thread 1 and 3 closes (effectively ending PHP Debug) and the final test completes. No breakpoints are ever hit.

When this is done the logs look like this

VSCode log

<- 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 (14:29:18)' } ] } }

-> setBreakpointsRequest
{ command: 'setBreakpoints',
  arguments: 
   { source: 
      { name: 'UserModelTest.php',
        path: '/path-to-test/UserModelTest.php' },
     lines: [ 20 ],
     breakpoints: [ { line: 20 } ],
     sourceModified: false },
  type: 'request',
  seq: 4 }

<- setBreakpointsResponse
Response {
  seq: 0,
  type: 'response',
  request_seq: 4,
  command: 'setBreakpoints',
  success: true,
  body: { breakpoints: [ { verified: true, line: 20 } ] } }

-> 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 }

-> threadsRequest
{ command: 'threads', type: 'request', seq: 8 }

<- threadsResponse
Response {
  seq: 0,
  type: 'response',
  request_seq: 8,
  command: 'threads',
  success: true,
  body: { threads: [ Thread { id: 1, name: 'Request 1 (14:29:18)' } ] } }

new connection 2
<- threadEvent
ThreadEvent {
  seq: 0,
  type: 'event',
  event: 'thread',
  body: { reason: 'started', threadId: 2 } }

<- initializedEvent
InitializedEvent { seq: 0, type: 'event', event: 'initialized' }

-> threadsRequest
{ command: 'threads', type: 'request', seq: 9 }

<- threadsResponse
Response {
  seq: 0,
  type: 'response',
  request_seq: 9,
  command: 'threads',
  success: true,
  body: 
   { threads: 
      [ Thread { id: 1, name: 'Request 1 (14:29:18)' },
        Thread { id: 2, name: 'Request 2 (14:29:19)' } ] } }

-> setBreakpointsRequest
{ command: 'setBreakpoints',
  arguments: 
   { source: 
      { name: 'UserModelTest.php',
        path: '/path-to-test/UserModelTest.php' },
     lines: [ 20 ],
     breakpoints: [ { line: 20 } ],
     sourceModified: false },
  type: 'request',
  seq: 10 }

-> disconnectRequest
{ command: 'disconnect',
  arguments: { restart: false },
  type: 'request',
  seq: 11 }

<- outputEvent
OutputEvent {
  seq: 0,
  type: 'event',
  event: 'output',
  body: { category: 'console', output: 'connection 2 closed\n' } }

connection 2 closed
<- threadEvent
ThreadEvent {
  seq: 0,
  type: 'event',
  event: 'thread',
  body: { reason: 'exited', threadId: 2 } }

new connection 3
<- threadEvent
ThreadEvent {
  seq: 0,
  type: 'event',
  event: 'thread',
  body: { reason: 'started', threadId: 3 } }

<- initializedEvent
InitializedEvent { seq: 0, type: 'event', event: 'initialized' }

-> threadsRequest
{ command: 'threads', type: 'request', seq: 12 }

<- threadsResponse
Response {
  seq: 0,
  type: 'response',
  request_seq: 12,
  command: 'threads',
  success: true,
  body: 
   { threads: 
      [ Thread { id: 1, name: 'Request 1 (14:29:18)' },
        Thread { id: 3, name: 'Request 3 (14:30:21)' } ] } }

-> setBreakpointsRequest
{ command: 'setBreakpoints',
  arguments: 
   { source: 
      { name: 'UserModelTest.php',
        path: '/path-to-test/UserModelTest.php' },
     lines: [ 20 ],
     breakpoints: [ { line: 20 } ],
     sourceModified: false },
  type: 'request',
  seq: 13 }

-> setFunctionBreakpointsRequest
{ command: 'setFunctionBreakpoints',
  arguments: { breakpoints: [] },
  type: 'request',
  seq: 14 }

-> setFunctionBreakpointsRequest
{ command: 'setFunctionBreakpoints',
  arguments: { breakpoints: [] },
  type: 'request',
  seq: 15 }

Vagrant XDebug (xdebug.remote_log)

Log opened at 2018-01-07 02:26:06
I: Connecting to configured address/port: 10.0.2.2:9888.
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///vagrant/vendor/phpunit/phpunit/phpunit" language="PHP" xdebug:language_version="7.1.7-1~ubuntu16.04.1+deb.sury.org+1" protocol_version="1.0" appid="6832" idekey="VSCODE"><engine version="2.5.5"><![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:///home/vagrant/code/tests/Unit/Models/UserModelTest.php -n 20
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="2" id="68320001"></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:///home/vagrant/code/tests/Unit/Models/UserModelTest.php" lineno="20" state="enabled" hit_count="0" hit_value="0" id="68320001"></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:///home/vagrant/code/tests/Unit/Models/UserModelTest.php" lineno="20" state="enabled" hit_count="0" hit_value="0" id="68320001"></breakpoint></response>

<- run -i 5
Log opened at 2018-01-07 02:26:07
I: Connecting to configured address/port: 10.0.2.2:9888.
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="dbgp://stdin" language="PHP" xdebug:language_version="7.1.7-1~ubuntu16.04.1+deb.sury.org+1" protocol_version="1.0" appid="6838" idekey="VSCODE"><engine version="2.5.5"><![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:///home/vagrant/code/tests/Unit/Models/UserModelTest.php -n 20
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="2" id="68380001"></response>

<- stop -i 3
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="stop" transaction_id="3" status="stopped" reason="ok"></response>

Log opened at 2018-01-07 02:27:09
I: Connecting to configured address/port: 10.0.2.2:9888.
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="dbgp://stdin" language="PHP" xdebug:language_version="7.1.7-1~ubuntu16.04.1+deb.sury.org+1" protocol_version="1.0" appid="6843" idekey="VSCODE"><engine version="2.5.5"><![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:///home/vagrant/code/tests/Unit/Models/UserModelTest.php -n 20
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="2" id="68430001"></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:///home/vagrant/code/tests/Unit/Models/UserModelTest.php" lineno="20" state="enabled" hit_count="0" hit_value="0" id="68430001"></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:///home/vagrant/code/tests/Unit/Models/UserModelTest.php" lineno="20" state="enabled" hit_count="0" hit_value="0" id="68430001"></breakpoint></response>

-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_list" transaction_id="4" status="stopping" reason="ok"></response>

Log closed at 2018-01-07 02:27:38

-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="run" transaction_id="5" status="stopping" reason="ok"></response>

Log closed at 2018-01-07 02:27:40

@alexalp
Copy link
Author

alexalp commented Jan 7, 2018

After some troubleshooting i've fixed the issue E: Time-out connecting to client. :-( into xdebug.log. Now I've the same problem of sunehinz above, Vs Code never stop at breakpoint and this are my logs:
VSCode log
<- 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 (4:15:56 PM)' } ] } }
-> setBreakpointsRequest
{ command: 'setBreakpoints',
arguments:
{ source:
{ name: 'index.php',
path: 'd:\Project\Project\public\index.php' },
lines: [ 7 ],
breakpoints: [ { line: 7 } ],
sourceModified: false },
type: 'request',
seq: 4 }
<- setBreakpointsResponse
Response {
seq: 0,
type: 'response',
request_seq: 4,
command: 'setBreakpoints',
success: true,
body: { breakpoints: [ { verified: true, line: 7 } ] } }
-> 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 }
-> threadsRequest
{ command: 'threads', type: 'request', seq: 8 }
<- threadsResponse
Response {
seq: 0,
type: 'response',
request_seq: 8,
command: 'threads',
success: true,
body: { threads: [ Thread { id: 1, name: 'Request 1 (4:15:56 PM)' } ] } }
<- configurationDoneResponse
Response {
seq: 0,
type: 'response',
request_seq: 7,
command: 'configurationDone',
success: true }
<- threadEvent
ThreadEvent {
seq: 0,
type: 'event',
event: 'thread',
body: { reason: 'exited', threadId: 1 } }
-> disconnectRequest
{ command: 'disconnect',
arguments: { restart: false },
type: 'request',
seq: 9 }
<- disconnectResponse
Response {
seq: 0,
type: 'response',
request_seq: 9,
command: 'disconnect',
success: true }

Xdebug log
image 1

@alexalp
Copy link
Author

alexalp commented Jan 17, 2018

No one could help us?

@felixfbecker felixfbecker added the remote debugging All issues related to debugging a remote host (server, VM, Docker container, ...) label Feb 23, 2018
@jonagoldman
Copy link

jonagoldman commented Mar 17, 2018

Besides this bug that will break your workflow when there are more than one request at the same time, I can make it work with Homestead v7.3.0 (Box 5.2.0) using this config:

xdebug.ini:

zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_host=10.0.2.2

VERY IMPORTANT: remove any other xdebug configuration besides the ones above. Using things like xdebug.remote_connect_back=1 break it for me.

launch.json:

"pathMappings": {
    "/home/vagrant/code": "/home/your-user-here/Code",
},

Full Step by Step Guide:

Setup Xdebug in Homestead

  • SSH into your homestead machine from local homestead folder: homestead ssh or vagrant ssh
  • Enable Xdebug on Homestead: xon
  • Find your guest machine's gateway IP (will output 10.0.2.2 for example, you need to set this IP as the remote_host in the xdebug.ini config): netstat -rn | grep "^0.0.0.0 " | cut -d " " -f10
  • Find xdebug.ini path (will outputh path /etc/php/7.2/cli/conf.d/20-xdebug.ini): php --ini | grep 'xdebug'
  • Open xdebug.ini: sudo vim /etc/php/7.2/cli/conf.d/20-xdebug.ini (use your correct path)
  • Configure Xdebug with this settings. IMPORTANT: remove all other configurations, otherwise it will not work!
    zend_extension=xdebug.so
    xdebug.remote_enable=1
    xdebug.remote_autostart=1
    xdebug.remote_host=10.0.2.2
  • Restart the PHP-FPM service: sudo service php7.2-fpm restart

Setup Xdebug in VSCode

  • Install the PHP Debug plugin and modify the default launch.json file with this values:
"configurations": [
    {
        "name": "Listen for XDebug on Homestead",
        "type": "php",
        "request": "launch",
        "pathMappings": {
            "/home/vagrant/code": "/home/your-user-here/Code",
        },
        "port": 9000
    }
]

IMPORTANT: if pathMapping is incorrect breakpoints will not stop. Make sure your local and server paths are correct.

You can also try with this:

"pathMappings": {
    "/home/vagrant/code": "/home/your-user-here/Code",
    "/home/vagrant/code/your-app": "/home/your-user-here/Code/your-app",
    "/home/vagrant/code/your-app/public": "/home/your-user-here/Code/your-app/public",
},

@gwleuverink
Copy link

I couldn't get it to work either at first what ended up being the case for me is that port 9000 was already in use by my local php installation's xdebug.

An easy fix was to move xdebug on vagrant to port 9001 and reflect this in your local launch.json

@kmaradona
Copy link

I couldn`t get it to work either i got an error

PHP Warning: Failed loading Zend extension 'xdebug.so' (tried: /usr/lib/php/20170718/xdebug.so (/usr/lib/php/20170718/xdebug.so: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/xdebug.so.so (/usr/lib/php/20170718/xdebug.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0

@cregx
Copy link

cregx commented Jun 6, 2018

I also had problems using the debugger properly. It started, but I didn't see in which line it was. Of course, only for a breakpoint, this was the right line.
I also received error messages that the file I am debugging cannot be found, e.g. web.php

The solution of the problem was the entry of all 3 lines for pathMapping as already described by @jonagoldman:

"pathMappings": { "/home/vagrant/code": "/home/your-user-here/Code", "/home/vagrant/code/your-app": "/home/your-user-here/Code/your-app", "/home/vagrant/code/your-app/public": "/home/your-user-here/Code/your-app/public", },

@reageek
Copy link

reageek commented Jun 8, 2018

@kmaradona this is because newer homestead comes with php7.2, which does not have xdebug installed in its stable version yet. You can install it via the following instructions

@BeingTomGreen
Copy link

BeingTomGreen commented Aug 15, 2018

I had many of the same issues, although not using Homestead. I've just today managed to get this working for myself.

In the end when I added xdebug.idekey = VSCODE, all of my issues went away.

My fully config looks like this:

[XDebug]
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 1
xdebug.remote_port = 9000
xdebug.idekey = VSCODE

@DeBelserArne
Copy link

After some troubleshooting i've fixed the issue E: Time-out connecting to client. :-( into xdebug.log. Now I've the same problem of sunehinz above, Vs Code never stop at breakpoint and this are my logs:
VSCode log
<- 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 (4:15:56 PM)' } ] } }
-> setBreakpointsRequest
{ command: 'setBreakpoints',
arguments:
{ source:
{ name: 'index.php',
path: 'd:\Project\Project\public\index.php' },
lines: [ 7 ],
breakpoints: [ { line: 7 } ],
sourceModified: false },
type: 'request',
seq: 4 }
<- setBreakpointsResponse
Response {
seq: 0,
type: 'response',
request_seq: 4,
command: 'setBreakpoints',
success: true,
body: { breakpoints: [ { verified: true, line: 7 } ] } }
-> 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 }
-> threadsRequest
{ command: 'threads', type: 'request', seq: 8 }
<- threadsResponse
Response {
seq: 0,
type: 'response',
request_seq: 8,
command: 'threads',
success: true,
body: { threads: [ Thread { id: 1, name: 'Request 1 (4:15:56 PM)' } ] } }
<- configurationDoneResponse
Response {
seq: 0,
type: 'response',
request_seq: 7,
command: 'configurationDone',
success: true }
<- threadEvent
ThreadEvent {
seq: 0,
type: 'event',
event: 'thread',
body: { reason: 'exited', threadId: 1 } }
-> disconnectRequest
{ command: 'disconnect',
arguments: { restart: false },
type: 'request',
seq: 9 }
<- disconnectResponse
Response {
seq: 0,
type: 'response',
request_seq: 9,
command: 'disconnect',
success: true }

Xdebug log
image 1

Quick question, I'm also having issues and I want to check the logs files, but I can't find them anywhere. Not the VScode ones and not the ones on the server, where can I find them?

@habenamare
Copy link

Also, when restarting the php-fpm service, make sure you are restarting the one with the version of PHP you are using.

@Y-k-Y
Copy link

Y-k-Y commented Aug 26, 2019

@jonagoldman

I have a quick question.
In your code the 3 lines of local path of pathMappings property Does it should be exactly same as your wrote? I mean in my computer the local path of my project is like this C:\Usres\Myuser\Desktop... and i wrote it as ${workspaceRoot} and the absolute path of my project folder. When i set the breakpoints as everything the debugger stops nowhere which i can't see where it is and throw error that file which locates on the homestead not found on my local machine.
I followed exactly the configuration you wrote above... If you have any idea about it please let me know. Thank you in advance and sorry it seems it's not a quick question

@jonagoldman
Copy link

jonagoldman commented Aug 26, 2019

@Y-k-Y

Does it should be exactly same as your wrote?

No, it should represent your server -> local mapping

"pathMappings": {
  "/your/server/path": "/your/local/path",
}

So, if you configured your Homestead.yaml file as this:

folders:
    - map: ~/code
      to: /home/vagrant/code

Your launch.json file (inside .vscode folder in your project) mapping should look like this:

"pathMappings": {
  "/home/vagrant/code": "/home/your-user-name/code",
}

Why ~/code is used instead of /home/your-user-name/code? Because server is Linux and in Linux ~/code is the same as /home/your-user-name/code.

But if you are using a Windows machine then your local path will look like C:\Users\YourUser\YourFolder instead.

Always be aware that because the server your are connecting to is Linux, then when setting a path in server, the path needs to be in linux format. When you are setting a path in your local machine, the path must be set in your local machine format, in linux something like /home/your-user-name/code, in Windows something like C:\Users\YourUser\YourFolder, in Mac /i-have-no-idea-macs-are too-expensive

I wrote it as ${workspaceRoot} and the absolute path of my project folder

You should check that ${workspaceRoot} points to the correct path. By the way ${workspaceRoot} is deprecated and you should use ${workspaceFolder} instead.

One way to chek if ${workspaceFolder} path is correct is to create a task in VSCODE.

  1. Create a tasks.json file in your .vscode folder in your project and add:
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "show-workspace-path",
            "type": "shell",
			"command": "echo ${workspaceFolder}",
        }
    ]
}
  1. In VSCODE go to Terminal->Run Task and select the task you just created show-workspace-path
    Screenshot from 2019-08-26 17-06-54

  2. Look at the output on your terminal, it should be the path that ${workspaceFolder} represents.

Then you can verify if your paths match.

@Y-k-Y
Copy link

Y-k-Y commented Aug 27, 2019

@jonagoldman
Thank you for your very fast answer!! 👍 but it's still throw same error that file not found.

alt text

And when i click the Create File button it creates file on my local machine.

Here is my settings:

launch.json

alt text

xdebug.ini

alt

Homestead.yaml

alt

If you need more info of my environment just let me know 🙏

@jonagoldman
Copy link

First, you are assumming that the error you see is related to the debbuger but are you sure it is related in some way? It looks to me that the file is not found, nothing to do with the plugin.

The create file button is just a helper, you are not supposed to create the file, you should look why it is not finding the file. Do your project run without any warnings in the laravel log file?

Your .yaml file looks strange, the folder mapping will map all the folder contents, so you should not map a folder inside a folder you have already mapped. Remember, you are mapping folders not websites! So why are you mapping 'Laravel/phpMyAdmin' if you have already mapped the 'Laravel' folder?

I don't know how to help you any more that that, you should dig deeper to see why the file is not found. Also try using a regular path not {$workspaceFolder}! Try different things until it works. Good look!

@Y-k-Y
Copy link

Y-k-Y commented Aug 28, 2019

@jonagoldman

Again, Thank you for your quick answer 🙏 and yes my project just runs fine without any error.
As you said i'll look why the file is not found thank you!!

@Y-k-Y
Copy link

Y-k-Y commented Aug 30, 2019

@jonagoldman

I finally figured where that file not found error comes from there was typo in the lauch.json.
The path in the pathMappings it was code not Code... since i fixed it that file not found error is gone.
But still it's pretty weird it stops on the breakpoints only when exception occurs i'm not sure if i should say it's working now😓

@jonagoldman
Copy link

Don't use ${workspaceFolder}" or ${workspaceRoot} in the path, try the full real path, and double check everything!

@Vlad412
Copy link

Vlad412 commented Jun 7, 2020

Besides this bug that will break your workflow when there are more than one request at the same time, I can make it work with Homestead v7.3.0 (Box 5.2.0) using this config:

xdebug.ini:

zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_host=10.0.2.2

VERY IMPORTANT: remove any other xdebug configuration besides the ones above. Using things like xdebug.remote_connect_back=1 break it for me.

launch.json:

"pathMappings": {
    "/home/vagrant/code": "/home/your-user-here/Code",
},

Full Step by Step Guide:

Setup Xdebug in Homestead

* SSH into your homestead machine from local homestead folder: `homestead ssh` or `vagrant ssh`

* Enable Xdebug on Homestead: `xon`

* Find your guest machine's gateway IP (will output 10.0.2.2 for example, you need to set this IP as the remote_host in the xdebug.ini config): `netstat -rn | grep "^0.0.0.0 " | cut -d " " -f10`

* Find xdebug.ini path (will outputh path /etc/php/7.2/cli/conf.d/20-xdebug.ini): `php --ini | grep 'xdebug'`

* Open xdebug.ini: `sudo vim /etc/php/7.2/cli/conf.d/20-xdebug.ini` (use your correct path)

* Configure Xdebug with this settings. _**IMPORTANT**_: remove all other configurations, otherwise it will not work!
    zend_extension=xdebug.so
    xdebug.remote_enable=1
    xdebug.remote_autostart=1
    xdebug.remote_host=10.0.2.2
* Restart the PHP-FPM service: `sudo service php7.2-fpm restart`

Setup Xdebug in VSCode

* Install the PHP Debug plugin and modify the default launch.json file with this values:
"configurations": [
    {
        "name": "Listen for XDebug on Homestead",
        "type": "php",
        "request": "launch",
        "pathMappings": {
            "/home/vagrant/code": "/home/your-user-here/Code",
        },
        "port": 9000
    }
]

IMPORTANT: if pathMapping is incorrect breakpoints will not stop. Make sure your local and server paths are correct.

You can also try with this:

"pathMappings": {
    "/home/vagrant/code": "/home/your-user-here/Code",
    "/home/vagrant/code/your-app": "/home/your-user-here/Code/your-app",
    "/home/vagrant/code/your-app/public": "/home/your-user-here/Code/your-app/public",
},

If it can help somebody, this pathMapping worked for me
"/home/vagrant/src/project": "${workspaceFolder}"
And deleting this option in xdebug.ini make it work
xdebug.remote_connect_back = 1

@jonagoldman thank you !! 🙏💪

@loctx21
Copy link

loctx21 commented Jul 3, 2020

From my experience, here are a few things that I think we can check if cannot get Xdebug work with vagrant

  • xdebug.remote_connect_back = 1 can only help us catch request from the browser
  • make sure the path we set for xdebug.remote_log is writable by any user who triggers phpunit or customer php script. The content of this log will help us check a lot of problem.
  • Double check if Xdebug really uses the port that we set in xdebug.remote_port. (Xdebug can only catch request on my browser not cli. After a lot of hair-pulling, I figure out from Xdebug log file that Xdebug connect to 9001 for request from browser and 9000 for cli. Maybe I set it through EXPORT by accident).
  • Sometimes 9000 port is used by other processes. We should double check by changing xdebug.remote_port to other port
  • Use either netstat or content of your xdebug log to find out which value to set for xdebug.remote_host

@alexalp alexalp closed this as completed Dec 15, 2020
@Kyon147
Copy link

Kyon147 commented Jan 24, 2021

I couldn't get it to work either at first what ended up being the case for me is that port 9000 was already in use by my local php installation's xdebug.

An easy fix was to move xdebug on vagrant to port 9001 and reflect this in your local launch.json

I spent two hours trying to get this to work and the above worked for me.

If you have been using xdebug with a local PHP instance through xampp or even locally running Laravel then make sure your port is different on the homestead instance otherwise they conflict and nothing works.

To be safe I changed my port to 9010 and works beautifully.

@Novelz
Copy link

Novelz commented Apr 20, 2021

Hi there.
I had the same problem using vscode breakpoints and to solve I had to dig a bit into the Xdebug documentation.
Some settings changed name with the update to xdebug 3.x so double check your version before making any adjustment in the configuration file.
I solved using this parameters:

xdebug.client_host = 10.0.2.2     
xdebug.discover_client_host = 1
xdebug.start_with_request = yes
xdebug.mode = develop,debug,trace
xdebug.idekey = VSCODE

xdebug.remote_port the default port in the v3.x changed from 9000 to 9003 (remember to change it in the VScode json config)
xdebug.client_host is the new remote_host
xdebug.discover_client_host is the new remote_connect_back
xdebug.start_with_request is the new remote_autostart

With all this changes and the relative fixes in the VSCODE json file (for the debug php plugin) I was able to use the php breakpoints and debug.
Let me know if something isn't clear and I will try to help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
remote debugging All issues related to debugging a remote host (server, VM, Docker container, ...)
Projects
None yet
Development

No branches or pull requests