Vagrant + PHPStorm + Xdebug not connecting

1,057 views
Skip to first unread message

Nicholas Loomans

unread,
Dec 3, 2014, 10:30:53 PM12/3/14
to vagra...@googlegroups.com
I am trying to set up a Vagrant box for Xdebug so I can run some performance tests, however I am having no luck getting it work. The box is a Homestead box (if that matters) running an instance of CodeIgniter. The website works and serves from the Vagrant box fine.

I used http://www.sitepoint.com/install-xdebug-phpstorm-vagrant/ to try and get the Xdebug connection working but no dice. Currently my config is:

xdebug.ini has:
zend_extension=xdebug.so
xdebug.remote_enable = on
xdebug.remote_host = 10.0.2.2
xdebug.remote_port = 8081
xdebug.idekey = "vagrant"

I am forwarding 8081 to 8081 in the vagrant config.

PHPStorm is setup as:
PHP > Debug Xdebug port is 8081
PHP > Servers has my hostname, port 8081, Debugger set to Xdebug and paths mapped.

Running Validate remote environment returns successfully.

PHPStorm screenshot: http://iforce.co.nz/i/4kwm1ir1.nuz.png

Thanks for your time, I appreciate it.

Vincenzo D'Amore

unread,
Dec 4, 2014, 4:39:40 AM12/4/14
to vagra...@googlegroups.com
Hi,

I'm not sure what's your problem but I would suggest to add in xdebug.ini the following line:

debug.remote_connect_back = 1

If enabled, the xdebug.remote_host setting is ignored and Xdebug will try to connect to the client that made the HTTP request. It checks the $_SERVER['REMOTE_ADDR'] variable to find out which IP address to use. Please note that there is no filter available, and anybody who can connect to the webserver will then be able to start a debugging session, even if their address does not match xdebug.remote_host.

Then add in query string the 

XDEBUG_SESSION_START=vagrant

for example 


Hope this helps


--
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Vincenzo D'Amore
email: v.da...@gmail.com
skype: free.dev
mobile: +39 349 8513251

Marco De Bortoli

unread,
Dec 4, 2014, 4:56:51 AM12/4/14
to vagra...@googlegroups.com
The connect remote back flag is not needed when the remote ip is specified. For the url session I would recommend a browser extension, you can find an approved list in the xdebug website. Also, to ease the process I generally use private networks, rather than port forwarding. One more thing, did you activate phpstorm incoming connection listener?
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--
Vincenzo D'Amore
email: v.da...@gmail.com
skype: free.dev
mobile: +39 349 8513251

--
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+unsubscribe@googlegroups.com.

Nicholas Loomans

unread,
Dec 4, 2014, 4:27:50 PM12/4/14
to vagra...@googlegroups.com
I have tried that option before and it didn't work. Tried again and I'm just getting "port 8081 is busy" from PHPStorm.

Nicholas Loomans

unread,
Dec 4, 2014, 4:34:47 PM12/4/14
to vagra...@googlegroups.com
Tried this extension: https://addons.mozilla.org/en-US/firefox/addon/the-easiest-xdebug/?src=search doesn't seem to do anything, I still get port 8081 is busy from PHPStorm.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--
Vincenzo D'Amore
email: v.da...@gmail.com
skype: free.dev
mobile: +39 349 8513251

--
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+...@googlegroups.com.

Nicholas Loomans

unread,
Dec 4, 2014, 4:54:14 PM12/4/14
to vagra...@googlegroups.com
Rebooted my computer and I still get port busy :/

Marco De Bortoli

unread,
Dec 4, 2014, 5:23:29 PM12/4/14
to vagra...@googlegroups.com
What's running on that port? Try default port over private host
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+unsubscribe@googlegroups.com.

Alvaro Miranda Aguilera

unread,
Dec 4, 2014, 5:32:30 PM12/4/14
to vagra...@googlegroups.com
port busy is something ..
on the guest

netstat -anp | grep 8081

Nicholas Loomans

unread,
Dec 4, 2014, 5:36:11 PM12/4/14
to vagra...@googlegroups.com
Ran in Vagrant box: nothing. Run on machine: VBoxHeadless.

Marco De Bortoli

unread,
Dec 4, 2014, 5:50:27 PM12/4/14
to vagra...@googlegroups.com
Hi Nicholas, as I said try to configure xdebug to listen on the default port and use private network so you don't have to forward anything. Also, what version of PHP are you using? Xdebug conflict with Zend Opcache. Did you verify the module is loaded properly in the VM?

On Thu Dec 04 2014 at 10:36:14 PM Nicholas Loomans <beave...@gmail.com> wrote:
Ran in Vagrant box: nothing. Run on machine: VBoxHeadless.

--

Nicholas Loomans

unread,
Dec 4, 2014, 6:19:56 PM12/4/14
to vagra...@googlegroups.com
I don't understand what you mean by private network - have you got some documentation on that? Xdebug is definitely loaded, and I commented out ;zend_extension=opcache.so and restarted fpm but still port busy.

vagrant@homestead:~$ php -v
PHP 5.6.3-1+deb.sury.org~trusty+1 (cli) (built: Nov 19 2014 19:38:33)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies
    with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans


Thanks for the input so far.

Nicholas Loomans

unread,
Dec 4, 2014, 6:22:24 PM12/4/14
to vagra...@googlegroups.com
 Does this mean I'm on a private network already?

   # Configure A Private Network IP
    config.vm.network :private_network, ip: settings["ip"] ||= "192.168.10.10"

Marco De Bortoli

unread,
Dec 5, 2014, 3:24:09 AM12/5/14
to vagra...@googlegroups.com
Yes that's what I meant from private network, however to fully use it, you have to do few other things.

1. Change xdebug remote host to be 192.168.10.1
2. Make sure that when you connect to the guest, the host uses the private ip 192.168.10.10 to reach your bmp

That said I want to clarify that this is not a vagrant problem. Let's continue.

I know that it shouldn't be the case by your php output tells me that xdebug is loaded in the cli not necessarily in fpm so double check via phpinfo. Also xdebug generally works on port 9000, any reason why you decided to change it? What's your host? Make sure that neither selinux nor iptables is running on the guest or alternatively make sure they allow connections to the specified remote port.

I hope it helps.

Cheers,
Debo

Andrew Coulton

unread,
Dec 5, 2014, 8:49:47 AM12/5/14
to vagra...@googlegroups.com
I think the issue is because you are forwarding port 8081 on the host to the guest. That means Virtualbox listens on port 8081 on the host and sends any traffic it receives on to the guest. In this case that means the XDebug connection will be going in a loop guest > host > guest.

Because Virtualbox is already listening, PHPStorm can't open that port which is why you're seeing "port busy".

Imagine if this was two separate machines on a LAN. You only need port forwarding if you want certain guest services (eg a webserver) to act as though they're actually running on localhost. If you just want to send traffic between host and guest, you don't need port forwarding rules - just use a private network adapter and specify the IP address and port on each side just like you would over a LAN. 

By default, your host always has the x.x.x.1 address of whatever private network you're using - so if your guest is running at 192.168.10.10 then it will see the host on 192.168.10.1.

Change your xdebug remote host and remove the port forwarding rule and you should be fine.

Nicholas Loomans

unread,
Dec 6, 2014, 6:53:41 PM12/6/14
to vagra...@googlegroups.com
Yes! Thanks all of you for your input. I removed the port forwarding, added the remote host IP, and removed the port from the browser window PHPStorm opens and it works :)
Reply all
Reply to author
Forward
0 new messages