skip to Main Content

I’ve spent hours and hours trying everything I or Google could think of, but Xdebug doesn’t stop on any breakpoints.

Also had a look at this question and answers but still… no luck:
Unable to get Xdebug 3 working with Docker

In the past it worked, but somehow it stopped working. Maybe an update of docker or whatever package / app caused it to stop.

On macOS:

  • deleted docker, reinstalled it with the newest version (4.8.1 78998).

  • removed my current Laravel Sail project and created a new Laravel Sail project through curl -s "https://laravel.build/example-app" | bash

  • added SAIL_XDEBUG_MODE=develop,debug to the newly created .env file

  • sail up -d to start everything

  • removed and reinstalled Visual Studio Code newest version: 1.6.7.1

  • created a PHP launch.json file with the following contents:

    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Listen for Sail Xdebug",
                "type": "php",
                "request": "launch",
                "port": 9003,
                "pathMappings": {
                    "/var/www/html": "${workspaceFolder}"
                },
                "hostname": "localhost",
                "ignore": [
                    "**/vendor/**/*.php"
                ],
                "xdebugSettings": {
                    "max_data": 65536,
                    "show_hidden": 1,
                    "max_children": 100,
                    "max_depth": 3
                }
            }
        ]
    }
    
  • got the following message inside of VSCode:

    ‘Cannot validate since a PHP installation could not be found. Use the setting ‘php.validate.executablePath’ to configure the PHP executable.’

    I don’t know if this is the problem or what I should do since I’m using docker.

  • placed a breakpoint in the route file or whatever else file that you create

  • inside of the ‘Run and Debug’ tab of VSCode I told it to use config ‘Listen for Sail Xdebug’ and run the debugger (F5) -> I checked all checkboxes for breakpoints (notices, warnings, errors …)

Nothing happens. VSCode does not stop on any breakpoint.

I still have no idea where to look as to get it working again.

I would be very happy if someone, maybe Derick himself, could help me out here. The last hairs that I still have are about to pulled out :O

Please let me know if you need any more information, settings or code from me!

  • PHP version 8.1.5
  • Xdebug version 3.1.2

xdebug_info() says:

