Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
xdebug docker on macOS with PhpStorm

Use xdebug with docker on macOS and PhpStorm

To use xdebug with macOS and docker is quite, let´s call it tricky ;)

The following steps need to be proceed to get it working:

  1. use the config from the xdebug.ini wihtin your docker web container. Important: set remote_connect_back to off

UPDATE

As mentioned by some comments (thanks for the feedback), it is not needed to configure the IP manually. Thus, the next step is optional and the configuration (xdebug.ini) is updated to use the dynamic IP.

  1. optional: set up an alias for your local interface (lo)

To bring up the alias at startup, you can either (sudo may be needed here):

  • manually place the file com.manuelselbach.docker_10254254254_alias.plist into directory: /Library/LaunchDaemons/

  • Or use the script set_and_install_autorun_alias_for_lo.sh

Configure PhpStorm

After all that, just configure your PhpStorm:

  1. set port for xdebug Preferences -> Languages & Frameworks -> PHP -> Debug | Xdebug: Debug port = 9005
  2. configure a configuration in the toolbar
  • use PHP remote Debug
  • add a server to your domain (without protocoll like http:// or https://)
  • set port for http / https (not the xdebug port here)
  • select Debugger: Xdebug
  • if needed: set path mappings
  1. set Ide key (session id): to PHPSTORM

Happy debugging with docker!

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.manuelselbach.docker_10254254254_alias</string>
<key>ProgramArguments</key>
<array>
<string>ifconfig</string>
<string>lo0</string>
<string>alias</string>
<string>10.254.254.254</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
#!/bin/bash
ifconfig lo0 alias 10.254.254.254
#!/bin/bash
ifconfig lo0 alias 10.254.254.254
curl https://gist.githubusercontent.com/manuelselbach/8a214ae012964b1d49d9fb019f5f5d7b/raw/fc57a5c8f13c6f9deb64d70f992a29487c49e494/com.manuelselbach.docker_10254254254_alias.plist >> /Library/LaunchDaemons/com.manuelselbach.docker_10254254254_alias.plist
# xdebug config within docker container
zend_extension=/path/to/xdebug.so
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_connect_back=off
xdebug.remote_host=host.docker.internal
# xdebug.remote_host=10.254.254.254 ## use this to configure it manually
xdebug.remote_port=9005
xdebug.idekey=PHPSTORM
xdebug.max_nesting_level=1500
@fabiojaniolima

This comment has been minimized.

Copy link

fabiojaniolima commented Jan 9, 2018

Should xdebug.remote_host be the ip address of the container?

@vulogic

This comment has been minimized.

Copy link

vulogic commented May 4, 2018

This was very helpful. Thanks!

@ojhaujjwal

This comment has been minimized.

Copy link

ojhaujjwal commented Aug 13, 2018

I have a suggestion. If you set xdebug.remote_host=docker.for.mac.localhost, you don't have to configure 10.254.254.254.
Check this discussion if you want to know why.

@sookoll

This comment has been minimized.

Copy link

sookoll commented Jan 31, 2019

It should work xdebug.remote_host=host.docker.internal
But I have found out, that it works occasionally. No idea why.

@wd3mo

This comment has been minimized.

Copy link

wd3mo commented Feb 22, 2019

Works for other IDEs too. For Visual Studio Code just change the xdebug.idekey=VSCODE and you are good to go.

@rsmondejar

This comment has been minimized.

Copy link

rsmondejar commented Mar 3, 2019

Thank you for all the information! It works like a charm.
xdebug.remote_host=docker.for.mac.localhost or xdebug.remote_host=host.docker.internal work fine for me.

@Sauerbrei

This comment has been minimized.

Copy link

Sauerbrei commented May 27, 2019

Thank you.

@tixastronauta

This comment has been minimized.

Copy link

tixastronauta commented Jul 4, 2019

Important: set remote_connect_back to off

This saved my life 🙏

@romlly

This comment has been minimized.

Copy link

romlly commented Nov 20, 2019

I have a suggestion. If you set xdebug.remote_host=docker.for.mac.localhost, you don't have to configure 10.254.254.254.
Check this discussion if you want to know why.

Helped me a lot, thanks !

@BalaWxd

This comment has been minimized.

Copy link

BalaWxd commented Nov 27, 2019

Thanks, works like a charm and easy to setup, saved my time..

@neomobil

This comment has been minimized.

Copy link

neomobil commented Jan 4, 2020

Thank you!
It helped me too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.