'Can't enable Docker Xdebug
I am trying to use Xdebug on Docker, I'm using Debian, PHP 8. Cannot make a connection with Xdebug. Won't give any errors.
Since I don't get any errors or logs can't figure out what is wrong with my configurations.
Everything builds normally with the configurations below. Could someone help me activate Xdebug?
Dockerfile:
FROM debian:stretch-slim as builder
RUN mkdir -p /usr/share/man/man1
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends wget gnupg2 unzip curl cron make \
locales ca-certificates apt-transport-https default-mysql-client-core sendmail \
default-jre-headless ca-certificates-java
RUN sed -i 's/mozilla\/DST_Root_CA_X3.crt/!mozilla\/DST_Root_CA_X3.crt/g' /etc/ca-certificates.conf
RUN update-ca-certificates
RUN wget -q https://packages.sury.org/php/apt.gpg -O- | apt-key add - && \
echo "deb https://packages.sury.org/php/ stretch main" | tee /etc/apt/sources.list.d/php.list && \
cd /etc/apt/sources.list.d && \
rm -rf ondrej-ubuntu*
RUN apt-get update && apt-get install -y \
git \
zip \
unzip \
sudo \
libzip-dev \
libicu-dev \
libbz2-dev \
libpng-dev \
libjpeg-dev \
libmcrypt-dev \
libreadline-dev \
libfreetype6-dev \
g++ \
nano \
vim \
php-xdebug
RUN curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | bash -
RUN apt-get update && apt-get install -y nodejs
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive \
apt-get install -y --no-install-recommends \
php8.0 \
php8.0-mysql \
php8.0-gd \
php8.0-xml \
php8.0-mbstring \
php8.0-curl \
libapache2-mod-php8.0 \
php8.0-intl \
php8.0-soap \
php8.0-zip \
php8.0-ldap \
php8.0-dev \
php-pear \
mysql-client \
apache2 \
php-xdebug && \
update-alternatives --set php /usr/bin/php8.0 && \
a2enmod php8.0 && \
a2enmod rewrite && \
a2enmod ssl
RUN echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen && \
echo "tr_TR.UTF-8 UTF-8" >> /etc/locale.gen && \
locale-gen
RUN apt-get -y autoremove wget unzip && apt-get -y clean && \
rm -rf "/tmp/"* "/var/cache/apt" "/usr/share/man" "/usr/share/doc" "/usr/share/doc-base" "/usr/share/info/*" >> /dev/null
RUN chown -R www-data. /var/www/html
RUN apt-get -y autoremove && apt-get -y clean && \
rm -rf "/tmp/"* "/var/cache/apt" "/usr/share/man" "/usr/share/doc" "/usr/share/doc-base" "/usr/share/info/*" >> /dev/null
RUN curl -Ss https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
WORKDIR /var/www/html
RUN a2enmod rewrite
CMD service apache2 restart
ENTRYPOINT ["/usr/sbin/apache2ctl"]
CMD ["-D", "FOREGROUND"]
EXPOSE 80
docker-compose.yml
version: "3.3"
networks:
my_network:
volumes:
my_volume:
services:
mysqllatest:
image: mysql:latest
container_name: mysqllatest
volumes:
- my_volume:/var/lib/mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
tty: true
environment:
MYSQL_DATABASE: local_db
MYSQL_USERNAME: root
MYSQL_PASSWORD: toor
MYSQL_ROOT_PASSWORD: toor
MYSQL_SERVICE_NAME: mysql
ports:
- "3306:3306"
networks:
- my_network
php8debian:
container_name: php8debian
build: ./base/
volumes:
- ../:/var/www/html/
- ./server/php/vhost/000-default.conf:/etc/apache2/sites-enabled/000-default.conf
- ./server/php/conf.d/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
ports:
- 80:80
extra_hosts:
- "mysite.test:127.0.0.1"
stdin_open: true
tty: true
networks:
- my_network
xdebug.ini
zend_extension=xdebug.so
[XDebug]
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_port = 9003
xdebug.client_host = 'host.docker.internal'
xdebug.idekey = VSCODE
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003,
"hostname": "0.0.0.0",
"pathMappings": {
"/var/www/html": "${workspaceRoot}/my_site"
},
"log": true
}
]
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
