Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remote Xdebug with VirtualBox

I'm trying to get remote debugging to work. The PHP is running on a VM and I'm trying to debug from NetBeans on the host machine.

I've followed the instructions here, forwarded port 9000 in the Windows 7 firewall and in the VirtualBox network settings, and set up path mappings in NetBeans. My xdebug settings look like this:

xdebug.remote_enable = On
xdebug.remote_connect_back = On
xdebug.idekey = "netbeans-xdebug"
xdebug.remote_log = /tmp/xdebug.log

When I load the URL I want to debug (using the correct idekey) it logs the following:

I: Checking remote connect back address.
I: Remote address found, connecting to 192.168.0.1:9000.
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" 
         xmlns:xdebug="http://xdebug.org/dbgp/xdebug"
         fileuri="file:///home/dev/web/projects/project.com.vm/httpdocs/index.php" 
         language="PHP" protocol_version="1.0" 
         appid="1380" 
         idekey="netbeans-xdebug">
   <engine version="2.2.1"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2012 by Derick Rethans]]></copyright></init>

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

However, NetBeans remains waiting for a connection. I've got it set up to stop at the first line, in addition to having a breakpoint set. The log file will include the "Connected to client" message even when NetBeans is not listening.

Any idea what I might be missing?

Thanks.

like image 309
Zach Avatar asked Aug 20 '12 23:08

Zach


5 Answers

What worked for me was running the following from my host:

ssh -R 9000:localhost:9000 yourUserName@yourVirtualMachine

Note the use of the -R flag instead of -L. I had trouble using port forwarding to get things working, while the ssh tunnel worked perfectly. Note you could also do this by running the ssh command from within the VM and connecting to the host with the -L flag.

Since I ended up on this question while working with Vagrant, this is the command I personally used, use the password 'vagrant' when prompted:

ssh -p 2222 [email protected] -R 9000:localhost:9000
like image 118
adamfeldman Avatar answered Nov 10 '22 07:11

adamfeldman


I added 4 options to use Xdebug in my projects in a virtual machine:

xdebug.remote_enable = On
xdebug.remote_host = [YOUR_HOST_IP]
xdebug.remote_connect_back = On
xdebug.remote_autostart = On

As long as your debugger is listening, it should break on a breakpoint.

like image 43
Gordon Forsythe Avatar answered Nov 10 '22 06:11

Gordon Forsythe


My solution to this issue was the following:

1) Enable the port forwarding in the network configuration (using the NAT adapter) I simply used port 9000 and the IP addresses of the host and the guest. Protocol is TCP

2) Configured my xdebug settings: In my case it was important to set xdebug.remote_host = "The permanent host IP" Then everthing worked perfectly.

Hope this helps someone out there.

like image 5
Sebastian Avatar answered Nov 10 '22 06:11

Sebastian


If you have this in your log file:

I: Connected to client. :-)

That means that Xdebug has successfully made a connection to the IDE.

The IDE (netbeans) simply then shuts down the connection without even attempting to send any information. This happens if it doesn't know what to do with the filename (file:///home/dev/web/projects/project.com.vm/httpdocs/index.php) in your example. The reason for this is that you do not have the correct path mapping set-up in your IDE.

like image 2
Derick Avatar answered Nov 10 '22 06:11

Derick


The virtual machine needs to be able to talk back to the host machine and to make that happen you need to forward 9000 to do this. This step is not described in some setups because it happens in the background.

To do this, issue the command ssh -L 9000:localhost:9000 yourUserName@youVirtualMachine.

To simplify this, I have the name of the virtual machine in /etc/hosts and in my ~/ssh/config file.

like image 1
Lloyd Moore Avatar answered Nov 10 '22 07:11

Lloyd Moore