dmstr/docker-php-yii2

Enable xdebug

Closed this issue · 14 comments

How would I go to enable xdebug? I understand I change it in the dockerfile to enable, but probably need more than that?

I'm working from PHPStorm with the docker plugin enabled.

Simply set PHP_ENABLE_XDEBUG=1 (does currently not work on alpine versions), but the standard image should be fine, see also https://github.com/dmstr/docker-php-yii2/blob/master/php-7.0/image-files/usr/local/bin/docker-entrypoint.sh#L17

Works with changes in /usr/local/etc/php/conf.d/xdebug.ini

zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_port=9000
xdebug.remote_autostart=1
xdebug.remote_connect_back=0
xdebug.idekey=PHPSTORM
; Host IP in your network (ifconfig / ipconfig) Given me by DHCP of my router
xdebug.remote_host=192.168.1.100

Followed by this instruction https://shippingdocker.com/xdebug/get-working/

So Xdebug should be available in PHP-fpm (Debian) and Alpine image, see also https://git.hrzg.de/dmstr/docker-php-yii2/builds/74789

Is connecting to PHPstorm also an issue?

After setting PHP_ENABLE_XDEBUG=1 this is what can be seen in logs

php_1     | /usr/local/bin/docker-php-ext-enable: line 83: nm: not found
php_1     | Enabled xdebug
php_1     | forego  | starting nginx.1 on port 5000
php_1     | forego  | starting phpfpm.1 on port 5100
php_1     | forego  | starting cron.1 on port 5300
php_1     | phpfpm.1 | [18-Feb-2017 07:41:00] NOTICE: PHP message: PHP Warning:  Xdebug MUST be loaded as a Zend extension in Unknown on line 0
php_1     | phpfpm.1 | [18-Feb-2017 07:41:00] NOTICE: fpm is running, pid 27
php_1     | phpfpm.1 | [18-Feb-2017 07:41:00] NOTICE: ready to handle connections

Can you check if it's available despite the errors. Looks OK to me when looking into Yii2 Debug Panel.

But the errors should be fixed, nonetheless.

CC: @handcode

Now it's not working, so I can't find a reason why.

Found working config. Here it is;

zend_extension=xdebug.so
xdebug.remote_connect_back=1
xdebug.remote_port=9000
xdebug.max_nesting_level=700
xdebug.remote_enable=1
xdebug.idekey="PHPSTORM"
xdebug.remote_log="/tmp/xdebug.log"

Is this correct for production environment too?

And another moment, you have two configs for xdebug: xdebug.ini and docker-php-ext-xdebug.ini. I think it's not correct, there should be only one within correct config.

I wrote a tutorial about xdebug

Please have a look, I had some issues with connecting from the container to the host - but I think the custom network is an OK solution. I haven't found anything better (host- or bridge-networking don't work in more complex setups for me).

Having two .ini files in this case also seems OK to me. docker-php-ext-xdebug.ini is only loaded when the ENV variable PHP_ENABLE_XDEBUG is set, the other one is for configuration of values, it could be removed since you can configure all variables via XDEBUG_CONFIG.

Feedback appreciated.

@schmunk42 , thanks. I have the same config now as you described, didn't know about network interfering problems though. I'm using the same network as default one, no problems so far.

I'm using the same network as default one, no problems so far.

Which Docker setup do you have? Docker-for-Mac/Win, Boot2docker, Linux native, Vagrant VM...?

On my first try I accepted all traffic on my phd5app_default bridge interface, but that broke several other things.

I'm using boot2docker on vmware and connecting to it from local machine.

Even I'm using connect back option for xdebug to not bother myself with browser plugin and enabling/disabling debug each time.

I'm using boot2docker on vmware and connecting to it from local machine.

Yeah, it appears easier with Xdebug in this setup. I am currently on native Linux, so there's no VM inbetween.

Even I'm using connect back option for xdebug to not bother myself with browser plugin and enabling/disabling debug each time.

I have the problem that yii app/setup on CLI in hanging and looking for the remote_host, I think - that's why I added it as a note.