visual-studio-codexdebuglampturnkeylinux.org

Debugging PHP on remote Turnkey Linux LAMP server in VS Code


I've been trying to get debugging working in VS Code for hours and have read every tutorial and question and answer, but no luck.

I have a server using Turnkey Linux LAMP with PHP 7.4 and Xdebug 3.

On another Windows computer I have VS Code running and am trying to debug.

I have tried various settings, but currently VS Code launch.json looks like this?

{
    "name": "Listen for Xdebug",
    "type": "php",
    "request": "launch",
    "port": 9003,
    "hostname": "192.168.20.110",
    "pathMappings": {
        "/var/websites/test": "${workspaceFolder}/",
    }
}

On the server, php.ini looks like this, although I have tried various:

[xdebug]
xdebug.mode=develop,debug
xdebug.discover_client_host=1
xdebug.client_port = 9003
xdebug.start_with_request=yes

Whenever I press the run button in VS Code I get

listen EADDRNOTAVAIL: address not available 192.168.20.110:9003

I have tried creating a firewall exception on the server for port 9003.

I have installed Xdebug extension in Chrome.

What am I missing?


Solution

  • First definitely remove the hostname setting from launch.json. This is the IP the IDE tries to bind to and as this is a remote IP of the server it cannot. Also do not use localhost as then the server will not be able to communicate with the workstation.

    Path mappings could be wrong as you did not provide information how the workstation is accessing the files on the server (SMB, SSH, SFTP).

    I suggest adding xdebug_info(); in one of the php files that you open with a browser and see what output it generates.