Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusing XDBUG documentation #381

Closed
sonicviz opened this issue Sep 18, 2018 · 14 comments · Fixed by #517
Closed

Confusing XDBUG documentation #381

sonicviz opened this issue Sep 18, 2018 · 14 comments · Fixed by #517

Comments

@sonicviz
Copy link

sonicviz commented Sep 18, 2018

ISSUE TYPE

  • Documentation

SUMMARY

https://devilbox.readthedocs.io/en/latest/intermediate/configure-php-xdebug/editor-vscode.html#configure-php-xdebug-editor-vscode

It says PHPSTORM, not what the IDE key for Visual Studio code should be. Same issue with sublime.

eg: Ensure that xdebug.idekey is set to PHPSTORM in your PHP Xdebug configuration.

Goal

What is the IDE key for VSCode -> mac-cain13/xdebug-helper-for-chrome#89

VSCODE

Also found the XDBUG documentation a little confusing with multilayered clickthroughs that make you quickly lose track of what you are doing. It would be simpler and more direct to have it on a single page with references at the bottom in my view.

@masiorama
Copy link

I must admit I'm having similar issues, and I'm not able to use xdebug on vscode.

@cytopia
Copy link
Owner

cytopia commented Sep 24, 2018

I have to admin the Xdebug documentation still has lots of potential. I made a major rewrite of this a few weeks ago, but its not yet in an easy and understandable shape.

I will dig into how to get this working with VSCode.

@cytopia cytopia self-assigned this Sep 24, 2018
@sonicviz
Copy link
Author

sonicviz commented Sep 24, 2018

I will dig into how to get this working with VSCode.

I got it working, but just found it a little difficult to piece it together.
I used my original instructions re the IP address for the Docker ethernet adaptor. See the original issue I posted.

@sonicviz
Copy link
Author

Here's how I got it working in VSCODE, very similar to my original solution here: #209
I don't know why you wrote such convoluted instructions tbh, Keep It Simple as devs are usually time poor would be my advice. Apart from that, a great tool so thanks! Goes well with Dockstation too, so you should also hook up with them.

XDebug.ini
; Xdebug
; Use these settings to enable Xdebug for PHP
; Make sure to read up on Xdebug some settings might significantly slow down requests.
; The following is just an example configuration and should be adjusted
#xdebug.default_enable = On
#xdebug.profiler_enable = On
xdebug.remote_enable = On
xdebug.remote_autostart = On
xdebug.remote_handler = dbgp
xdebug.remote_port = 9000
xdebug.idekey = VSCODE
xdebug.remote_log = /var/log/php/xdebug.log
xdebug.remote_connect_back=0
xdebug.remote_host=[IP Address of vEthernet (Default Switch) NOT the vEthernet (DockerNAT) IP - Note my solution here: https://github.com//issues/209 for getting the correct IP, it's different from yours]

PHP.ini
; ############################################################
; # Devilbox php.ini: Current default settings
; ############################################################
;
; Information
; -----------
; * Do not edit this file (it belongs to git)
; * This file shows example settings that are currently effective
; * If this file is enabled, nothing will change as it reflects the current default settings
;
; How to enable?
; --------------
; * Copy this file to another file with ".ini" extension
; * Only files with ".ini" extensions will be applied by PHP

;
; PHP.ini configuration
;
[PHP]
; Memory
; Note: "memory_limit" should be larger than "post_max_size"
memory_limit            = 512M

; Timeouts
max_execution_time = 120
max_input_time = 120

; Uploads
; Note: "post_max_size" should be greater than "upload_max_filesize"
post_max_size = 72M
upload_max_filesize = 64M
max_file_uploads = 20

; Vars
variables_order = EGPCS
max_input_vars = 8000
max_input_nesting_level = 64

; Error reporting
; Note: error_log is dynamic and handled during start to set appropriate setting
error_reporting = E_ALL | E_NOTICE | E_STRICT | E_DEPRECATED
xmlrpc_errors = Off
report_memleaks = On
display_errors = On
display_startup_errors = On
track_errors = On
log_errors = On
html_errors = On

VSCode Launch.json for XDebug
{
// 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": 9000,
"pathMappings": {
"/shared/httpd/websitename/htdocs": "${workspaceRoot}/data/www/websitename/htdocs"
}
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}

@masiorama
Copy link

I changed the pathMappings suggested with
"pathMappings": { "/shared/httpd/xdebug/htdocs": "${workspaceFolder}/htdocs" }

since it seems that ${workspaceRoot} is deprecated.

@cytopia cytopia added the xdebug label Dec 30, 2018
@keithy
Copy link
Contributor

keithy commented Feb 5, 2019

Struggled to get xdebug working, on Mac OS X (mojave), and Docker Desktop.
My solution was to add a loopback alias to the OS:

ifconfig lo0 alias 10.254.254.254

And give it a name in /etc/hosts

10.254.254.254 realhost
172.16.238.1 dockershost

Supported by invocation on boot:
/Library/LaunchDaemons/com.ralphschindler.docker_10254_alias.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.ralphschindler.docker_10254_alias</string>
    <key>ProgramArguments</key>
    <array>
        <string>ifconfig</string>
        <string>lo0</string>
        <string>alias</string>
        <string>10.254.254.254</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

xdebug can now connect to realhost

Can also add it to

    extra_hosts:
      docker.for.lin.host.internal: 172.16.238.1
      docker.for.lin.localhost: 172.16.238.1
      docker.realhost: 10.254.254.254

@cytopia
Copy link
Owner

cytopia commented Mar 2, 2019

Thanks for all the input. I am in the process of consolidating and simplifying the current Xdebug documentation and keep you posted as soon as the first PR is created.

cytopia added a commit that referenced this issue Mar 2, 2019
Fixes #381 Rewrite and simplify Xdebug documentation
@cytopia
Copy link
Owner

cytopia commented Mar 2, 2019

Xdebug documentation

@sonicviz @masiorama @keithy @drupalshift @ToolOwner

I have completely rewritten the Xdebug documentation and made sure it is as simple and straight forward as possible.

If anything is still unclear or not working, please comment again and I will re-open

@sonicviz
Copy link
Author

sonicviz commented Mar 4, 2019

Awesome, ty!

@georgesreti
Copy link

georgesreti commented May 22, 2021

Hello folks, I finally managed to make Xdebug work on Windows 10 Home Edition, PHP 7.4 and VS Code.

TLDR;

devilbox\cfg\php-ini-7.4\xdebug.ini

[PHP]

; Defaults
xdebug.mode=debug
xdebug.client_port=9003
xdebug.remote_handler=dbgp

; The Windows way
xdebug.client_host=docker.for.lin.host.internal

; idekey value is specific to Visual Studio Code
xdebug.idekey=VSCODE

; Optional: Set to true to always auto-start xdebug
xdebug.start_with_request = yes

devilbox\docker-compose.override.yml

# IMPORTANT: The version must match the version of docker-compose.yml
---
version: '2.3'

services:

  php:

    # Expose port 9003 for XDebug
    ports:
      # [local-machine:]local-port:docker-port
      - "9003:9003"

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Xdebug for Project mytest",
            "type": "php",
            "request": "launch",
            "port": 9003,
            "pathMappings": {
                "/shared/httpd/mytest/htdocs": "${workspaceRoot}/htdocs"
            }
        }, {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9003
        }
    ]
}

