简体   繁体   中英

VS Code launch.json Xdebug configuration for step debugging PHP pages in a Windows Server 8

I have a PHP project on a Windows Server 8 and I want to be able to work with those pages from VS Code and make step debugging but I don't know how to configure the launch.json correctly.

I installed Xdebug 3 on the Windows Server and it's active. The configuration that I put in php.ini is this one:

[XDebug]
zend_extension = xdebug
xdebug.mode= debug, develop
xdebug.start_with_request=yes
xdebug.idekey=VSCODE
xdebug.remote_port = 9003
xdebug.discover_client_host = true
xdebug.client_discovery_header = HTTP_XDEBUG_IP
xdebug.show_exception_trace = 1
xdebug.connect_timeout_ms = 5000

Take into consideration that:

  • "11.128.7.124:3555" is the IP Windows server and port used by Apache on that server.

  • I open the server PHP Folder from VS Code throw a network unit.

  • In the Windows 8 server is installed XAMPP with PHP 7.2

I've read a lot of information but I've being able to configure the environment to do the step debugging that I can do when I open that project locally.

I also installed Xdebug extensions in Microsoft Edge and Google Chrome browsers (active).

The launch.json file on VS Code has this configuration (No the same IP address and port):

{
    // 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": "Launch Built-in web server",
            "type": "php",
            "request": "launch",
            "runtimeArgs": [
                "-dxdebug.mode=debug",
                "-dxdebug.start_with_request=yes",
                "-S",
                "11.128.7.124:3555"
            ],
            "program": "",
            "cwd": "${fileDirname}",
            "port": 9003,
            "pathMappings": {
                "d:/xampp/htdocs/myproject": "${workspaceFolder}/htdocs",
                "/myproject": "${workspaceFolder}"
              },
            "serverReadyAction": {
                "pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
                "uriFormat": "http://localhost:%s",
                "action": "openExternally"
            }
        },
        
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9003,
            "runtimeArgs": [
                "-dxdebug.start_with_request=yes"
            ],
            "env": {
                "XDEBUG_MODE": "debug,develop",
                "XDEBUG_CONFIG": "client_port=${port}"
            }
        },

        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9003
        }

    ]
}

I think your problem is:

xdebug.remote_port = 9003

The setting has been renamed in Xdebug 3 to xdebug.client_port ( https://xdebug.org/docs/upgrade_guide#changed-xdebug.remote_port ).

Alternatively, you can modify launch.json , so that it also sets the port to the port setting of the same launch configuration in the "Launch Built-in web server" case.

        "runtimeArgs": [
            "-dxdebug.mode=debug",
            "-dxdebug.start_with_request=yes",
            "-dxdebug.client_port=${port}",
            "-S",
            "11.128.7.124:3555"
        ],

Tips

In order to debug issues with Xdebug debugging, you can use the new Xdebug 3 function xdebug_info() in a script that you're trying to debug, and it will show you diagnostics on what's going on, what Xdebug has tried, and whether it could connect to the debugger, among other things.

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