Skip to content

Instantly share code, notes, and snippets.

@bullgare
Forked from manuelselbach/README.md
Created March 1, 2021 17:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bullgare/0d9cc2e8ff896ca651286d92d4912cbc to your computer and use it in GitHub Desktop.
Save bullgare/0d9cc2e8ff896ca651286d92d4912cbc to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment