Reputation: 1257
I'm trying to install the XDebug in a Docker container, but I'm getting the following error:
E: Unable to locate package php-xdebug
This is my Dockerfile:
FROM php:7.0-apache
RUN a2enmod rewrite
RUN docker-php-ext-install pdo pdo_mysql
RUN apt-get install php-xdebug -y
COPY php.ini /usr/local/etc/php/
COPY . /var/www/html/
When I'm running the same command in my computer, the XDebug is getting installed without any error:
apt-get install php-xdebug
Where might the problem be?
Upvotes: 29
Views: 80551
Reputation: 1257
I solved this by adding the following lines into my Docker file:
# "xdebug-2.9.0" for PHP<=7.4 — "xdebug" (3) for PHP>=8
ARG XDEBUG_VERSION="xdebug-2.9.0"
FROM php:7.0-apache
RUN a2enmod rewrite
RUN docker-php-ext-install pdo pdo_mysql
RUN yes | pecl install ${XDEBUG_VERSION} \
&& 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=off" >> /usr/local/etc/php/conf.d/xdebug.ini
COPY php.ini /usr/local/etc/php/
COPY . /var/www/html/
Upvotes: 48
Reputation: 75636
Just a note that use of xdebug.remote_enable
and xdebug.remote_host
is no longer correct as these options are renamed in xdebug v3 and now you should to use config names instead:
# For xdebug v3
RUN pecl install xdebug \
&& docker-php-ext-enable xdebug \
&& echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.client_host = host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
Docs:
Upvotes: 0
Reputation: 1014
I was using php8.0-alpine
in the dockerfile.
I was having an issue in installing xdebug
in the container,
so I changed the image to php8.0-alpine3.13
and works fine.
Seems like 3.14 was having some issue with xdebug.
Upvotes: 0
Reputation: 101
For PHP 7.3 I was able to install XDebug using the mlocati's docker-php-extension-installer.
My Dockerfile looks like this:
FROM php:7.3-apache
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
RUN install-php-extensions xdebug @composer
My docker-compose.yml
contains the following which allows the special host.docker.internal
name:
extra_hosts:
- "host.docker.internal:host-gateway"
My xdebug configuration file /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
looks like this:
[xdebug]
zend_extension=xdebug
xdebug.mode=develop,debug
xdebug.start_with_request = yes
xdebug.client_host = "host.docker.internal"
xdebug.client_ip = "9003"
xdebug.idekey="VSCODE"
xdebug.log=/tmp/xdebug_remote.log
More details are in a Gist describing my PHP Debugging in Docker setup.
Upvotes: 5
Reputation: 5905
Since xdebug version 3 there are breaking changes in config names.
RUN pecl install xdebug; \
docker-php-ext-enable xdebug
and for configuration:
{ \
echo "xdebug.mode=debug"; \
echo "xdebug.start_with_request=yes"; \
echo "xdebug.client_host=host.docker.internal"; \
echo "xdebug.client_port=9000"; \
} > /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
More info: https://xdebug.org/docs/upgrade_guide
Upvotes: 9
Reputation: 447
As of PHP 7.4 you only need this
RUN pecl install xdebug \
&& docker-php-ext-enable xdebug
And add this line to enable remote debugging
&& echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.remote_host = host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
Upvotes: 23