I was stuck with the following error message : VS Code complains that "Error: listen EADDRINUSE: address already in use :::9000"

After some digging, it seems that PHP-FPM uses port 9000 and now Xdebug 3 uses port 9003 as a default.

Secondly, I struggled finding the host IP, with reference to 3.2.3.4.1.2. Gather Host IP address. I do not have the "virtual switch manager" nor do I have a "default switch" connection. From the php container, I can ping the host with the ip on my local LAN, or the "Ethernet adapter vEthernet (WSL)". In a different thread, I see the host is not conveniently assigns a DNS name "host.docker.internal", but it is not resolved by the PHP container. In docker-compose.yml, I can see docker.for.lin.host.internal is statically assigned to 172.16.238.1 and pings go through, so that is what I used.

Finally, the documentation refers to Xdebug 2.0 configuration that needs to be tranlated to XDebug 3.0. It may still be valid for older version of PHP though. This is the documentation I used.

@ARehmanMahi
Copy link

Here is a walk through for PHPStorm and xdebug on Linux Ubuntu, Hope it helps.
#575 (comment)

@masiorama
Copy link

@georgesreti I followed your exact instructions but I am having the
"Error: listen EADDRINUSE: address already in use :::9003"
on port 9003, and then I have no clue how to go on.
Does the configuration still work for you?
Thanks!

@georgesreti
Copy link

georgesreti commented Oct 28, 2021 via email

@marcimat
Copy link

I think that documentation isn’t up to date with version 3 of XDebug ?

This doc tells us for example to use xdebug.remote_host=10.254.254.254 config.
But it has been renamed in version 3 in xdebug.client_host=10.254.254.254.

https://xdebug.org/docs/upgrade_guide

To work properly I think for me in vscode / macos, I had to use

xdebug.mode  = debug
xdebug.start_with_request = yes

; The MacOS way
#xdebug.discover_client_host=0
xdebug.client_host=10.254.254.254
xdebug.client_port=9003

; idekey value is specific to Visual Studio Code
xdebug.idekey=vsc

Note that

  • I use port 9003 (new default for xdebug 3)
  • I use idekey vsc which is my default in vscode (and not VSCODE)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants