PHPStorm 8 / Vagrant / Xdebug

Hi.

I'm are looking into moving our development environment over on a vagrant setup.
This seams to working quite nicely and I'm now able to run our phpunit tests from phpstorm against the vagrant server.

However what I'm trying to get working now is remote debugging with xdebug. I've configured xdebug in php.ini and start listening for connections in phpstorm.
If I set a breakpoint in the index.php and open that http//vagrant.local/index.php I get the connection popup in phpstorm and I'm able to setup mapping.

What I'm trying to accomplish in someway is to be able to debug the phpunit tests. With a local development environment I could simply configure phpunit tests and then press the debug icon in phpstorm. It would then run through all my phpunit tests and stop at wherever I set the breakpoints.
This doesn't seem to be the case anymore and I understand that one should use the "listen for php debug connection", but is it possible to achive what I'm trying to do it a simple way?

If further information is needed or you have any follow up questions, please let me know.

--
Tom

9 comments

Thanks for the quick reply Andriy.

However I can't seem to get this working.
I used that documentation to get phpunit up and running, but I'm not able to debug these test cases.

I've tried both to only hit the "debug" icon, but I have also tried to "start listening for php debug connection" and then hit the "debug" icon, but it doesn't stop on my breakpoint.
I tried to configure mappings under Settings->PHP->Servers->[Name of my server].

When I hit the debug icon the console pops up and stops on "Instantiating tests...". The command it tries to execute is:
vagrant:///path/to/vagrant/server/usr/bin/php -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host=10.0.2.2 /home/vagrant/.phpstorm_helpers/phpunit.php --testsuite Dev --configuration /vagrant/tests/phpunit.xml

I can then choose to resume tests and it then runs through all the test cases as normal, but as mention, it does not stop on my breakpoints.
At one time I recieved the following error in phpstorm: Cannot accept external Xdebug connection:Cannot evaluate expression 'isset($_SERVER['PHP_IDE_CONFIG']). But this error message is not consistent.

Any ideas?

0
but I have also tried to "start listening for php debug connection" and then hit the "debug" icon,


You do not need to use  "start listening for php debug connection" at all. You just need to create run/debug config entry of "PHPUnit" type and then use "Debug" button

This also requires to have Remote PHP Interpreter to be configured (Settings | PHP) and selected as default for this project (as I understand you are fine in this regard as you can execute tests).

I tried to configure mappings under Settings->PHP->Servers->[Name of my server].


"PHPUnit" type of Run/Debug configuration is executed in CLI mode -- the above settings are for web debug (or debug remote CLI scripts in pre-v8 PhpStorm by using some additional manual config)

The mappings (local <--> remote) for debug using Remote Interpreters are taken from Deployment; make sure you have created one of SFTP type and marked it as Default for this project.

0

You do not need to use  "start listening for php debug connection" at all. You just need to create run/debug config entry of "PHPUnit" type and then use "Debug" button


Ah, perfect, I understand now. That makes sense.

The mappings (local <--> remote) for debug using Remote Interpreters are taken from Deployment; make sure you have created one of SFTP type and marked it as Default for this project.


I didn't have a SFTP deployment server, but now I do. The root path was auto-detected to /home/vagrant and the *Test SFTP connection...* verify that the settings is correct.
On mappings I configured the local path /path/to/my/project and on the deployment server /vagrant/project as I've configured vagrant to mount this local folder into /vagrant folder.

I hit the debug, for the same phpunit tests that works when only running tests, and the console pops up with a yellow "pause" symbol saying: "Instantiating tests...".
The command it tries to run is
vagrant:///path/to/vagrant/server/usr/bin/php -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host=10.0.2.2 /home/vagrant/.phpstorm_helpers/phpunit.php --testsuite Dev --configuration /vagrant/project/tests/phpunit.xml

I then need to press "Resume program" for the tests to start running, but it does not trigger the breakpoint and I'm sure it runs this tests because I tried to run die(); after the breakpoint and it hits it. I'm wondering if it might be my xdebug.ini settings. I've tried changing them a little bit but so far, no luck. These are two of the different setups I've tried:

zend_extension=xdebug.so

xdebug.remote_enable = 1

xdebug.remote_host="localhost"

xdebug.remote_port = 9000

xdebug.remote_handler=dbgp

and

zend_extension=xdebug.so

xdebug.remote_enable = 1

xdebug.remote_port = 9000

xdebug.remote_handler=dbgp                                                   

xdebug.idekey = "PHPStorm"

xdebug.remote_autostart = 1

xdebug.remote_log="/var/log/xdebug/xdebug.log"

xdebug.remote_host=10.0.2.2

If this is incorrect and you have a working xdebug.ini configuration example, please let me know. I will continue to troubleshoot, but any ideas are welcome.

0

Enable extra logging from both IDE and xdebug sides and look into logs:

These are two of the different setups I've tried:

There is no need for that. Since it's launched via Remote Interpreters .. IDE will pass port/host as well as other necessary info as part of the command line (which you can clearly see yourself).

Considering that IDE breaks at some point (first line?) .. this means that actual xdebug is configured correctly (it can establish connection with IDE). The behavior you describing looks to me as wrong path mappings -- xdebug log should have enough info for diagnose that.

