Remote Xdebug with VirtualBox

后端 未结 6 1172
盖世英雄少女心
盖世英雄少女心 2021-02-02 00:55

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

相关标签:
6条回答
  • 2021-02-02 01:11

    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.

    0 讨论(0)
  • 2021-02-02 01:12

    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.

    0 讨论(0)
  • 2021-02-02 01:15

    3 conditions must be fullfilled for xdebug to work remotely with VirtualBox, I had it especially in connection with Docker inside virtualbox.

    1) remote_connect_back=0 or exact ip address of your host machine must be listed in remote_host (, sometimes both at the same time don't work together, especially in the case of docker being separately from virtualbox at windows hyper-v directly)

    2) no other application like eg web-project can be exposed at port 9000, that must be reserved for php editor, or different port must be reserved by editor/listened at (or for php web project), and addressed/transmitted to from the php

    3) it's similar to the second point, virtual box must have no port forwarding to that port, as it would effectively occupy it but it must be reserved for php editor, not for virtualbox port forwarding, not virtualbox has to listen at that port to be forwarded to some internal app, but outernal php-editor has to listen for it=that port

    0 讨论(0)
  • 2021-02-02 01:16

    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.

    0 讨论(0)
  • 2021-02-02 01:18

    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 vagrant@127.0.0.1 -R 9000:localhost:9000
    
    0 讨论(0)
  • 2021-02-02 01:27

    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.

    0 讨论(0)
提交回复
热议问题