5

I managed to get xdebug in combination with docker and phpstorm. For http calls...IE

http://192.168.99.100:8081/?XDEBUG_SESSION_START=PHPSTORM

But when I try to run my phpunit tests, It does not connect with phpstorm

I did the correct directory mapping right in phpstorm, and also ran the following on my docker-instance export XDEBUG_CONFIG="idekey=PHPSTORM"

I also tried on my docker: export PHP_IDE_CONFIG='serverName=web.docker'and named the server config on phpstorm web.docker . still working over http but not CLI

So can I get phpstorm and xdebug working together for command line too?

here is my file: /etc/php5/cli/conf.d/20-xdebug.ini

zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.idekey=PHPSTORM
xdebug.remote_connect_back=1
xdebug.remote_host=172.17.42.1
dxdebug.remote_autostart=1

When I turn on logging, and play with the xdebug_remote_host IP adress I get

W: Remote address not found, connecting to configured address/port: localhost:9000. :-|
E: Could not connect to client. :-(
Log closed at 2015-10-13 12:20:39

Log opened at 2015-10-13 12:22:58
I: Checking remote connect back address.
W: Remote address not found, connecting to configured address/port: 172.17.42.1:9000. :-|
E: Could not connect to client. :-(
Log closed at 2015-10-13 12:22:58

Log opened at 2015-10-13 12:23:58
I: Checking remote connect back address.
W: Remote address not found, connecting to configured address/port: 192.168.99.100:9000. :-|
E: Could not connect to client. :-(
Log closed at 2015-10-13 12:23:58

Solution (edit) By turning on the xdebug logging, I saw it was succesfully connecting to 192.168.99.1 so this solved the issue

xdebug.remote_host=192.168.99.1
Confidence
  • 2,283
  • 3
  • 33
  • 57
  • 1
    For remote debug IDE uses server/host name as unique id to decide what path mappings to use (`PHP | Servers`). For CLI debug such info is not provided (nowhere to take from) so you need to provide it manually (similar to what you did with idekey) -- `serverName=ServerNameHere`. Also -- https://devnet.jetbrains.com/message/5534075#5534075 – LazyOne Oct 09 '15 at 13:07
  • I did not 100% understand your hint, but anyway I tried on my docker: `export PHP_IDE_CONFIG='serverName=web.docker'`and named the server config on phpstorm web.docker . still working over http but not CLI – Confidence Oct 09 '15 at 13:17
  • 1) You can read about remote CLI debug / that serverName param [here](https://youtrack.jetbrains.com/issue/WI-7906) 2) What's your `PHP | Servers` looks like (screenshot please) 3) Before debugging PHPUnit .. try debugging simple script (place it in your project root; both local and remote of course) -- at least you will guarantee that it's not working debug overall and not phpunit specific moment. 4) What xdebug log says about this unsuccessful attempt (make sure it's clear/has only this request details) – LazyOne Oct 09 '15 at 13:37
  • Some manual -- could be useful: https://confluence.jetbrains.com/display/PhpStorm/Debugging+PHP+CLI+scripts+with+PhpStorm (not docker specific -- just about CLI debug in general) – LazyOne Oct 09 '15 at 13:39
  • yeah I followed this guideline. I tried a very simple echo script in root public folder.....again...works fine in HTTP but not CLI. Here is a screen of my php storm server settings http://prntscr.com/8pgsqt – Confidence Oct 09 '15 at 13:55
  • Your server/host name is `192.168.99.100` and not `web.docker`. Your second export should be something like `export PHP_IDE_CONFIG='serverName=192.168.99.100'` – LazyOne Oct 09 '15 at 14:08
  • P.S. There is no real need for mapping parent and then sub-folder (unless it's a symbolic link or alike) -- all subfolders will inherit paths from the parent. In your case (based on screenshot) `PROJECT/code/` => `/srv/` mapping should be enough. – LazyOne Oct 09 '15 at 14:12
  • thanks but this did not bring any changes with: `export PHP_IDE_CONFIG='serverName=192.168.99.100'` – Confidence Oct 10 '15 at 07:41
  • How do you debug your CLI script? Can you please show your whole IDE window at that moment? What xdebug log says about this? – LazyOne Oct 10 '15 at 08:54
  • Read the manual. If the `xdebug.remote_connect_back` is on, then autostart and host does not matter. Try to turn off this settings: `xdebug.remote_connect_back=0` and restart apache. – vaso123 Oct 12 '15 at 07:21
  • thanks lolka_bolka...but your suggestion did not get it running for phpunit. – Confidence Oct 12 '15 at 07:51

3 Answers3

4

Two things come to my mind right now:

  1. Is xdebug.remote_host set correctly? For the HTTP Link you provided a 192.168. address, for the way back it's a 172.17. address. Can you ping your host on that IP?

  2. In your ini file it reads:

    dxdebug.remote_autostart=1
    

    Is this just a typo here, or is that actually in your config file? Because it should read xdebug without the "d" in front of it. It should be:

    xdebug.remote_autostart=1
    

    You should only add the d when you add the option when executing the script like this:

    php -dxdebug.remote_autostart=1 script.php
    

If that doesn't help yet, please enable the remote log by adding something like this to the config:

xdebug.remote_log = /var/log/xdebug_remote.log

maybe that'll help to find the problem.

Pampy
  • 959
  • 7
  • 15
1

What worked for me is ssh tunnel with this configuration xdebug.remote_connect_back=0 xdebug.remote_host=127.0.0.1

See: Xdebug with SSH tunnel on Docker for Mac

Community
  • 1
  • 1
Eugene Tulika
  • 703
  • 5
  • 11
0

Since Docker-17.06, you can access services hosted on Mac inside Container, via the static host name: docker.for.mac.localhost

full answer is here: https://stackoverflow.com/a/48495802/1241980

Lyfing
  • 1,778
  • 1
  • 19
  • 20