2
votes

I am trying to setup xdebug for PhpStorm.

Setup is as follows:

  • Symfony application is inside Docker container
  • I am using it for the REST API calls

What I have tried till now:

  • Installed Xdebug - reference

    RUN pecl install xdebug
    RUN docker-php-ext-enable xdebug
    

And run the commands:

echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
echo "xdebug.idekey = PHPSTORM" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
echo "xdebug.default_enable = 0" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
echo "xdebug.remote_enable = 1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
echo "xdebug.remote_autostart = 0" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
echo "xdebug.remote_connect_back = 0" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
echo "xdebug.profiler_enable = 0" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
echo "xdebug.remote_host = "docker.for.mac.host.internal"" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

Set up PhpStorm like below image(except the port is 8090 as my web application runs on that port. I access the website locally using localhost:8090/ ):

enter image description here

Now, when I make API call, nothing happens. It wont stop at breakpoint.

Anyone help me with this please?

PS: I am using Xdebug Helper chrome plugin.

2

2 Answers

0
votes

Here are the settings I use in my Docker LAMP stack

https://github.com/delboy1978uk/lamp

xdebug.default_enable=1
xdebug.remote_enable=1
xdebug.remote_handler=dbgp

xdebug.remote_port=9001
xdebug.remote_autostart=0

xdebug.remote_connect_back=1
xdebug.idekey="PHPSTORM"

xdebug.max_nesting_level = 250

I use PHP-FPM, so port 9000 was already taken and I changed to 9001. Give it a try, it should work!

0
votes

I was finally able to make it work on MacBook. I use Symfony4 as Rest API which is inside a docker container and Apache server.

  1. In dockerfile, (make sure to put it almost at the end of the file so that it should not interfere while running composer or cli)

    RUN yes | pecl install xdebug \
    && echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_autostart=1" >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_port = 9000" >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_handler = "dbgp"" >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_connect_back = 0" >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_host = "host.docker.internal"" >> /usr/local/etc/php/conf.d/xdebug.ini
    

    host.docker.internal is for Mac and Windows. More Information

  2. in host machine, open PhpStorm

    • Preferences -> Languages & Frameworks -> PHP -> Debug -> DBGp Proxy

      IDE Key: XDEBUG_ECLIPSE HOST: {{host machine IP address}} Port: 9000

    • Go to Preferences -> Languages & Frameworks -> PHP -> Servers

      Click +, Give it a name, Host is the address on which your application is running(in my case it is localhost) and Port number for your application(8090 for my application)

      I was not able to figure out what should be the path mappings, so I am not covering that part. It does not harm if you do not set it up but slows your application by some seconds.

      If you cannot figure out mappings then make sure you uncheck the checkbox Force break at first line when no mapping specified which can be found in Preferences -> Languages & Frameworks -> PHP -> Debug

  3. Install chrome plugin Xdebug Helper, and follow the instructions provide there.

  4. Final step would be enable listener in PhpStorm. Run -> Start Listening for PHP Debug Connections

  5. Enjoy debugging by setting up breakpoints.