As the name points out the command docker-php-ext-install is meant to install a PHP extension – an .so file. Using PECL is just another way of installing extensions, so, by trying to use docker-php-ext-install after a pecl install you are trying to do twice the same thing.
And as the end of the pecl install points out:
You should add "zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20190902/xdebug.so" to php.ini
Which would be what docker-php-ext-enable is meant to do.
So, your working Dockerfile would be:
FROM php:7.4
RUN pecl install xdebug-3.1.5 \
&& docker-php-ext-enable xdebug
This is actually pointed out in the documentation of the php image:
PECL extensions
Some extensions are not provided with the PHP source, but are instead available through PECL. To install a PECL extension, use
pecl installto download and compile it, then usedocker-php-ext-enableto enable it:FROM php:7.4-cli RUN pecl install redis-5.1.1 \ && pecl install xdebug-2.8.1 \ && docker-php-ext-enable redis xdebug
Source: https://hub.docker.com/_/php
Answer from β.εηοιτ.βε on Stack OverflowRUN apk add --no-cache $PHPIZE_DEPS \
&& pecl install xdebug-2.9.2 \
&& docker-php-ext-enable xdebug \
I found this instructions here on how to set it up. Add it to the end of the php.dockerfile:
# Install base packages
RUN apk update
RUN apk upgrade
# xdebug with VSCODE
ENV XDEBUG_VERSION=2.9.2
RUN apk --no-cache add --virtual .build-deps \
g++ \
autoconf \
make && \
pecl install xdebug-${XDEBUG_VERSION} && \
docker-php-ext-enable xdebug && \
apk del .build-deps && \
rm -r /tmp/pear/* && \
echo -e "xdebug.remote_enable=1\n\
xdebug.remote_autostart=1\n\
xdebug.remote_connect_back=0\n\
xdebug.remote_port=9001\n\
xdebug.idekey=\"VSCODE\"\n\
xdebug.remote_log=/var/www/html/xdebug.log\n\
xdebug.remote_host=host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
# Change TimeZone
RUN apk add --update tzdata
ENV TZ=Europe/Bucharest
EDIT: You should also remove the xdebug port in docker-compose.yml (In case you added it)
For **Visual Studio Code** Here is the kaunch.json I used:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9001,
"pathMappings": {
"/var/www/html/public": "${workspaceFolder}/src/public"
},
}
]
}
Videos
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/
try this:
RUN pecl install xdebug && docker-php-ext-enable xdebug