All of this could be happening because you may have symlinks on your remote side. You have to remember: xdebug works with final/resolved paths only while PhpStorm/PHP itself works with them as is.

but it does not trigger the breakpoint and I'm sure it runs this tests because I tried to run die(); after the breakpoint and it hits it

Try placing xdebug_break(); (programmatic breakpoint) instead of die(); -- does it stop now? Although .. if path mappings is wrong it may not help here (IDE may not know in what file it is happening) ...

I didn't have a SFTP deployment server, but now I do.

Screenshots please. Did you marked it as Default for this project (double check that)?

-----

Without screenshots (or even better -- some screencast) it's hard to suggest anything more concrete as I have to literally guess what has been done and hope that it was done correctly (for example: lots of people simply skipping the "mark as default" part when configuring deployment (for deployment purposes, not just remote debug) for God-knows reasons, most often are: "I know better what I'm doing" and "TL;DR -- Too long and seems complicated -- lets make it shorter and skip it").

0

Try placing xdebug_break(); (programmatic breakpoint) instead of die(); -- does it stop now? Although .. if path mappings is wrong it may not help here (IDE may not know in what file it is happening) ...


It breaks when using xdebug_break(); and I now think there is some problems with the mappings as you mention, because when I hit the "Debugger" tab it says:
Remote file path '/vagrant/api/..../....Test.php' is not mapped to any file in project.

The deployment server is default for the porject and I've attached some screenshots as well.

Without screenshots (or even better -- some screencast) it's hard to suggest anything more concrete as I have to literally guess what has been done and hope that it was done correctly (for example: lots of people simply skipping the "mark as default" part when configuring deployment (for deployment purposes, not just remote debug) for God-knows reasons, most often are: "I know better what I'm doing" and "TL;DR -- Too long and seems complicated -- lets make it shorter and skip it").


I know how it is and I appreciate the help you're providing me and I promise that nothing in this thread is TL;DR for me.

I activated logging in xdebug.ini and phpstorm as well as you mention. xdebug doesn't give me any output to the logs. I know it's working because when I was using "start listening" button it logged to the same file. However phpstorm logs the following, which verifies that it must be a mapping problem:

2014-10-02 09:12:20,922 [5687107]  DEBUG - p.debug.common.PhpDebugProcess - 2133877351# Stop at ('file:///vagrant/api/..../....Test.php':29)

2014-10-02 09:12:20,922 [5687107]  DEBUG - p.debug.common.PhpDebugProcess - 2133877351# remote: 'file:///vagrant/api/..../....Test.php' <-> local: 'null'

2014-10-02 09:12:20,922 [5687107]  DEBUG - p.debug.common.PhpDebugProcess - 2133877351# remote: 'file:///vagrant/api/..../..../BankAccountTest.php' <-> extracted: '/vagrant/api/..../....Test.php'



Attachment(s):
Screen Shot 2014-10-02 at 9.18.18 AM.png
Screen Shot 2014-10-02 at 9.17.41 AM.png
0

file:///vagrant/api/..../..../BankAccountTest.php' <-> extracted: '/vagrant/api/..../....Test.php'

It should not be like that (same path on 2 ends, considering your screenshots). It definitely looks like path issue. What actual xdebug.log says about it?

Where you project files are located? On local computer at /Users/tomtom/conta/www/api (is that is the root folder of the project)?

What is the file you are trying to place breakpoint in (full local path)? And what is the remote path for it?

Please attach xdebug.log

-----

The "slight problem" here is .. that I'm not using Vagrant or debugging PHPUnit remotely myself .. hence I cannot look at my own settings and give concrete answer on where the problem may be. Sure, I did some remote debugging it the past (more like a test that serious/regular task) plus helped others in this regard (in vast majority of cases it's related to the path mapping or complete xdebug misconfiguration) .. but so far I have not used Remote Interpreters or remote CLI PHPUnit debug myself.
0

The remote interpreter -- how did you configure it (screenshot please).

If you have used "take from Vagrant" (or whatever the proper name/label is) .. then try getting those details from your new SFTP connection. It should help (it did for some users when IDE was in EAP stage).

EDIT: For example:

0

The remote interpreter -- how did you configure it (screenshot please).

If you have used "take from Vagrant" (or whatever it's called there) .. then try getting those details from your new SFTP connection. It may help (it did for some users when IDE was in EAP stage).


Perfect, this seems to be the issue. I used a Vagrant Interpreter setup, but after changing this to SFTP it works like charm and debugging breaks at my breakpoint.
For anyone else who might have this problem: I ended up with the following settings for my deployment server:

Vagrant server:
Path: /path/to/my/projects/
(this will automatically mount the projects folder into /vagrant on the server).
Vagrantfile: /path/to/my/projects/Vagrantfile

Deployment settings:
Root path: /
Web server root URL: http://<ip or hostname>/


Mappings:
Local path: /path/to/my/projects/api
Remote path: /vagrant/api
Web path: api


Run configuration: Same as used for regular phpunit tests (that was working for me all the time).

Thank you so much for the help Andriy, it is much appreciated.
http://img2.wikia.nocookie.net/__cb20131102231616/vampirediaries/images/f/f1/Phil-Thumbs-Up.gif

0

Please sign in to leave a comment.