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
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
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
- set Ide key (session id): to PHPSTORM
Happy debugging with docker!
Hola ! Podrían darme una mano, tengo un Dockerfile que uso hace bastante en Linux y no tenia problemas en el debug con phpstorm, pero hace un tiempo lo quiero usar en mac y no me funciona.
Específicamente la parte de xdebug la tengo asi, como ven deje algunas lineas comentadas de las variantes que probe, sin dar con la configuracion correcta.
Muchas Gracias!
RUN pecl install xdebug-2.9.6 amqp
RUN docker-php-ext-enable --ini-name 05-opcache.ini opcache amqp xdebug
RUN echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.remote_autostart=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.remote_handler=dbgp" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.remote_mode=req" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.remote_port=9006" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.client_port=9006" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.remote_log=/var/log/xdebug_remote.log" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.idekey=PHPSTORM" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.remote_connect_back=0" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
docker nginx ip adress
#RUN echo "xdebug.remote_host=172.17.0.1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
#RUN echo "xdebug.remote_host=host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.discover_client_host=0" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.remote_host=docker.for.mac.localhost" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini