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

How to use PHP Xdebug without sidecar? #15740

Closed
davidwindell opened this issue Jan 17, 2020 · 8 comments
Closed

How to use PHP Xdebug without sidecar? #15740

davidwindell opened this issue Jan 17, 2020 · 8 comments
Labels
kind/question Questions that haven't been identified as being feature requests or bugs.

Comments

@davidwindell
Copy link
Contributor

The development image we use for our workspace, already has PHP 7 and Xdebug installed on it.

How do we get this working with Che7/Theia so that the xdebug in the development container is able to communicate with the debugger in theia?

I can see there is a plugin for the felixfbecker/vscode-php-debug but this seems to start a new sidecar container without all the php modules we need (whereas these are already installed on the dev container).

I guess we need to be able to point our xdebug to the right internal host/port somehow?

@davidwindell davidwindell added the kind/question Questions that haven't been identified as being feature requests or bugs. label Jan 17, 2020
@che-bot che-bot added the status/need-triage An issue that needs to be prioritized by the curator responsible for the triage. See https://github. label Jan 17, 2020
@davidwindell
Copy link
Contributor Author

I'd also like to loop in @gorkem and @amisevsk having read the discussion here https://www.eclipse.org/lists/che-dev/msg03362.html, it looks like exactly this was being discussed

@tolusha tolusha added area/debugger kind/question Questions that haven't been identified as being feature requests or bugs. and removed kind/question Questions that haven't been identified as being feature requests or bugs. status/need-triage An issue that needs to be prioritized by the curator responsible for the triage. See https://github. labels Jan 17, 2020
@tolusha
Copy link
Contributor

tolusha commented Jan 17, 2020

/cc @tsmaeder @vrubezhny

@amisevsk
Copy link
Contributor

amisevsk commented Jan 17, 2020

The way debugging currently works in Che, for a sidecar plugin like PHP, is

  1. User starts application in the development container, with remote debugging enabled. E.g. for java-mysql. This starts the application with the dependencies/modules you require, listening for remote debugging

  2. The theia debugger is used to connect to the application running in the development container, e.g. for java-debug

For PHP specifically, I don't have the background to give a definitive answer, but I'm able to get remote debugging as described above working for the php-simple sample devfile (which uses apache, so may be of limited use for your setup):

  1. Update the image we use to include XDebug, since for some reason it doesn't have it:
    FROM quay.io/eclipse/che-php-7:nightly
    
    USER 0
    RUN pecl install xdebug
    USER 10001
  2. Grab php.ini from its default path and put it in projects
    cp /usr/local/etc/php/php.ini-development /projects/php-web-simple
  3. Add recommended setings from the plugin docs to this php.ini:
    [xdebug]
    zend_extension="/usr/local/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so"
    xdebug.remote_enable = 1
    xdebug.remote_autostart = 1
    
  4. Update apache2 conf to use this php.ini: add line
    PHPINIDir /projects/php-web-simple/php.ini
    
    to /etc/apache2/sites-available/000-default.conf
  5. Start apache from terminal service apache2 start
    • Double check XDebug is enabled in phpinfo()
  6. Create and launch a debug configuration (I got it from the plugin docs):
    {
      "name": "Listen for XDebug",
      "type": "php",
      "request": "launch",
      "port": 9000
    }

With this I'm able to hit breakpoints in the index.php when loading the page. I was kind of working through this manually, but most of this could easily be automated (e.g. there's a configure sites-available command already there).

@davidwindell
Copy link
Contributor Author

@amisevsk this is fantastic, thank you. I can confirm that just by enabling the config below for xdebug in our dev container:

xdebug.remote_enable = 1
xdebug.remote_autostart = 1

it is able to communicate with Theia debugger.

I think I had misunderstood how the plugin sidecar worked because the first test I did was using a "Launch currently open script" launch command. This I believe launches the said script in the xdebug plugin sidecar (correct me if I'm wrong). Whereas the listen action works when the site is browsed via the dev container.

Thanks again!

@amisevsk
Copy link
Contributor

I'm glad I was able to help!

This I believe launches the said script in the xdebug plugin sidecar (correct me if I'm wrong).

This is correct, and also is the focus of the che-dev email you mentioned; many default debug configs in VS Code and Theia are launch configs, which usually means launching the application locally (either in the Theia or plugin sidecar container). This can often work (for simple projects), but the canonical way to do it is using remote debugging.

@davidwindell
Copy link
Contributor Author

@amisevsk thanks again! Would I be right in thinking that if our dev container has everything the plugin needs, we could use the vscode plugin directly without needing the che xdebug sidecar (to save on overall memory)

@amisevsk
Copy link
Contributor

@davidwindell Not quite, there's additional machinery we have to run to make each plugin .vsix communicate with the Theia server (see the remote runtime -- I think that's the right link). Basically there's a binary that runs in each sidecar container that is responsible for activating the plugin and connecting it to Theia.

It may be possible to combine the plugin and main dev container, though this is currently not a supported option and I don't know how it would shake out.

You can, however, try to reduce the memory allotted to the xdebug sidecar in your devfile, if memory usage is a concern, though determining whether there's enough memory in a container can be tricky.

@davidwindell
Copy link
Contributor Author

Ah, and now I can see the .vsix reference in the docs https://www.eclipse.org/che/docs/che-7/using-a-visual-studio-code-extension-in-che. Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/question Questions that haven't been identified as being feature requests or bugs.
Projects
None yet
Development

No branches or pull requests

4 participants