0

Running a script.php from command line I do like this

$ php -f myscript.php

I can follow the process with die() and print_r(). But I can't connect with my IDE (IntelliJ) like a regular xdebug session comming from the Browser.

I am running inside a MacOS(HOST) connected with a docker ubuntu 16.04.

The IntelliJ is configured to listen incoming call from Docker. I think when I use my terminal I am using the php from my host and this is why the IntelliJ is not catching the connection.

Even when I run from the terminal inside the Docker container, the xdebug process in IntelliJ is not trigged.

Note: The xdebug is working good with the Docker and IntelliJ in a regular Browser session. I just pass the HOST IP when building the container and it works.

This is the portion of my Dockefile that set the xdebug:

RUN { \
        echo '[xdebug]'; \
        echo 'zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so'; \
        echo 'xdebug.remote_enable=1'; \
        echo 'xdebug.remote_port=9000'; \  
        echo 'xdebug.remote_autostart=1'; \
        echo 'xdebug.remote_handler=dbgp'; \
        echo 'xdebug.idekey=dockerdebug'; \
        echo 'xdebug.profiler_output_dir="/var/www/html"'; \
        echo 'xdebug.remote_connect_back=0'; \
        echo 'xdebug.remote_host=$REMOTE_HOST'; \
    } >> /usr/local/etc/php/php.ini

How could I achieve this debug process?

IgorAlves
  • 5,086
  • 10
  • 52
  • 83
  • Duplicate of https://stackoverflow.com/questions/2288612/how-to-trigger-xdebug-profiler-for-a-command-line-php-script?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – gview Apr 09 '18 at 16:00
  • 2
    Possible duplicate of [How to trigger XDebug profiler for a command line PHP script?](https://stackoverflow.com/questions/2288612/how-to-trigger-xdebug-profiler-for-a-command-line-php-script) – gview Apr 09 '18 at 16:01
  • Hi, they are not using docker. I've tried those approaches and it is not working. – IgorAlves Apr 09 '18 at 16:31
  • The point is that the only thing different with Docker is how you have configured networking. In order to connect to xdebug, you need to configure it. What port are you using? Did you make sure that port is mapped so that your IDE can connect to it? – gview Apr 09 '18 at 18:15
  • My docker is working good with xdebug. It is already configured. Not only the port but also the host ip that should be sent to the container. The point is how to run the cli file to be caught by the IntelliJ in a cli session. I've tried to run from the terminal inside and outside container. But it is not working. – IgorAlves Apr 09 '18 at 19:07
  • Clearly you need to run php from inside the container. Maybe you should update your question with the pertinent information: your xdebug init settings, and your docker run command. – gview Apr 09 '18 at 19:10
  • Just updated with the dockerfile info. – IgorAlves Apr 09 '18 at 20:22
  • I found a way to enable a debug session from my host. Using POSTMAN. Now it triggers the the xdebug inside intelliJ – IgorAlves Apr 09 '18 at 20:42

1 Answers1

0

I have found a way to trigger the xdebug. Just called the myscript.php from the POSTMAN (GET or POST) will work. mysite.com/myscript.php

IgorAlves
  • 5,086
  • 10
  • 52
  • 83