Version 3.1.2
Support Xdebug on Patreon, GitHub, or as a business
Enabled Features
(through 'XDEBUG_MODE' env variable)
Feature Enabled/Disabled    Docs
Development Helpers ✔ enabled   🖹
Coverage    ✘ disabled  🖹
GC Stats    ✘ disabled  🖹
Profiler    ✘ disabled  🖹
Step Debugger   ✔ enabled   🖹
Tracing ✘ disabled  🖹
Optional Features
Compressed File Support no
Clock Source    clock_gettime
Diagnostic Log
No messages
Step Debugging  Docs
Debugger    Not Active  🖹
PHP
Build Configuration
Version (Run Time)  8.1.5
Version (Compile Time)  8.1.1
Debug Build no
Thread Safety   disabled
Settings
Configuration File (php.ini) Path   /etc/php/8.1/cli
Loaded Configuration File   /etc/php/8.1/cli/php.ini
Scan this dir for additional .ini files /etc/php/8.1/cli/conf.d
Additional .ini files parsed    /etc/php/8.1/cli/conf.d/10-mysqlnd.ini, /etc/php/8.1/cli/conf.d/10-opcache.ini, /etc/php/8.1/cli/conf.d/10-pdo.ini, /etc/php/8.1/cli/conf.d/15-xml.ini, /etc/php/8.1/cli/conf.d/20-bcmath.ini, /etc/php/8.1/cli/conf.d/20-calendar.ini, /etc/php/8.1/cli/conf.d/20-ctype.ini, /etc/php/8.1/cli/conf.d/20-curl.ini, /etc/php/8.1/cli/conf.d/20-dom.ini, /etc/php/8.1/cli/conf.d/20-exif.ini, /etc/php/8.1/cli/conf.d/20-ffi.ini, /etc/php/8.1/cli/conf.d/20-fileinfo.ini, /etc/php/8.1/cli/conf.d/20-ftp.ini, /etc/php/8.1/cli/conf.d/20-gd.ini, /etc/php/8.1/cli/conf.d/20-gettext.ini, /etc/php/8.1/cli/conf.d/20-iconv.ini, /etc/php/8.1/cli/conf.d/20-igbinary.ini, /etc/php/8.1/cli/conf.d/20-imap.ini, /etc/php/8.1/cli/conf.d/20-intl.ini, /etc/php/8.1/cli/conf.d/20-ldap.ini, /etc/php/8.1/cli/conf.d/20-mbstring.ini, /etc/php/8.1/cli/conf.d/20-msgpack.ini, /etc/php/8.1/cli/conf.d/20-mysqli.ini, /etc/php/8.1/cli/conf.d/20-pcov.ini, /etc/php/8.1/cli/conf.d/20-pdo_mysql.ini, /etc/php/8.1/cli/conf.d/20-pdo_pgsql.ini, /etc/php/8.1/cli/conf.d/20-pdo_sqlite.ini, /etc/php/8.1/cli/conf.d/20-pgsql.ini, /etc/php/8.1/cli/conf.d/20-phar.ini, /etc/php/8.1/cli/conf.d/20-posix.ini, /etc/php/8.1/cli/conf.d/20-readline.ini, /etc/php/8.1/cli/conf.d/20-redis.ini, /etc/php/8.1/cli/conf.d/20-shmop.ini, /etc/php/8.1/cli/conf.d/20-simplexml.ini, /etc/php/8.1/cli/conf.d/20-soap.ini, /etc/php/8.1/cli/conf.d/20-sockets.ini, /etc/php/8.1/cli/conf.d/20-sqlite3.ini, /etc/php/8.1/cli/conf.d/20-sysvmsg.ini, /etc/php/8.1/cli/conf.d/20-sysvsem.ini, /etc/php/8.1/cli/conf.d/20-sysvshm.ini, /etc/php/8.1/cli/conf.d/20-tokenizer.ini, /etc/php/8.1/cli/conf.d/20-xdebug.ini, /etc/php/8.1/cli/conf.d/20-xmlreader.ini, /etc/php/8.1/cli/conf.d/20-xmlwriter.ini, /etc/php/8.1/cli/conf.d/20-xsl.ini, /etc/php/8.1/cli/conf.d/20-zip.ini, /etc/php/8.1/cli/conf.d/25-memcached.ini, /etc/php/8.1/cli/conf.d/25-swoole.ini, /etc/php/8.1/cli/conf.d/99-sail.ini
Directive   Local Value Master Value    Docs
xdebug.mode (through XDEBUG_MODE)   develop,debug   develop 🖹
xdebug.start_with_request   default default 🖹
xdebug.start_upon_error default default 🖹
xdebug.output_dir   /tmp    /tmp    🖹
xdebug.use_compression  0   0   🖹
xdebug.trigger_value    no value    no value    🖹
xdebug.file_link_format no value    no value    🖹
xdebug.filename_format  no value    no value    🖹
xdebug.log  no value    no value    🖹
xdebug.log_level    7   7   🖹
xdebug.var_display_max_children 128 128 🖹
xdebug.var_display_max_data 512 512 🖹
xdebug.var_display_max_depth    3   3   🖹
xdebug.max_nesting_level    256 256 🖹
xdebug.cli_color    0   0   🖹
xdebug.force_display_errors Off Off 🖹
xdebug.force_error_reporting    0   0   🖹
xdebug.halt_level   0   0   🖹
xdebug.max_stack_frames -1  -1  🖹
xdebug.show_error_trace Off Off 🖹
xdebug.show_exception_trace Off Off 🖹
xdebug.show_local_vars  Off Off 🖹
xdebug.dump.COOKIE  no value    no value    🖹
xdebug.dump.ENV no value    no value    🖹
xdebug.dump.FILES   no value    no value    🖹
xdebug.dump.GET no value    no value    🖹
xdebug.dump.POST    no value    no value    🖹
xdebug.dump.REQUEST no value    no value    🖹
xdebug.dump.SERVER  no value    no value    🖹
xdebug.dump.SESSION no value    no value    🖹
xdebug.dump_globals On  On  🖹
xdebug.dump_once    On  On  🖹
xdebug.dump_undefined   Off Off 🖹
xdebug.profiler_output_name cachegrind.out.%p   cachegrind.out.%p   🖹
xdebug.profiler_append  Off Off 🖹
xdebug.cloud_id no value    no value    🖹
xdebug.client_host  host.docker.internal    localhost   🖹
xdebug.client_port  9003    9003    🖹
xdebug.discover_client_host Off Off 🖹
xdebug.client_discovery_header  no value    no value    🖹
xdebug.idekey   no value    no value    🖹
xdebug.connect_timeout_ms   200 200 🖹
xdebug.scream   Off Off 🖹
xdebug.gc_stats_output_name gcstats.%p  gcstats.%p  🖹
xdebug.trace_output_name    trace.%c    trace.%c    🖹
xdebug.trace_format 0   0   🖹
xdebug.trace_options    0   0   🖹
xdebug.collect_assignments  Off Off 🖹
xdebug.collect_return   Off Off

4

Answers


  1. Laravel Sail should work straight out of the box. I have made a 5 minute video titled "Laravel Sail with PhpStorm", but it should work equally well with VS Code with the configuration that you outlined.

    To find out why something does not work, you can either try debugging a file that has xdebug_info() in it. It will tell you whether (and if) Xdebug tried making a connection, to where, and what the result was. There are also links to the documentation directly next to each error message (if present).

    Your log says:

    Diagnostic Log
    No messages

    Which means that you did not instruct Xdebug to start a debugging session through a trigger. You need to tell Xdebug to start one. The Laravel Sail documentation points to the Xdebug documentation on how to do this. It recommends you use one of the mentioned browser extensions to "click" when you want to debug or not.

    If you need more debugging information, make a log file and crank it up to 10: xdebug.log=/tmp/xdebug.log and xdebug.log_level=10.

    Login or Signup to reply.
  2. I had the same problem as you trying to get Laravel Sail, XDebug and VS Code to cooperate for debugging on a newly created Laravel project on Linux although it should work as it is with just adding SAIL_XDEBUG_MODE=develop,debug in the .env file. It didn’t work until I also added SAIL_XDEBUG_CONFIG="client_host=localhost" in the .env file. I didn’t have to change anything in the default launch.json that was created automatically from VS Code. Just remember to restart VS Code to lauch the docker containers with the new configuration.

    Login or Signup to reply.

  3. I had the same problem. I have fixed this issue by updating php.ini file of docker.
    To update php.ini of you sail docker you have to follow this steps

    1. run :

    ./vendor/bin/sail artisan sail:publish

    This will create docker folder in root of your project.

    1. update php.ini of docker/8.1 folder. Add this code in php.ini

    [XDebug]
        zend_extension = xdebug.so
        xdebug.mode = debug
        xdebug.start_with_request = yes
        xdebug.discover_client_host = true
        xdebug.idekey = VSC
        xdebug.client_host = host.docker.internal
        xdebug.client_port = 9003
    1. Refresh sail docker container with:

      ./vendor/bin/sail build –no-cache

    2. add following line to .env file

    SAIL_XDEBUG_MODE=develop,debug

    1. run docker and enjoy your xdebug with vscode.
    Login or Signup to reply.
  4. When trying to set this up I add "log": true, to my launch.json file to see whether there are errors or useful information.

    Another useful tool is the sail root-shell command, which acts similar as docker exec -it /bin/bash. This allows you to execute commands in the container, such as printenv to check if your environment variables are set correctly.

    The following made it work for me:

    "version": "0.2.0",
        "configurations": [
            {
                "name": "Listen for Xdebug",
                "type": "php",
                "request": "launch",
                "port": 9003,
                "hostname": "0.0.0.0",
                "log": true, 
                "pathMappings": {
                    "/var/www/html": "${workspaceFolder}",
    
                }
            },
            {
                "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",
                "program": "",
                "cwd": "${workspaceRoot}",
                "port": 9003,
                "serverReadyAction": {
                    "pattern": "Development Server \(http://localhost:([0-9]+)\) started",
                    "uriFormat": "http://localhost:%s",
                    "action": "openExternally"
                }
            }
        ]
    

    Add these two to your .env file. These are the only two variables which are recognized by the artisan serve command (which powers sail) as of Laravel version 8.53.0 so there is no point in adding additional variables.

    XDEBUG_MODE=develop,debug,coverage
    XDEBUG_CONFIG="client_host=host.docker.internal"
    

    Edit:
    In the newer versions of laravel you have to use different environment variables:

    SAIL_XDEBUG_MODE=debug,develop,coverage
    SAIL_XDEBUG_CONFIG="client_host=host.docker.internal"
    

    I added the php XDebugHelper extension to chrome aswell.

    You can check if your Xdebug instance is running in your sail container via sail php -v, your output should look something like this:
    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search