Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Xdebug does not work #190

Open
panchalkalpesh opened this issue Jan 5, 2022 · 6 comments
Open

[BUG] Xdebug does not work #190

panchalkalpesh opened this issue Jan 5, 2022 · 6 comments
Assignees

Comments

@panchalkalpesh
Copy link

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:

  1. Clone sample.env to .env
  2. Run in terminal: docker-composer up -d
  3. Open VS Code
  4. Install the Official PHP Debug Extension by Felix Becker
  5. Open docker-compose-lamp directory in VS Code
  6. 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"
            }
        }
    ]
}
  1. 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

@fhfrosacruz
Copy link

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/": "${workspaceFolder}"
}

maybe change sintax xdebug for xdebug 3

@MrOffline77
Copy link
Collaborator

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

@alainseys
Copy link

on php version 7.* the problem still persist on php 8 seems to work properly

@vilija19
Copy link

I also have a problem with Xdebug.
I tried on PHP74 and PHP8 - not work.
Any advice?

@vilija19
Copy link

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.

@vilija19
Copy link

vilija19 commented Mar 24, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants