I've a problem with xdebug in my dev environment
FROM library/php:5.5-apache
RUN apt-get -qqy update && apt-get -qqy install \
libpq-dev \
libmcrypt-dev \
libxml2-dev \
ssl-cert \
vim \
git \
mc \
&& rm -r /var/lib/apt/lists/*
# compile and add xdebug
RUN pecl install xdebug \
&& echo "zend_extension=xdebug.so" >> "/usr/local/etc/php/conf.d/xdebug.ini"
# configure apache and vhosts
RUN a2enmod rewrite ssl \
&& a2ensite 000-default default-ssl
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_RUN_DIR /var/run/apache2
ENV APACHE_PID_FILE /var/run/apache2/apache2.pid
ENV APACHE_LOCK_DIR /var/lock/apache2
CMD ["apache2-foreground"]
Xdebug settings:
[xdebug]
xdebug.remote_enable=1
xdebug.remote_autostart=0
xdebug.remote_host=172.17.42.1
xdebug.remote_port=9000
Everything works good but one thing. When debbuging code:
<?php
class A {
static private $a;
static public function init() {
self::$a = 123;
}
}
A::init();
If i set breakpoint on self::$a = 123; or step into the line then i get:
Fatal error: Access to undeclared static property: A::$a
If i don't step into that line debugging session continous without any problem.
I tried different xdebug versions, different debug clients (PhpStorm and Netbeans), different ways to install xdebug (pecl, compile from source). Nothing worked. I believe there is some problem in the the official image.
Same here, tested with 5.5.x and 5.6.x with various versions of xdebug.
Same code can be debugged perfectly fine using the same php versions install from the Jessie apt repo.
Same here, with 5.3, 5.4, 5.5 always newest cgi version self compiled - now using the Zend-Debugger which drives me crazy because it's that slow :-(
Any idea on the cause of the problem and how we could fix the images?
Just a "me too" from here. Been driving me nuts for a couple of days.
Welcome me to the club as well.
+1 for having to deal with weird fatal errors for perfectly fine code.
Same issue here with the following Dockerfile
FROM php:5.6-apache
COPY ./server/vhost.conf /etc/apache2/sites-enabled/vhost.conf
RUN a2enmod ssl
RUN a2enmod headers
RUN a2enmod rewrite
RUN docker-php-ext-install pdo_mysql mbstring
RUN pecl install -o -f xdebug \
&& rm -rf /tmp/pear \
&& echo "zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so" > /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_handler=dbgp" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_port=9000" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_connect_back=1" >> /usr/local/etc/php/conf.d/xdebug.ini
Presumably xdebug is a remote debugger what os and version is the debug client connecting to on the containers debug server port (9000).
Got some questions:
@jfilipczyk how are your referencing xdebug.ini? host volume mapping? Your xdebug setup differs slightly from @parrisvarney because you're using what looks like the docker0 as a static ip xdebug client.
@parrisvarney your path to xdebug differs from @jfilipczyk is that normal?
Probably unrelated, but has anyone tried UNIX socket option instead of TCP? You can map UNIX sockets using -v.
@booyaa I've never seen the xdebug path configured as a relative path, but I don't think that's the issue since if it's incorrect the remote debugger wouldn't work at all.
The issue we're seeing is that a seemingly incorrect fatal error arises during run time when a value is assigned to a static class member. This only happens when a breakpoint is set the in the file containing that assignment. Both the php program and xdebug behave normally if the breakpoint is not set.
This issue started last week for me when I switched from a custom Vagrant box build to this premade Docker build, at the same time upgrading from php5.3 to php5.6. The work around is easy enough for me since the error occurs in a config file (don't place a breakpoint), but the scenario is similar enough to what @jfilipczyk is experiencing that I figured I'd add my use case.
I have the same issue without a docker.
has somebody found an solution or an step-try-to-follow?
As noted before, this effect only happens in the official PHP 5 docker builds. When building a PHP 5 container from jessie or a recent ubuntu, xdebug works just fine.
The official PHP 7 builds also don't show the erroneous behavior.
+1. It is happening on the official 5.6 image
+1 =(
:+1: Any workaround?
There is no known workaround except switch to a different image.
To describe the issue in more detail this only happens after the first breakpoint of a static type. Hitting next breakpoint simple breaks xdebug on this image.
I would love to correct the code with this image but I do not know where to begin as I have never seen an issue as described above.
@codeorganic which image i can use as alternative?
Looks like it's xdebug issue https://bugs.xdebug.org/view.php?id=1185. waiting for fix
@codeorganic having a suggested alternative would be helpful.
To describe the issue in more detail this only happens after the first breakpoint of a static type. Hitting next breakpoint simple breaks xdebug on this image.
In relation to that statement, I'm pretty sure I tried setting breakpoints that were before the static variable reference and was able to step through the code until it hit the static reference.
@ihor-sviziev When I ran across this bug about 2 weeks ago, I switched to a custom container. I don't guarantee it's bug-free. It's also somewhat customized to our own development environment and subject to change as our development needs change. It may be a helpful jump-off point, though.
@ihor-sviziev you also may start with a recent debian or ubuntu container and just install your desired PHP version and extensions via Dockerfile. Works pretty well for me.
@willydee could you send your Dockerfile where xdebug works good for you?
Sure. This is for PHP 5.6; for the latest PHP 7 you may use the official image, which does not show this debugging misbehaviour.
FROM ubuntu:latest
# To use the latest stable PHP version:
RUN apt-get update \
&& apt-get install -y --allow-unauthenticated --no-install-recommends \
software-properties-common python-software-properties
RUN add-apt-repository ppa:ondrej/php
# Add here whatever extensions you might need
RUN apt-get update \
&& apt-get install -y --allow-unauthenticated --no-install-recommends \
php5.6-fpm \
php5.6-xdebug
# Cleanup caches to keep image size small
RUN rm -r /var/lib/apt/lists/*
RUN rm -r /var/cache/apt/*
# For your own php.ini directives
COPY custom.ini /etc/php/5.6/fpm/conf.d/custom.ini
# For your own FPM pool directives
COPY www.conf /etc/php/5.6/fpm/pool.d/www.conf
# Make sure the pidfile directory exists
RUN mkdir /run/php
CMD ["php-fpm5.6", "--nodaemonize", "--fpm-config", "/etc/php/5.6/fpm/php-fpm.conf"]
I've contacted with Derick Rethans (Xdebug developer), gived him information about this issue and he was able to reproduce this issue and gave following response:
It's not a bug in Xdebug and it doesn't seem to be that the bug is in PHP either, but rather in the compiler that Jessie uses by default.
So the current conclusion is: compiler bug (or weird interaction between compiler and PHP).
I haven't had the time to file a bug for PHP yet, but I have mailed internals and cc-ed some PHP devs, but they don't seem interested :-(.
You can work around it by changing the -O2 to -O0 in the Makefile file after running "./configure" but before "make". Before you run "./configure", don't forget to run "make clean" first.
I'll try to prepare Dockerfile with that workaround little bit later. I hope it will help us.
Derick also reported bug to PHP: https://bugs.php.net/bug.php?id=73545
The fix has been committed.
[2016-12-01 15:31 UTC] [email protected]
The fix for this bug has been committed.Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.For Windows:
http://windows.php.net/snapshots/
Thank you for the report, and for helping us make PHP better.
Looks like this fix pushed to master & php-5.6 branches. I hope it will be included to 5.6.29.
https://github.com/php/php-src/commit/1cd566e13f915ccd06a1140d04d4d946748ad021
Unfortunately that fix wasn't added to 5.6.29. Waiting for next release...
That commit was included to 5.6.30, but this issue still reproducing =(
@derickr any ideas?
As I could reproduce this without Xdebug in the mix, I don't think there is much I can do about it.
This is a deal breaker for 5.6.3... Could we mention this issue in the readme?
@ihor-sviziev Are you sure it was the same problem again?
The below worked for me:
FROM php:5.6.3-apache
# XDebug
RUN yes | pecl install xdebug \
&& yes | apt-get update \
&& yes | apt-get install php5-xdebug \
&& echo "zend_extension=/usr/lib/php5/20131226/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=off" >> /usr/local/etc/php/conf.d/xdebug.ini
Previous to this I had: docker-php-ext-enable xdebug somewhere in the above.
@derickr If that question was actually meant for me, yes same issue (Fatal error upon access of static class property).
Just another "same here" from my side. PHP 5.6.30
If it's helpful to anyone, I've made https://github.com/chrissound/dockercompose_phpapachemysql_ubuntu
You're able to install Xdebug following vanilla Ubuntu instructions.
bingo. Same here .
PHP 5.6.30 (cli) (built: Jul 4 2017 04:28:04)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Xdebug v2.5.5, Copyright (c) 2002-2017, by Derick Rethans
@nei did you try my solution a bit further up?
I'm closing given the solution posted above in https://github.com/docker-library/php/issues/133#issuecomment-304933175 -- this doesn't seem to be an issue specific to our images, but rather the combination of Jessie's compiler + PHP + Xdebug. Since then, PHP has been updated with a fix, _and_ some images are on Stretch (https://github.com/docker-library/php/issues/504).
For further discussion of this topic, I'd recommend posting to the Docker Community Forums, the Docker Community Slack, or Stack Overflow in order to capture a wider user base. Thanks!
I'm looking for a workaround for php 5.4
"apt-get install php5-xdebug" it only works for >=5.6
Still had this problem on PHP 5.6.40.
Constructed the following for my Dockerfile (basing off of official PHP image):
FROM php:5.6-fpm-stretch
(...)
# Compile and install xdebug with the static property fix
RUN BEFORE_PWD=$(pwd) \
&& mkdir -p /opt/xdebug \
&& cd /opt/xdebug \
&& curl -k -L https://github.com/xdebug/xdebug/archive/XDEBUG_2_5_5.tar.gz | tar zx \
&& cd xdebug-XDEBUG_2_5_5 \
&& phpize \
&& ./configure --enable-xdebug \
&& make clean \
&& sed -i 's/-O2/-O0/g' Makefile \
&& make \
# && make test \
&& make install \
&& cd "${BEFORE_PWD}" \
&& rm -r /opt/xdebug
(...)
Now works. Hope this solution helps someone that wishes to keep using the official PHP images. Saw a comment that it only affects Debian 'jessie', but had no luck with 'stretch' either :(
Same problem with php:5.4.45-apache and pecl install xdebug-2.4.1 & docker-php-ext-enable xdebug. Guess i have to build the image myself...
Still had this problem on PHP 5.6.40.
Constructed the following for my Dockerfile (basing off of official PHP image):
FROM php:5.6-fpm-stretch (...) # Compile and install xdebug with the static property fix RUN BEFORE_PWD=$(pwd) \ && mkdir -p /opt/xdebug \ && cd /opt/xdebug \ && curl -k -L https://github.com/xdebug/xdebug/archive/XDEBUG_2_5_5.tar.gz | tar zx \ && cd xdebug-XDEBUG_2_5_5 \ && phpize \ && ./configure --enable-xdebug \ && make clean \ && sed -i 's/-O2/-O0/g' Makefile \ && make \ # && make test \ && make install \ && cd "${BEFORE_PWD}" \ && rm -r /opt/xdebug (...)Now works. Hope this solution helps someone that wishes to keep using the official PHP images. Saw a comment that it only affects Debian 'jessie', but had no luck with 'stretch' either :(
Note to all :+1: this from @Wilkolicious is the solution. it works on PHP 5.6 on Debian 8 (and even for PHP 5.3 on Debian 8)
The solution from Wilkolicious worked for me on PHP 5.4.45 and Xdebug 2.4.1 on Debian Jessie, docker image php:5.4-fpm. I just replaced 2_5_5 with 2_4_1 in both places in his instructions.
I still needed to do RUN docker-php-ext-enable xdebug after the RUN line he gave.
BEFORE
RUN pecl install xdebug-2.4.1
RUN docker-php-ext-enable xdebug
AFTER
RUN BEFORE_PWD=$(pwd) \
&& mkdir -p /opt/xdebug \
&& cd /opt/xdebug \
&& curl -k -L https://github.com/xdebug/xdebug/archive/XDEBUG_2_4_1.tar.gz | tar zx \
&& cd xdebug-XDEBUG_2_4_1 \
&& phpize \
&& ./configure --enable-xdebug \
&& make clean \
&& sed -i 's/-O2/-O0/g' Makefile \
&& make \
# && make test \
&& make install \
&& cd "${BEFORE_PWD}" \
&& rm -r /opt/xdebug
RUN docker-php-ext-enable xdebug
Most helpful comment
Still had this problem on PHP 5.6.40.
Constructed the following for my Dockerfile (basing off of official PHP image):
Now works. Hope this solution helps someone that wishes to keep using the official PHP images. Saw a comment that it only affects Debian 'jessie', but had no luck with 'stretch' either :(