Debug PHP with Xdebug in Docker with VSCode on Mac
NickName:Ted Logan Ask DateTime:2022-05-09T15:51:46

Debug PHP with Xdebug in Docker with VSCode on Mac

I am running a Symfony application inside a Docker-Container. I want to debug the code with VSCode on my mac. With Windows everything works fine. The debugger is connecting to the container, but does not stop at the breakpoints.

This is my launch.json

{
"version": "0.1.0",
"configurations": [{
        "name": "Listen for XDebug",
        "type": "php",
        "request": "launch",
        "port": 9003,
        "log": true,
        "externalConsole": false,
        "pathMappings": {
            "/srv/app": "${workspaceFolder}",
            "/srv/cssp/src/WorkingBundle": "${workspaceFolder}/src/WorkingBundle"
        },
        "ignore": [
            "**/vendor/**/*.php"
        ]
    },
]

In the php.ini I added

xdebug.mode=debug
xdebug.client_host=host.docker.internal
xdebug.start_with_request=trigger

My Dockerfile

FROM composer:latest AS composer
FROM php:7.2-apache-stretch


COPY --chown=33:33 . /srv/cssp
COPY .docker/vhost.conf /etc/apache2/sites-available/000-default.conf
COPY .docker/php.ini /usr/local/lib/
COPY .docker/php.ini /usr/local/lib/php
COPY .docker/php.ini /usr/local/etc/php

WORKDIR /srv/symfonyApp

ENV COMPOSER_ALLOW_SUPERUSER 1

COPY --from=composer /usr/bin/composer /usr/bin/composer

RUN chown -R www-data:www-data /srv/symfonyApp\
    && apt-get update \
    && apt-get -y install libpng-dev libjpeg-dev unzip\
    && docker-php-ext-install -j$(nproc) mbstring mysqli pdo pdo_mysql shmop zip gd \
    && a2enmod rewrite ssl socache_shmcb \
    && service apache2 restart \
    && composer install \
    && chown -R www-data:www-data /srv/symfonyApp\
    && useradd -rm -d /home/symfonyApp -s /bin/bash -g root -G sudo -u 503 cssp \
    && pecl install xdebug \
    && apt install nano \
    && docker-php-ext-enable xdebug \
    && apt-get install libfontconfig1 libxrender1 libxtst6

And my docker-compose.yml

version: '3.8'
services:
app:
    build:
      context: .
      dockerfile: .docker/Dockerfile
      image: symfonyApp-docker
    ports:
      - 8080:80
    links:
      - mysql
    volumes:
      - .:/srv/symfonyApp
    environment:
      PHP_IDE_CONFIG: 'serverName=localhost'
      XDEBUG_SESSION: 'VSCODE'
  mysql:
    image: mariadb:10.4.4
    container_name: symfonyApp_mysql
    volumes:
      - .docker/mysql/init:/docker-entrypoint-initdb.d

    restart: always
    ports:
      - 13306:3306
    environment:
      MYSQL_ROOT_PASSWORD: secret

Copyright Notice:Content Author:「Ted Logan」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/72168609/debug-php-with-xdebug-in-docker-with-vscode-on-mac

More about “Debug PHP with Xdebug in Docker with VSCode on Mac” related questions

Debug with XDebug, VSCode, and Docker

I'm trying to configure XDebug in the Docker from docker4drupal and VSCode, I get nothingh although I have follow this: https://medium.com/@jasonterando/debugging-with-visual-studio-code-xdebug-and-

Show Detail

Debug PHP with Xdebug in Docker with VSCode on Mac

I am running a Symfony application inside a Docker-Container. I want to debug the code with VSCode on my mac. With Windows everything works fine. The debugger is connecting to the container, but do...

Show Detail

Docker and XDebug not reading breakpoints VSCode

I have been using XDebug with PHP Version 7.0.* for the last 6 months on a MAC using remote debugging to a Docker container. I was running an older version of docker that was using VirtualBox to V...

Show Detail

Debug PHP with VSCode and Docker

I'm trying to debug a PHP app running on Docker with VSCode, but without success. In the past I was able to easily debug my PHP apps with VSCode running WAMP Server, but since I started working with

Show Detail

Docker xDebug not connecting to VSCode

I'm trying to set up php debugging with VSCode and xDebug, but xDebug can't connect to the host. Thus, VSCode doesn't hit any breakpoints either. When I start the debug listener in VSCode, run a B...

Show Detail

Setting up XDebug with Docker and VSCode

I set up a Laravel dev environment using Docker - nginx:stable-alpine, php:8.0-fpm-alpine and mysql:5.7.32. I install Xdebug from my php.dockerfile: RUN apk --no-cache add pcre-dev ${PHPIZE_DEPS} ...

Show Detail

PHP Xdebug, VSCode, Docker & MacOS - debugger not disconnecting

I've encountered a weird problem that seems to have either started appearing when the Xdebug extension was updated or Visual Studio Code received an update. When the debugger is active in VSCode the

Show Detail

Xdebug, Docker and VSCode on Windows 10

I am looking for some guidance on setting up Xdebug with Docker and VSCode on Windows 10. My docker settings are as follows, but I always get 'EADDRINUSE: address already in use :::9000' and never ...

Show Detail

Xdebug inside Docker on Mac is not working

I ported a local development setup from Linux to a new Mac machine and am having problems with getting Xdebug to work with PhpStorm in a Mac M1 Pro machine. I have one container with PHP where Xdeb...

Show Detail

Docker toolbox Mac OS Xdebug

I'm using Docker Toolbox (docker-machine) in Mac OS 10.13, and trying to use Xdebug with PHP 7.1. At first I configured the interpreter via Docker container in virtual machine: Then I add the Server

Show Detail