0

After successfully installing Valet, Xdebug and configuring VSCODE for the Listener for Xdebug 3. and checking that everything worked, at the first power off and on of the mac (OS: Big Sur), Xdebug started to stop working.

I tried to restart valet using the command

valet restart

but nothing Xdebug still doesn't work.

Version of PHP and Xdebug:

/usr/local/bin/php -v
PHP 7.4.21 (cli) (built: Jul 12 2021 11:57:26) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.21, Copyright (c), by Zend Technologies
    with Xdebug v3.0.4, Copyright (c) 2002-2021, by Derick Rethans

PHP ini:

php --ini
Configuration File (php.ini) Path: /usr/local/etc/php/7.4
Loaded Configuration File:         /usr/local/etc/php/7.4/php.ini
Scan for additional .ini files in: /usr/local/etc/php/7.4/conf.d
Additional .ini files parsed:      /usr/local/etc/php/7.4/conf.d/error_log.ini,
/usr/local/etc/php/7.4/conf.d/ext-opcache.ini,
/usr/local/etc/php/7.4/conf.d/ext-xdebug.ini,
/usr/local/etc/php/7.4/conf.d/php-memory-limits.ini

Config Xdebug ini:

# Configuration for Xdebug 3
[Xdebug]
zend_extension="xdebug.so"
xdebug.mode=debug
xdebug.start_with_request=default
xdebug.idekey=VSCODE
xdebug.client_port=9003
xdebug.client_host=127.0.0.1
xdebug.start_upon_error=yes
xdebug.discover_client_host=1

VSCODE settings.json

{
    "php.validate.executablePath": "/usr/bin/php",
    "intelephense.environment.phpVersion": "7.4",
    "intelephense.completion.fullyQualifyGlobalConstantsAndFunctions": true,
    "grunt.autoDetect": "on",
    "artisan.php.location": "/usr/local/bin/php"
}

Configuration myproject/.vscode/lunch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9003,
        }
    ]
}

This is the output of xdebug_info()

How can I fix it?

Pave
  • 1
  • 2

2 Answers2

0

After 3 hours looking for a solution I have installed two extensions one for Google Chrome and one for Safari and magically Xdebug is back to work.

I don't understand why I have to install extensions on browsers (Safari Extension and Chrome Extension) to make Xdebug work.

Before Xdebug worked without having installed extensions on the various browsers. How is this possible?

Could you explain this to me?

How to avoid using extensions on browsers to make Xdebug work?

Pave
  • 1
  • 2
  • 1
    `start_with_request=default` when `mode=debug` is the same as `trigger`. The Xdebug browser extension is actually adding that trigger (Xdebug cookie) -- when it's present in the request it means "look, this request needs to be debugged". – LazyOne Jul 22 '21 at 20:32
  • Thx a lot @LazyOne for the response, but it is still not clear to me how it is possible that it worked before without having installed the plugins. – Pave Jul 24 '21 at 19:30
  • You may have had something else in place: 1) Xdebug cookie or GET/POST parameter that acts as "debug me" flag; 2) Xdebug config may have been a bit different ("debug every request, do not look for the flag"); 3) Some Xdebug param in ENV (on Valet/server end; that affects the "debug me" flag) that was there before the restart. I have only to guess since I have no idea what exactly you were doing ... and it's always possible you may have missed or forgot some step (we all make mistakes without realising them in short term). – LazyOne Jul 24 '21 at 20:00
  • @LazyOne the answers to your questions: 1. No Xdebug cookie or GET / POST parameter that activate "debug me" flag. 2. How to activate "debug every request, do not look for the flag"? 3. I don't have params Xdebug in ENV, I have only the default params of Laravel. – Pave Jul 25 '21 at 15:27
0

I faced the same problem, but I solve it by another way. The solution is easier.

I use Linux Ubuntu 20.04 + VSCode + PHP 8.1 + Laravel 9 + Laravel Nova + Valet + Xdebug 3.

It helped me: https://coreysalzano.com/web-development/troubleshooting-vs-code-xdebug-and-laravel-valet-on-macos/

You need use a simple config and set configs to PHP for Xdebug.

In my example I use 9002 port, 9003 is the default port. You may use any port.

  1. Set VSCode config ./.vscode/launch.json.
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "port": 9002
        }
    ]
}
  1. Set config to /etc/php/8.1/fpm/conf.d/20-xdebug.ini or /etc/php/8.1/mods-available/xdebug.ini or your PHP config. /etc/php/8.1/mods-available/xdebug.ini is an original file for me and other files are symlinks for it.

You may use one of these configs. There are two main parameters: xdebug.start_with_request=yes and xdebug.mode=debug. You may use the default port or change it. I use 9002 port in the example.

Example. Custom port and mode

zend_extension=xdebug.so
xdebug.client_port=9002
xdebug.start_with_request=yes
xdebug.mode=debug,develop

Example. The default port is 9003 port

zend_extension=xdebug.so
xdebug.start_with_request=yes
xdebug.mode=debug

Save your changes.

  1. Restart Valet.
valet restart

Now you may get two different outputs, but both mean that it works.

Option 1. You don't start debugging

If you don't start debugging in VSCode you will get the following message. It is not error. Just start debugging, for example F5, and you can work for VSCode and XDebug: add breakpoints and start your script for it.

enter image description here

Option 2. You are debugging your code

It means you are debugging your script.

enter image description here

Each time when you change your Xdebug config you need to restart Valet through valet restart.