[Be careful about changing the version of Xdebug! ] Create a development environment with Xdebug3 + docker + VS Code


I wanted to create a PHP debug environment using Xdebug in the docker (windows) + VSCode development environment. Since the version of xdebug has increased from 2 to 3, the description method of php.ini has changed a lot, so I will share it as a memo.


Docker Desktop (OS:Windows 10 Home) I noticed that Docker Desktop can be used on windows 10 Home. If you haven't tried it yet, we recommend installing it. Thanks to this, you can create a development environment in much the same way as on a Mac.

Visual Studio Code VS Code is popular these days. It is convenient because it has many extensions.

Xdebug 3 (installed in Docker container)

Create a PHP + Apache container and install Xdebug in it. It is convenient because you do not need to install any PHP other than the above two in the local environment.

If you install Xdebug without specifying a version, version 3 is now installed. Along with this, the way of writing php.ini has changed. (Details will be explained below)

Various installations

1. Install Docker Desktop

Install Docker Desktop on Windows Home (https://docs.docker.jp/docker-for-windows/install-windows-home.html)

I think that there is no problem if you follow the procedure on the following page. (Windows 10 Home)

2. Install Visual Studio Code

VSCode Download Page

Download and install from here.

3. Install VS Code extension

Install "PHP Debug" as an extension of VS Code. Procedure: Install "PHP Debug"-> "PHP Debug" in the sidebar "Extensions"-> Search field

Please restart VS Code after installation. install.png

Install Xdebug in Docker container

0. Directory structure

This time it was a sample, so I configured it easily. folder.png

1. Description of DockerFile, docker-compose.yml

This time, to make it easier, create a Dockerfile to install Xdebug with a command in a PHP + Apeche container.


FROM php:7.3-apache

RUN apt-get update && apt-get install -y \
    git \
    unzip \

#xdebug installation
RUN pecl install xdebug \
    && docker-php-ext-enable xdebug

Also describe docker-compose.yml as follows according to the directory structure.


version: '3'

            context: ./docker
        container_name: app
        stdin_open: true
        tty: true
            - '5000:80'
            - ./src:/var/www/html
            - ./docker/php.ini:/usr/local/etc/php/php.ini

2. Create and describe launch.json

VS Code sidebar "Run"-> Click "Create launch.json file"-> Select "PHP" from the environment selection At this stage, launch.json will be automatically generated and the directory structure will be as shown in the image below. launch.png Add pathMappings to the automatically generated launch.json and do as follows.


    "version": "0.2.0",
    "configurations": [
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9000,
            "pathMappings": {
                "/var/www/html/": "${workspaceRoot}/src"
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9000

3. Description of php.ini (main subject)

This is the part that made me decide to write this article. I wrote it as follows.


;Enable remote debugging
;Automatic start of remote debugging
;Host designation
;Specifying the port on the host side
;Specify VSCODE as IDE

It was necessary to change the writing style when the version of Xdebug changed from 2 to 3.

Official Document: Upgrading from Xdebug 2 to 3

With the settings described this time, the following changes are required. In addition to this, it seems that the writing style has changed in various ways, so please refer to the official document for details.

Enable remote debugging

Xdebug 2: xdebug.remote_enable=1 Xdebug 3: xdebug.mode=debug

Automatic start of remote debugging

Xdebug 2: xdebug.remote_autostart=1 Xdebug 3: xdebug.start_with_request=yes

Host designation

Xdebug 2: xdebug.remote_host=host.docker.internal Xdebug 3: xdebug.client_host=host.docker.internal

Specifying the port on the host side

Xdebug 2: xdebug.remote_port=9000 Xdebug 3: xdebug.client_port=9000

4. Create index.php

Try it at the sample level.


    echo 'Hello World';

5. Build and launch a Docker container

After starting Docker Desktop, execute the following command from View Windows PowerShell or VS Code-> Terminal.


$ docker-compose up -d --build

Run debug

1. Set breakpoints, debug execution

Click to the left of the row you want to place to set a breakpoint. breakpoint.png In this state, press the F5 key or press the green triangle mark "Start Debugging" to execute debugging.

2. Connect with browser

I set port number 5000 with docker-compose, so connect from the browser. port.png

3. Check with VS Code

If you execute steps 1 and 2, it will stop at the breakpoint as shown in the image below. This is a success! stop.png

in conclusion

Due to the changes that accompany the version change of Xdebug, I took time to identify the cause of the debug environment not working. I hope there is a similar person and it helps.

Recommended Posts

[Be careful about changing the version of Xdebug! ] Create a development environment with Xdebug3 + docker + VS Code
Create a Spring Boot development environment with docker
Build a Java development environment with VS Code
[Environment construction] Build a Java development environment with VS Code!
Debug the VSCode + Docker + PHP development environment with XDebug.
Until you build a Nuxt.js development environment with Docker and touch it with VS Code
I tried to create a padrino development environment with Docker
About the solution of the error that occurred when trying to create a Japanese file of devise in the Docker development environment
Create a Vue3 environment with Docker!
[Note] A story about changing Java build tools with VS Code
Building a haskell environment with Docker + VS Code on Windows 10 Home
One file of Docker x Laravel threat! Build a local development environment with the minimum configuration
Prepare Java development environment with VS Code
Create a MySQL environment with Docker from 0-> 1
Create Spring Boot-gradle-mysql development environment with Docker
Build a Wordpress development environment with Docker
A record of setting up a Java development environment with Visual Studio Code
Template: Build a Ruby / Rails development environment with a Docker container (Ubuntu version)
Create a java web application development environment with docker for mac part2
Template: Build a Ruby / Rails development environment with a Docker container (Mac version)
Build a Docker-based development environment on Windows 10 Home 2020 ver. Part 2 VS Code should make the Docker development environment comfortable
[Memo] Create a CentOS 8 environment easily with Docker
Build a WordPress development environment quickly with Docker
Improve the performance of your Docker development environment
A reminder of Docker and development environment construction
Create Spring Boot environment with Windows + VS Code
Build a development environment to create Ruby on Jets + React apps with Docker
Build Java development environment with VS Code on Mac
Create a Java (Gradle) project with VS Code and develop it on a Docker container
Docker the development environment of Ruby on Rails project
Build ruby debug environment with VS Code of Windows 10
The procedure I did when I prepared the environment of gradle + Java with VS Code (Windows 10)
[First team development ③] Share the development environment created with Docker
[Note] Create a java environment from scratch with docker
How to build Java development environment with VS Code
Create a Java (Maven) project with VS Code and develop it on a Docker container
Beginners create Spring Tools Suite environment with VS Code
Create Chisel development environment with Windows10 + WSL2 + VScode + Docker
I tried to create a java8 development environment with Chocolatey
I made a development environment with rails6 + docker + postgreSQL + Materialize.
Create a Docker image with the Oracle JDK installed (yum
Install by specifying the version of Django in the Docker environment
Java web application development environment construction with VS Code (struts2)
A memo to start Java programming with VS Code (2020-04 version)
Docker management with VS Code
Create a VS Code Plugin.
What I was addicted to when updating the PHP version of the development environment (Docker) from 7.2.11 to 7.4.x
I tried to take a look at the flow of Android development environment construction with Android Studio
[SAP] Create a development environment with NW AS ABAP Developer Edition (1)
Summary of steps for developing in Docker container with VS Code
I tried to build the environment of PlantUML Server with Docker
Procedure for building a Rails application development environment with Docker [Rails, MySQL, Docker]
Install Rails in the development environment and create a new application
Build a development environment for Django + MySQL + nginx with Docker Compose
Build a Node.js environment with Docker
About the current development environment (Java 8)
Create SolrCloud verification environment with Docker
About the matter that tends to be confused with ARG of Dockerfile which is a multi-stage build
Getting Started with Docker with VS Code
Java development environment (Mac, VS Code)
Make a daily build of the TOPPERS kernel with Gitlab and Docker