skip to Main Content

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?

2

Answers


  1. It seems like the issue might be related to the address specified in your launch.json file. The error "EADDRNOTAVAIL: address not available" suggests that the specified IP address is not reachable or not assigned to your server.

    Here are some suggestions to troubleshoot and resolve the issue:

    1. Check Server IP Address:

      • Confirm that the IP address 192.168.20.110 is the correct IP address of your Turnkey Linux LAMP server. You can check the IP address using the ifconfig or ip a command on the server.
    2. Use "localhost" or "127.0.0.1" as the Hostname:

      • Instead of using the server’s IP address, try using "localhost" or "127.0.0.1" as the "hostname" in your launch.json file. This can sometimes resolve connection issues.
      "hostname": "localhost",
      
    3. Check Firewall Settings:

      • Double-check your firewall settings on the server. Make sure that port 9003 is open and accessible. You may need to create an exception for this port.
    4. Verify Xdebug Settings:

      • Ensure that Xdebug is configured correctly in your PHP settings. Your configuration looks reasonable, but double-check that Xdebug is properly installed and enabled.
    5. Verify PHP Process:

      • Make sure that the PHP process on your server is using Xdebug. You can use the phpinfo() function to check if Xdebug is loaded.
    6. Check for Multiple Xdebug Configurations:

      • Make sure that there are no conflicting Xdebug configurations in other files. Sometimes, additional configurations in .ini files can cause conflicts.
    7. Restart Services:

      • After making changes to your PHP configuration, restart your web server (e.g., Apache) to apply the changes.
    8. Review VS Code Output:

      • Look at the output window in VS Code for any additional error messages or information about the debugging attempt. It might provide more insights into what’s going wrong.
    9. Try Different Ports:

      • If the issue persists, try using a different port in your launch.json file. Make sure that the port you choose is not blocked by the firewall.
      "port": 9000,
      
    10. Check for Typos:

      • Double-check for any typos or syntax errors in your launch.json file.
    11. Reinstall Xdebug Extension in Chrome:

      • Remove the Xdebug extension from Chrome and reinstall it. Ensure that the extension is properly configured.

    After making any changes, restart your server and try again. If the problem persists, review each step to ensure accuracy and consistency in your configurations.

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search