DEV Community

Viktor Le
Viktor Le

Posted on • Updated on

How to enable Xdebug v-3.3.2 in Visual Studio Code

Today, I upgrade my project to new laravel version, v-10, and want to install xdebug for development a bit easier. I am around to search on the internet how to install xdebug in Laravel.

Firstly, I install xdebug.so in my local machine. Then, I check if it is installed already by the following command

$ php -m | grep xdebug
xdebug
Enter fullscreen mode Exit fullscreen mode

Yes, it shows xdebug. In case non line shown, then Xdebug needs installed by the following prompt on MacOS, or follow the offical document - https://xdebug.org/docs/install

pecl install xdebug
Enter fullscreen mode Exit fullscreen mode

Secondly, I search on the internet that all the posts have been related to xdebug instruct me to find php.ini and add new lines in EOF.

[xdebug]
xdebug.remote_enable=1
xdebug.remote_autostart=1
Enter fullscreen mode Exit fullscreen mode

Thirdly, I create a launch.json file in VS code by clicking bug icon, then I select PHP (Xdebug)

Image description

Bump, snippet json file is generated automatically

{
    // 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
        }
    ]
}
Enter fullscreen mode Exit fullscreen mode

Finally, I start Xdebug by clicking on Listen for Xdebug

Image description

In the result, no breakpoint is hit. Oops!

I try to search how and find that, the section in php.ini is out-up-dated. new Xdebug version uses another one to enable the mode, instead that, use it

[xdebug]
xdebug.mode=debug
xdebug.start_with_request=1
Enter fullscreen mode Exit fullscreen mode

I try to turn on Xdebug mode again. Wow, one of breakpoints is hit.

Hope my post can help you navigate the situation when installing Xdebug v-3.3.2 in Visual Studio Code

Top comments (0)