docker-compose-lamp
docker-compose-lamp copied to clipboard
[BUG] Xdebug does not work
Describe the bug
Xdebug does not work when trying to debug the php application.
which Branch / PHP Version are you using ? php8
Steps to reproduce Steps to reproduce the behavior:
- Clone sample.env to .env
- Run in terminal:
docker-composer up -d
- Open VS Code
- Install the Official PHP Debug Extension by Felix Becker
- Open docker-compose-lamp directory in VS Code
- Add the following launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003,
"pathMappings": {
"/var/www/html": "${workspaceFolder}/www"
}
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 0,
"runtimeArgs": [
"-dxdebug.start_with_request=yes"
],
"env": {
"XDEBUG_MODE": "debug,develop",
"XDEBUG_CONFIG": "client_port=${port}"
}
},
{
"name": "Launch Built-in web server",
"type": "php",
"request": "launch",
"runtimeArgs": [
"-dxdebug.mode=debug",
"-dxdebug.start_with_request=yes",
"-S",
"localhost:0"
],
"program": "",
"cwd": "${workspaceRoot}",
"port": 9003,
"serverReadyAction": {
"pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
"uriFormat": "http://localhost:%s",
"action": "openExternally"
}
}
]
}
- Run and debug using these settings
Expected behavior If you set a breakpoint, the debugger should stop at execution.
Desktop (please complete the following information):
- OS: Windows 10
- Browser: Chrome (version 96.0.4664.110 (Official Build) (64-bit))
- Docker Version:
docker -v
Docker version 20.10.11, build dea9396
Additional context The problem will still persist even if the port 9003 is explicitly exposed through docker-compose.yml
I have same problem with php 7.4, i solution was add lines in
Install xdebug
RUN pecl install xdebug-2.8.0
&& echo 'zend_extension='$(find /usr/local/lib/php/extensions/ -name xdebug.so)'\n
xdebug.mode=debug\n
xdebug.remote_enable=1\n
xdebug.remote_host=host.docker.internal\n
xdebug.remote_enable=1\n
xdebug.remote_autostart=1' >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
docker-php-ext-enable xdebug
in dockerfile from bin/php74 and folder config/php memory_limit = 1G post_max_size = 1G upload_max_filesize = 1G max_file_uploads = 500 max_execution_time=600 xdebug.remote_enable=1 xdebug.remote_host=127.0.0.1 xdebug.remote_port="9000" xdebug.remote_autostart=1 xdebug.remote_connect_back=1 xdebug.idekey = 'xDOCKERx' xdebug.var_display_max_depth = -1 xdebug.var_display_max_children = -1 xdebug.var_display_max_data = -1
in php.ini.
and you launch.json
"pathMappings": {
"/var/www/html/
}
maybe change sintax xdebug for xdebug 3
Hi, we just added new code and better documentation to the project regarding xdebug. Please let me know if your issue is still a thing, or if I can close this one :) Thank you
on php version 7.* the problem still persist on php 8 seems to work properly
I also have a problem with Xdebug. I tried on PHP74 and PHP8 - not work. Any advice?
I also have a problem with Xdebug. I tried on PHP74 and PHP8 - not work. Any advice?
Workaround - I jumped to the old commit 52defc2. With this version XDebug works.
The main issue with xdebug is in docker-compose file:
XDEBUG_CONFIG: "client_host=host.docker.internal remote_port=${XDEBUG_PORT}"
extra_hosts:
- "host.docker.internal:host-gateway"
host.docker.internal - it is docker gateway IP, but VSCODE server listens 9003 port on webserver - not on gateway.
To fix it you should:
docker-compose down
remove an image of webserver (e.g lamp82-webserver):
docker rmi -f id_your_webserver_image
Comment string XDEBUG_CONFIG: "client_host=host.docker.internal remote_port=${XDEBUG_PORT}" in docker-compose.yml
Change xdebug.client_host value in config/php/php.ini
xdebug.client_host=localhost
And rebuild stack:
docker-compose up -d