PHPStorm 9 - Remote debugger on virtual machine

I've searched the docs but was unable to figure out a way to setup remote debugging for my virtual machine.

I am using Mac host machine with VirtualBox running Ubuntu 14.04 server, and have setup virtual hosts.

e.g.,

192.168.1.101     example.local

How do I setup the remote debugger to work with this?

18 comments

Hi there,

Without showing what you have done so far I cannot suggest you anything except giving you the links to diff aricles:


Debugging code running in VM is no different to debugging code running on remote server.

For example, the minimum settings for xdebug are shown here: https://confluence.jetbrains.com/display/PhpStorm/Xdebug+Installation+Guide

0

These are the steps, I've tried from this video: https://www.youtube.com/watch?v=hui9GKJGb8I

1) In the video at the 3:56 mark, they are setting up PHP listening as follows:

php -S 0.0.0.0:8000 -t /www/

Instead of 0.0.0.0 I am using the server remote ip of 192.168.1.101:8000, with my document root of /var/www/html/.

2) In PhpStorm I am going to Preferences>Languages & Frameworks > Debug > Use debugger booklets to iniate debugging from your favorite browser

3) I am selecting on Xdebug and clicking on the 'Start Debugger' from the page that opened from User debugger booklets ... https://www.jetbrains.com/phpstorm/marklets/

4) In PhpStorm I click on the 'Start Listening for PHP Debug Connections' icon

5) Refresh the page and I don't see any pop-ups from PHPStorm as shown in the video at 5:02.

Is this not the proper of setting up the remote debugger?

0

1) In the video at the 3:56 mark, they are setting up PHP listening as follows:

php -S 0.0.0.0:8000 -t /www/

Instead of 0.0.0.0 I am using the server remote ip of 192.168.1.101:8000, with my document root of /var/www/html/.

That's how you start PHP's own built-in web server. AFAIK 0.0.0.0 is the IP to bind to, which in this case means any/all IP.

You can do the same from PhpStorm using "PHP Built-in Web Server" type of Run/Debug configuration -- https://www.jetbrains.com/phpstorm/help/php-built-in-web-server.html?search=buil (works for local PHP interpreter, not sure if remote PHP interpreter is supported -- never tried this myself)

5) Refresh the page and I don't see any pop-ups from PHPStorm as shown in the video at 5:02.

This most likely means that you do not have xdebug (or zend debugger) php extension installed/enabled or did not configured it correctly. And most likely they have already configured it in advance.

So .. do you have xdebug installed and configured in your PHP?

0

Do I need to do the PHP built-in listening server bit? Or can I skip that step?

Yes, I have XDebug installed and it shows up in phpinfo.

As for configuring it, I followed the example here: https://confluence.jetbrains.com/display/PhpStorm/Remote+debugging+in+PhpStorm+via+SSH+tunnel#RemotedebugginginPhpStormviaSSHtunnel-1.XdebugorZendDebuggerinstalledandconfigured

[xdebug]

zend_extension=xdebug_module_goes_here

xdebug.remote_enable=1

xdebug.remote_host=127.0.0.1

xdebug.remote_port=9000



Do I need to put anything in the zend_extension= ... ?

Is there more configuration that needs to be with XDebug/PhpStorm?
0

Well.. if it's a remote then

xdebug.remote_host=127.0.0.1
will be incorrect as it should point to an IP where PhpStorm is running (remember: it's xdebug who connects to IDE and not other way around; this also means that firewall on your local computer or remote/vm could prevent such connection from happening)

Do I need to do the PHP built-in listening server bit? Or can I skip that step?

You can skip -- I just pointed that it's not necessary to do such launch from command line. So better keep it as it's now.
Yes, I have XDebug installed and it shows up in phpinfo.

Could you please create new file (e.g. test.php), place "<?php phpinfo();" text in it and execute it via browser. Then please show here the header part + whole xdebug section

0

Changed the 127.0.0.1 to my remote server address: 192.168.1.101.

What is the best way to check the port that it's using? Or stick with port 9000?

0
Changed the 127.0.0.1 to my remote server address: 192.168.1.101

No -- it should be IP address of computer where PhpStorm is running.

Basically -- just check what you see in $_SERVER['REMOTE_ADDR'];

Alternatively -- "xdebug.remote_connect_back = 1"

I also suggest enabling "xdebug.remote_log = /path/to/xdebug.log" (file must be writable by php/apache) -- when xdebug will receive debug request it will write all info there.

What is the best way to check the port that it's using? Or stick with port 9000?

Well.. you can enable "phone handle icon" in PhpStorm and then try to connect from remote to phpstorm using telnet on that 9000 port

0

Ok I've changed my to match what I have for $_SERVER['REMOTE_ADDR'];.

Just to go over the steps again:

1) I've set break points in my code.
2) I got to and click Preferences>Languages & Frameworks > Debug > Use debugger booklets to iniate debugging from your favorite browser
3) Click on Start Debugger under the Xdebug section
4) Turn on start listening in PhpStorm
5) Refresh the page, and nothing comes up from PhpStorm

0

So what does xdebug log says.

Does it see debug request (cookie or query parameter) at all?

P.S.
You can always use "xdebug.remote_autostart = 1" to tell xdebug to try to debug every single request.

Plus, to be sure, make sure that you do not have anything in "Settings | Language & Frameworks | PHP | Servers" -- on first incoming debug connection IDE will help you with its' creation.

0

I've set the path to the xdebug.log in php.ini, ran the steps I mentioned.

Nothing, comes up, the log isn't created. (assuming no error?) Folder is writeable by apache server and the debug location shows up in the phpinfo.

Also added in xdebug_remote.autostart=1 to the php.ini file as well.                                                                                                     

0
Nothing, comes up, the log isn't created. (assuming no error?)

Quite opposite.

Either xdebug is unable to create log there .. or xdebug is does not see debug request at all. Although I have seen one question on StackOverflow (I believe) where person was saying that even after making debugging working it still was not creating log file.

Folder is writeable by apache server and the debug location shows up in the phpinfo.

Also added in xdebug_remote.autostart=1 to the php.ini file as well.             

No clue then. Maybe when you running your code another php interpreter/config is used?


Here is an example of me doing simple debug on my local Windows 7:

Log opened at 2015-07-09 23:02:59
I: Connecting to configured address/port: 127.0.0.1:9000.
I: Connected to client. :-)
-> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" fileuri="file:///E:/Projects/web/_idetest/test.php" language="PHP" protocol_version="1.0" appid="5132" idekey="12325"><engine version="2.3.2"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[http://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2015 by Derick Rethans]]></copyright></init>

<- feature_set -i 1 -n show_hidden -v 1
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="1" feature="show_hidden" success="1"></response>

<- feature_set -i 2 -n max_depth -v 1
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="2" feature="max_depth" success="1"></response>

<- feature_set -i 3 -n max_children -v 100
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="3" feature="max_children" success="1"></response>

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

<- step_into -i 5
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="step_into" transaction_id="5" status="break" reason="ok"><xdebug:message filename="file:///E:/Projects/web/_idetest/test.php" lineno="3"></xdebug:message></response>

<- breakpoint_set -i 6 -t line -f file://E:/Projects/web/_idetest/test.php -n 22
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="6" id="51320001"></response>

<- stack_get -i 7
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="stack_get" transaction_id="7"><stack where="{main}" level="0" type="file" filename="file:///E:/Projects/web/_idetest/test.php" lineno="3"></stack></response>

<- run -i 8
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="run" transaction_id="8" status="break" reason="ok"><xdebug:message filename="file:///E:/Projects/web/_idetest/test.php" lineno="22"></xdebug:message></response>

.....

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

<- run -i 15
Log closed at 2015-07-09 23:03:02


This is what should be in a log when xdebug tries to connect to debug client (PhpStorm in our case)

I: Connecting to configured address/port: 127.0.0.1:9000.
0

Another suggestion to try:

Try adding programmatic breakpoint -- add "xdebug_break();" in your php file somewhere on the top (try with small simple files first).

0

What kind of framework/VM you are using?

If Laravel and you are using Homestead with vagrant -- have a look at these links (returned by gooogling for "laracast phpstorm debug"):

https://laracasts.com/forum/?p=1648-phpstorm-homestead-xdebug/0
https://laracasts.com/series/how-to-be-awesome-in-phpstorm/episodes/19

0

I was able to get it running once, after setting chown on the folder and I got the debugger to come up in Phpstorm.

However now, when reloading the page, it's caught reloading and not doing anything.

I do see this in the event log:

4:09:01 PM Cannot accept external Xdebug connection: Cannot evaluate expression 'isset($_SERVER['PHP_IDE_CONFIG'])'

0

For this application it's ZendFramework v1 and VirtualBox.

It's weird as it worked the first time, however after refreshing it's stuck re-freshing. Once I disable the 'Stop debugger' and turn off listen in PhpStorm the page reloads fine.

0

Maybe you are still debugging (in debug session)?

What web server you are using there? Apache/nginx .. or just PHP's own server?

As far as I'm concerned there is still some misconfiguration from PHP side/web server somewhere there. Right now it sounds like you are trying to debug a CLI script (e.g. some cron job .. or script executed in terminal). Remember: if you have used "xdebug.remote_autostart = 1" then xdebug will attempt to debug every single request.

Just search this forum for "PHP_IDE_CONFIG" (or even Issue Tracker) and you will see various reasons for why it's not working.

Have a look at what xdebug log says at such failed debug attempt -- what file:line is was attempting to debug etc.

Also keep in mind that by default PhpStorm accepts only one debug connection at the time -- maybe try increasing that limit in settings (just use search box in Settings and search for "max simul").

0

I'll play around with the settings some more.

Thanks for all your help and helping me resolve this Andriy.

0

Please sign in to leave a comment.