jonnie jonnie - 4 months ago 59
PHP Question

How can I debug php mounted to a container running on docker beta for mac

I have spent half the day trying different things including this solution I came across on gist.github.com

I have a docker-compose file which mounts a folder containing my client and server projects:

volumes:
- ~/projectx:/projectx


my docker php.ini contains the following xdebug options

[xdebug]
xdebug.remote_enable=1
xdebug.remote_port=9000
xdebug.remote_connect_back=On
xdebug.var_display_max_children = 999
xdebug.var_display_max_data = 999
xdebug.var_display_max_depth = 100


I have the xdebug chrome extension installed

In my mac host file I have the following
127.0.0.1 localhost dtest.xxx.com
so I can access my web app (and other docker web apps) through
dtest.xxx.com
which all works to run the app

In Phpstorm (version 2016.1.2) In preferences
->
Languages & Frameworks
->
PHP
->
Servers I have :

host = dtest.xxx.com, port=80 , Debugger = Xdebug
Use path mappings is checked and I have

      File/Directory set to
/Users/<myname>/projectx/server


      Absolute path on the server is set to
/projectx/server


I have tried setting the
xdebug.remote_host
to my macs ip obtained from ifconfig as well as trying the ip in
/Users/<myname>/Library/Containers/com.docker.docker/Data/database/com.docker.driver.amd64-linux/slirp/host


But I cannot hit a breakpoint , I have even added
xdebug_break()
double check.
I am also running the latest docker beta
Version 1.12.0-rc3-beta18 (build: 9996)


I would very much appreciate anyone's help, it's a real blocker for me.

If any further information is required I am happy to provide.

Answer

The workaround I used was to open up an ssh tunnel to the docker container running php using a command like, in my case I have the docker container ssh port mapped to 12 hence the -p 12

ssh -R 9000:localhost:9000 root@dtest.xxx.com -p:12

UPDATE: The Correct way

so I eventually figured out that my xdebug settings in docker should be

xdebug.enable=1
xdebug.remote_enable = 1
xdebug.idekey="PHPSTORM"
xdebug.remote_port=9000
xdebug.remote_host="192.168.65.1"
xdebug.remote_connect_back=0

where 192.168.65.1 is the entry found in ~/Library/Containers/com.docker.docker/Data/database/com.docker.driver.amd64-linux/slirp/host

Also make sure to set the idekey correctly in the chrome extension, in my case PHPSTORM
With this I no longer require the ssh tunnel