sprintcube / docker-compose-lamp

A basic LAMP stack environment built using Docker Compose.
MIT License
2.63k stars 1.41k forks source link

[BUG] Xdebug does not work #190

Open panchalkalpesh opened 2 years ago

panchalkalpesh commented 2 years ago

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):

fhfrosacruz commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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

vilija19 commented 2 years ago

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

vilija19 commented 2 years ago

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 commented 5 months ago

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