I have created my own docker-compose and DockerFiles for a Laravel app. Everything is working as expected, but I can’t get Xdebug to work. I’ve run through a few tutorials on Xdebug with Windows, but no luck. I’m recently returning to Windows after running Mac for many years.
My Setup:
- Windows 10 Pro
- VSCode
- List item
- WSL2
- Docker Desktop
docker-composer.yml
# For more information: https://laravel.com/docs/sail
version: '3'
services:
# The Application
app:
container_name: 'mybot_laravel_app'
build:
context: './'
dockerfile: 'docker/app.dockerfile'
networks:
- 'frontend'
- 'backend'
working_dir: '/var/www'
volumes:
- './:/var/www'
env_file: '.env'
environment:
DB_HOST: ${DB_HOST:-mybot_mysql_database}
REDIS_HOST: ${REDIS_HOST:-cache}
APCU_VERSION:
XDEBUG_CONFIG: ${XDEBUG_CONFIG:-""}
# The Web Server
web:
container_name: 'mybot_nginx_server'
build:
context: './'
dockerfile: 'docker/web.dockerfile'
networks:
- frontend
volumes_from:
- app
ports:
- '${APP_PORT:-80}:80'
# The Database
database:
container_name: 'mybot_mysql_database'
networks:
- backend
image: 'mysql:8.0'
command: --default-authentication-plugin=mysql_native_password
volumes:
- 'dbdata:/var/lib/mysql'
environment:
MYSQL_DATABASE: ${DB_DATABASE:-mybot}
MYSQL_USER: ${DB_USERNAME:-root}
MYSQL_PASSWORD: ${DB_PASSWORD:-""}
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD:-""}
MYSQL_ALLOW_EMPTY_PASSWORD: 'no'
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
healthcheck:
test: ["CMD", "mysqladmin", "ping"]
redis:
image: 'redis:alpine'
ports:
- '${FORWARD_REDIS_PORT:-6379}:6379'
volumes:
- 'redis:/data'
networks:
- backend
healthcheck:
test: ["CMD", "redis-cli", "ping"]
mailhog:
image: 'mailhog/mailhog:latest'
ports:
- '${FORWARD_MAILHOG_PORT:-1025}:1025'
- '${FORWARD_MAILHOG_DASHBOARD_PORT:-8025}:8025'
networks:
- backend
networks:
frontend:
driver: bridge
backend:
driver: bridge
volumes:
dbdata:
redis:
app.dockerfile
FROM php:7.4-fpm-alpine
COPY composer.lock composer.json /var/www/
COPY database /var/www/database
WORKDIR /var/www
RUN apk add --no-cache autoconf gcc g++ libtool make
&& apk update
&& apk add --no-cache --virtual .deps
mysql-client
git
zip
libzip-dev
icu-libs
zlib
zlib-dev
openssh
imagemagick
imagemagick-libs
imagemagick-dev
libpng-dev
libwebp-dev
libxpm-dev
libjpeg-turbo-dev
freetype-dev
&& apk del --no-cache autoconf gcc g++ libtool make
&& apk del --no-cache libmcrypt-dev
COPY . /var/www
RUN chown -R www-data:www-data
/var/www/storage
/var/www/bootstrap/cache
ARG APCU_VERSION
ENV APCU_VERSION=${APCU_VERSION:-5.1.20}
RUN set -xe
&& apk add --no-cache --virtual .build-deps
$PHPIZE_DEPS
icu-dev
&& docker-php-ext-install
intl
pdo_mysql
&& pecl channel-update pecl.php.net
&& pecl install
apcu-${APCU_VERSION}
apcu_bc
imagick
redis
&& docker-php-ext-enable --ini-name 20-apcu.ini apcu
&& docker-php-ext-enable --ini-name 21-apc.ini apc
&& docker-php-ext-enable --ini-name 05-opcache.ini opcache
&& docker-php-ext-enable --ini-name 20-imagick.ini imagick
&& docker-php-ext-enable --ini-name 20-redis.ini redis
RUN set -xe
apk add --no-cache --virtual .build-deps zlib-dev
&& docker-php-ext-install exif
&& docker-php-ext-install pcntl
&& docker-php-ext-install bcmath
&& docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp --with-xpm --with-webp
&& docker-php-ext-install -j$(nproc) gd
&& apk del --no-cache zlib-dev
RUN apk add --no-cache --virtual .build-deps
libmcrypt
libltdl
&& apk add --no-cache --virtual .build-deps $PHPIZE_DEPS libmcrypt-dev
&& yes '' | pecl install -f mcrypt
&& docker-php-ext-enable mcrypt
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
&& php -r "if (hash_file('SHA384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
&& php composer-setup.php
&& php -r "unlink('composer-setup.php');"
&& mv composer.phar /usr/local/bin/composer
RUN apk add --no-cache $PHPIZE_DEPS
&& pecl install xdebug
&& docker-php-ext-enable xdebug
RUN echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
&& echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
&& echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
&& echo "xdebug.remote_autostart=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
&& echo "xdebug.remote_connect_back=0" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
&& echo "xdebug.remote_host=docker.for.mac.localhost" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
&& echo "xdebug.max_nesting_level=1500" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN apk add --update npm
CMD ["php-fpm"]
launch.json
{
// 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": 9000,
"pathMappings": {
"/var/www/public": "${workspaceFolder}/public",
"/var/www": "${workspaceFolder}",
},
"hostname": "localhost",
"xdebugSettings": {
"max_data": 65535,
"show_hidden": 1,
"max_children": 100,
"max_depth": 5
}
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
2
Answers
Thanks @derick,
I added to docker-compose.yml in the
environment
section on line 21and .env
Then altered line 84 in app.dockerfile
It's working as expected now.
pecl
will install Xdebug 3, and all your settings are still for Xdebug 2. Please go through the Upgrade Guide and adjust your settings.