Debugging PHP on a VM with xDebug

Hello there,

I've posted this question on Stack Overflow as well, so here's a copy and paste of my question (http://stackoverflow.com/questions/4260922/debug-vm-with-xdebug-and-phpstorm):

My work setup is a Windows XP host, running an Ubuntu VM LAMP stack. I am using PhpStorm to edit my code on my host Windows machine. Upon saving files are automatically uploaded to the VM via SFTP. Everything works for this process, except debugging.

I have setup PhpStorm to have a server named "UbuntuVM" with the following settings:

Debugger:
- XDebug

Debug session settings:
- Break at the first line
- Wait for connection with ide key: XDEBUG_PHPSTORM

Before launch:
- Upload files to selected server

I am using Chrome with Xdebug Helper, and have set the extension to use "Other" as the IDE, with "XDEBUG_PHPSTORM" as the key.
The VM has the following in the php.ini:

zend_extension="/usr/lib/php5/20090626+lfs/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_host=10.1.6.22
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.collect_params=On
xdebug.show_local_vars=On

When I set a break point in my IDE, enable the debugger in Chrome, and reload the page, I never hit the break point; and the IDE says "Waiting for connection on port 9000 with ide key 'XDEBUG_PHPSTORM'".
Does anyone have any idea why I'm not hitting my break points?

Thanks in advance,
Andrew

13 comments

Hi Andrew,

My experience tells me that the issue is most likely with mappings (the path to the project files on your PC is different to what you have on VM):
1) Open your debug configuration
2) "Debug" tab and then "Server path mappings..." button
3) Add your paths there

If it still does not work -- please provide your debugger log.

0

Hello Andrew,

It looks like you have a problem with connection. Do you use firewall?
Try "Validate Xdebug configuration before debug" option in run configuration settings.



Attachment(s):
validate_xdebug_before_launch.png
0

Hey Andriy,

Here is what I have, and no luck. Keep in mind baytn.com and ubuntuvm are spoofed to the VM's IP in my hosts file.

Server:
Connection
Access Type: SFTP
SFTP host: ubuntuvm
Port: 22
Root path: /var/www/baytn.com
User name: root
Auth type: password
Password: ****

Mappings
Local path: C:\wamp\www\My Dropbox\www\BAYTN\www
Deployment path on server 'UbuntuVM': /
Web path on server 'UbuntuVM': /
Project URL: http://baytn.com/

Debug:
Local Path on Client: C:\wamp\www\My Dropbox\www\BAYTN\www\html
Local Path on Server: /var/www/baytn.com/html

The reason the debug paths link to "html" is because there's there my index.php is sitting, and that's the DocumentRoot for that vHost.

Attached is my debugger log.

Regards,
Andrew



Attachment(s):
idea.log.zip
0

Hey Nikolay,

This VM is running on the same computer I'm working on; it's not a network VM. But either way, I don't have a firewall on my PC as I've got my router setup to handle the firewall activity from the outside world, internal connections are open.

Regards,
Andrew

0

Hi Andrew,

I cannot see anything useful in this log that relates to debugging sessions. It looks like you just send the logs that you already had. Can you collect new logs:
1) Delete existing logs
2) Follow points 1-3 in that document -- category_name should be com.jetbrains.php.debug
3) Start PhpStorm
4) Set some breakpoints; start debugging
5) When debugging is finished (successful or not), stop PhpStorm
6) Find and attach log here

You can check how such log should look like in this thread: http://devnet.jetbrains.net/thread/291898

Also -- have you tried the "Validate Xdebug configuration before debug" option in run configuration settings as Nikolay suggested? This will check if debugger is installed/enabled and connectable (it's Xdebug who initiates connection to your IDE, not IDE to Xdebug).

This VM is running on the same computer I'm working on; it's not a network VM. But either way, I don't have a firewall on my PC as I've got my router setup to handle the firewall activity from the outside world, internal connections are open.

You may have firewall on your VM OS.

0

Hey Andriy,

I did all of those steps, if you don't see anything related to debugging, it's because I never even hit a break point. Once the debugger has been set to active in Chrome using Xdebug Helper, PhpStorm is still saying "Waiting for connection on port 9000 with ide key 'XDEBUG_PHPSTORM'".

Keep in mind, the files I'm editing are local files. The VM has it's own files, which are SFTPed from my local machine to the VM upon modification.

Regards,
Andrew

0

Hi Andrew,

Well, in this case we came back to the original though from Nikolay -- you are having connection issue -- Xdebug cannot connect to client.

1) Create a simple script that will print caller IP address (or see the output from phpinfo()):

<?php
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
    echo "HTTP_X_FORWARDED_FOR = {$_SERVER['HTTP_X_FORWARDED_FOR']} \n";
}
elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
    echo "HTTP_CLIENT_IP = {$_SERVER['HTTP_CLIENT_IP']} \n";
}
elseif (isset($_SERVER['REMOTE_ADDR'])) {
    echo "REMOTE_ADDR = {$_SERVER['REMOTE_ADDR']} \n";
}

  Compare values received to what you have got in xdebug.remote_host
2) You can try xdebug.remote_connect_back=1 if Xdebug is v2.1 or newer (http://xdebug.org/docs/remote)
3) Can you check if you can connect from your guest OS (Ubuntu) to your host (Windows XP) somehow ?

If everything is fine here (IPs are correct and you CAN connect from Ubuntu to XP; you already confirmed that there is no firewall on XP) then I'm out of ideas.

0

Another idea to try -- is to configure xdebug.remote_log -- maybe it will tell something useful.

0

Hey Andriy,

So I tried changing the xdebug.remote_host to my actual computer's IP address, and not the VM's, and that worked! I then figured I'd change that to xdebug.remote_connect_back=1 and that started to work too.

Thanks for all of the help, now I have the perfect work environment and am ready to get back to cranking out some awesome goodies! :)

Regards,
Andrew

0

Andriy,

Thanks for your help! You are really very competent!

0

Andrew,

Did you try to enable "validate xdebug" option? It can detect such problems.

0

Hey Nikolay,

Yep, that was checked, but it never said anything. :\

Regards,
Andrew

0

Thanks, of course. :)

I'm just not so sure about that :| (really) -- but I'm learning, and maybe one day I will be as good as you think I am ;)

0

Please sign in to leave a comment.