简体   繁体   中英

Laravel sail - How to debug in VSCode with windows docker desktop

I am quite new to Linux and Docker. It is good that Sail manages everything for me. But I would like to allow the debugging in VSCode. I have added in my windows laravel folder /docker/8.0/php.ini

[XDebug]
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_host = host.docker.internal
xdebug.remote_port = 9001

I have added this in my windows laravel folder /docker/8.0/Dockerfile

ARG INSTALL_XDEBUG=true
RUN if [ ${INSTALL_XDEBUG} = true ]; then \
    # Install the xdebug extension
    pecl install xdebug && \
    docker-php-ext-enable xdebug \
    ;fi

# Copy xdebug configration for remote debugging
COPY .docker/xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini
EXPOSE 9001

And I have modified my VScode launch.json with:

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

When I launch 'sail up' in Ubuntu and start the debugger in VSCode it does not work: the debug bar is not active (only pause, stop, and restart buttons are active, all other are not active)

How should I do? Thanks !

In php.ini add:

xdebug.idekey="VSCODE"

In Dockerfile add:

RUN echo "zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20190902/xdebug.so" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

(in my case is php 7.4 and xdebug 2.9) after install xdebug line.

Change

COPY .docker/xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini

to

COPY .docker/xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

Finally in VSCode config change like this: vscode config

P/S: dont forget add something like this if you using docker-compose because docker linux dont auto mapping host.docker.internal to your host ip.

extra_hosts:
      - "host.docker.internal:host-gateway"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM