mightycode Newton
mightycode Newton

Reputation: 3949

How to debug a Yii application in Visual Studio Code?

I've installed Xdebug. And I'm trying to debug a Yii application (version: 1.1.24). But if I put a breakpoint on the method nothing happens.

But if I make a very simple example script file in another folder (just app with single file). Just like this:

<?php

echo 'Hello';
?>

And I choose: debug current script in console. Then it will hit the code line.

But in the Yii application it doesn't hit any breakpoint.

So the launch.json looks like this for the Yii application:

{
    // 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
        },
        {
            "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"
            }
        }
    ]
}

So my question is. How to debug a Yii application with Xdebug in VSCode?

Upvotes: 1

Views: 1872

Answers (1)

A. Adaro
A. Adaro

Reputation: 26

You must change the value of 'cwd' from '${workspaceRoot}' to '/your_app_path/web/' in the config section "Launch Built-in web server", that's work fine for me :)

Upvotes: 1

Related Questions