XDebug for PHPUnit in Docker with PHPStorm update Set the IP-address to the following DNS-name: docker.for.mac.localhost (yes, literally)! Working with the IP-address doesn’t work anymore /update Want to get XDebug working for your PHPUnit tests which run in Docker? Debugging is always an important aspect of coding. Without it, you can not see what is going wrong with the code. It’s a good practice to set up your debugging environment before writing the code, because, if you are developing a complex application which contains thousands of lines of code, you will need a PHP debugger that finds errors and warning signs quickly.
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:
- 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.
- 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:
- set port for xdebug
Preferences -> Languages & Frameworks -> PHP -> Debug | Xdebug: Debug port = 9005
- 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
Xdebug For Mac Tutorial
- set Ide key (session id): to PHPSTORM
Xdebug For Mac Pro
Happy debugging with docker!