How to setup vscode to work with xdebug and docker

  docker, visual-studio-code, vscode-debugger, xdebug

I’m trying to setup xdebug in my development environment and am having some problems.

Setup:

  • MacOS
  • PHP 7.4
  • xdebug 2.9.8

I believe xdebug is working properly as it was working before I decided to change my folder structure. When I launch xdebug in vscode the program does not stop at the specified breakpoints.

launch.json

{
  "version": "0.2.0",
  "configurations": [
  {
    "name": "Listen for XDebug",
    "type": "php",
    "request": "launch",
    "port": 9000,
    "log": true,
    "pathMappings": {
    "/var/www": "${workspaceFolder}/"
    }
  }]
}

Dockerfile

FROM php:7.4-apache

COPY /config/000-default.conf /etc/apache2/sites-available/000-default.conf

RUN apt-get update 
    && apt-get install -y git 
    && docker-php-ext-install mysqli pdo_mysql 
    && a2enmod rewrite

ADD config/php.ini /usr/local/etc/php

# xdebug must be 2.9.x for the settings below to work
RUN pecl install xdebug-2.9.8 && docker-php-ext-enable xdebug 
    # not yet in linux: host.docker.internal must specify ip 
    && echo "n 
    xdebug.remote_host = host.docker.internal n
    xdebug.default_enable = 1 n
    xdebug.remote_autostart = 1 n
    xdebug.remote_connect_back = 0 n
    xdebug.remote_handler = "dbgp" n
    xdebug.remote_enable = 1 n
    xdebug.remote_port = 9000 n
    xdebug.remote_log = /var/www/xdebug.log n
    " >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

# Remove access log from output while in development
RUN rm /var/log/apache2/access.log

EXPOSE 80 433

and my folder structure is:

/app
|--.vscode
|  --launch.json
|--config
|  --Dockerfile
|  --vendor
|  --...
|--public
|  --...
|--src
|  --...

Source: Docker Questions

LEAVE A COMMENT