Debug the VSCode + Docker + PHP development environment with XDebug.

Introduction

The project I was working on was a PHP application using Laravel, created by VS Code. I'm used to working with Java and Swift, but it's a reminder that I've been so addicted to PHP debugging for the first time in a while.

What i did

Since XDebug is used for debugging PHP, I read XDebug commentary article and read it (it is a very easy-to-understand article).

Many articles explain it carefully, so I will wrap up the details.

php.ini


;...abridgement

[XDebug]
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20190902/xdebug.so
xdebug.default_enable=1
xdebug.remote_port=9000
xdebug.remote_autostart=1
xdebug.remote_handler=dbgp
xdebug.remote_connect_back=0
xdebug.remote_host=host.docker.internal
xdebug.remote_log=/tmp/xdebug.log
xdebug.idekey=VSCODE

Dockerfile


FROM php:7.4-apache

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

#...abridgement

launch.json


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

With this feeling, I finished PHP initialization, Docker initialization, and XCode debug settings.

__ This doesn't work at all. __

solution

I messed with various parameters, but it didn't work at all and I gave up, but eventually I realized that it was a problem with the version of xdebug.

$ php -v | grep -i "xdebug"
    with Xdebug v3.0.2, Copyright (c) 2002-2021, by Derick Rethans

From Xdebug 2.x to 3.x, the __ setting value has changed. __ https://xdebug.org/docs/upgrade_guide It is described in detail and clearly in this document.

For example, xdebug.remote_log has been renamed to xdebug.log. No wonder, the log doesn't come out at all.

If you look at the detailed meaning there, the above php.ini is now correct.

php.ini


;...abridgement

[XDebug]
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20190902/xdebug.so
xdebug.mode=debug
xdebug.client_port=9000
xdebug.start_with_request=yes
xdebug.discover_client_host=0
xdebug.client_host=host.docker.internal
xdebug.log=/tmp/xdebug.log

That's all from the field.

Recommended Posts

Debug the VSCode + Docker + PHP development environment with XDebug.
Lightweight PHP 7.4 development environment created with Docker
WSL2 + VSCode + Docker development environment
[Vscode xdebug3.0 x PHP x Docker]
Create Chisel development environment with Windows10 + WSL2 + VScode + Docker
Build Go development environment with WSL2 + Docker Desktop + VSCode (Remote --Containers)
Laravel development environment construction with Docker (Mac)
Ruby on Rails development environment construction with Docker + VSCode (Remote Container)
Build a PureScript development environment with Docker
Prepare the format environment with "Rails" (VScode)
Create Spring Boot-gradle-mysql development environment with Docker
Build a Wordpress development environment with Docker
[Be careful about changing the version of Xdebug! ] Create a development environment with Xdebug3 + docker + VS Code
Build a Laravel / Docker environment with VSCode devcontainer
Prepare the JVM language development environment with WSL
Build a WordPress development environment quickly with Docker
Improve the performance of your Docker development environment
Rails development environment created with VSCode and devcontainer
Build a development environment for Docker, java, vscode
[First team development ②] Build an environment with Docker
Wordpress local environment construction & development procedure with Docker
Create a Spring Boot development environment with docker
Php settings with Docker
Disposable PHP with Docker
Docker the development environment of Ruby on Rails project
Build Docker + Laravel PHP + Vue.js development environment in 5 minutes
Build Java development environment with WSL2 Docker VS Code
Pytorch execution environment with Docker
[Docker] Rails 5.2 environment construction with docker
Build docker environment with WSL
I made a development environment with rails6 + docker + postgreSQL + Materialize.
Rails application development environment construction with Docker [Docker, Rails, Puma, Nginx, MySQL]
How to build Rails, Postgres, ElasticSearch development environment with Docker
I tried to build the environment of WSL2 + Docker + VSCode
[Vagrant] Prepare LAMP development environment with Vagrant (centos + apache + MySQL + PHP)
I tried to create a padrino development environment with Docker
Rails + MySQL environment construction with Docker
Create a Vue3 environment with Docker!
One file of Docker x Laravel threat! Build a local development environment with the minimum configuration
Build Couchbase local environment with Docker
Build a Node.js environment with Docker
[PDO → DB connection with docker, PHP]
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 build the environment of PlantUML Server with Docker
Procedure for building a Rails application development environment with Docker [Rails, MySQL, Docker]
Build environment with vue.js + rails + docker
About the current development environment (Java 8)
Build Rails environment with Docker Compose
Create SolrCloud verification environment with Docker
How to install Pry after building Rails development environment with Docker
Prepare a transcendentally simple PHP & Apache environment on Mac with Docker
Build a browser test environment using Capybara in the Docker development environment
PostgreSQL environment construction with Docker (from setup to just before development)
Create Laravel environment with Docker (docker-compose)
Build jooby development environment with Eclipse
[Environment construction with Docker] Rails 6 & MySQL 8
Build a development environment for Django + MySQL + nginx with Docker Compose
Build Unity development environment on docker
Build docker + laravel environment with laradock
Problems I was addicted to when building the digdag environment with docker
Creating a java web application development environment with docker for mac part1