1

I try to setup Xdebug for shopware-docker without success.

VHOST_[FOLDER_NAME_UPPER_CASE]_IMAGE=ghcr.io/shyim/shopware-docker/6/nginx:php74-xdebug

After replacing your Folder Name and running swdc up Xdebug should be activated.

Which folder name should I place?
Using myname, the same name as in /var/www/html/myname, return error on swdc up myname:

swdc up myname
[+] Running 2/0
 ⠿ Network shopware-docker_default    Created                                                                                                                                  0.0s
 ⠿ Container shopware-docker-mysql-1  Created                                                                                                                                  0.0s
[+] Running 1/1
 ⠿ Container shopware-docker-mysql-1  Started                                                                                                                                  0.3s
.database ready!
[+] Running 0/1
 ⠿ app_myname Error                                                                                                                                                       1.7s
Error response from daemon: manifest unknown

EDIT #1
With this setup VHOST_MYNAME_IMAGE=ghcr.io/shyim/shopware-docker/6/nginx:php81-xdebug (versioned Xdebug) the app started:

// $HOME/.config/swdc/env
...
VHOST_MYNAME_IMAGE=ghcr.io/shyim/shopware-docker/6/nginx:php81-xdebug

But set a debug breakpoint (e.g. in index.php), nothing happens

EDIT #2
As @Alex recommend, i place xdebug_break() inside my code and it works.
Stopping on the breakpoint the debugger log aswers with hints/warnings like described in the manual:

...
Cannot find a local copy of the file on server /var/www/html/%my_path%
Local path is //var/www/html/%my_path%
...

  • click on Click to set up path mapping to open the modal
    enter image description here
  • click inside modal select input Use path mapping (...) enter image description here
  • input field File path in project response with undefined enter image description here

But i have already set up the mapping like described in the manual, go to File | Settings | PHP | Servers:
enter image description here

Why does not work my mapping? Where failed my set up?

rammi22
  • 271
  • 1
  • 11
  • Try to set a breakpoint with inserting `xdebug_break()` into the code. If that works, you might have a Problem with your directory mapping. Are you using PHPStorm or another IDE? – Alex Dec 23 '22 at 06:57
  • @Alex, yes, with the `xdebug_break` it works and yes, i use PHPStorm. How do i map the directory? Under `File -> Settings -> PHP -> Servers`? Could i map any provided files? – rammi22 Dec 23 '22 at 12:40
  • Yes, you just need to map the root directory there – Alex Dec 24 '22 at 13:02
  • @Alex see my **EDIT #2** – rammi22 Dec 24 '22 at 13:49
  • Sometimes there are problems with detecting the server name from the docker container. You might try something like this: https://stackoverflow.com/a/50176116/288568 So what you are setting in the last screenshot seems correct, but PHPStorm/Xdebug might not apply it because the server name does not match. – Alex Dec 27 '22 at 08:35
  • But what if you supply the local path in the 2nd/3rd screenshot? – Alex Dec 27 '22 at 08:39
  • Did you ever solve this issue? I have the very same problem and I don't know how to get rid of it – Robin Schambach Jul 19 '23 at 07:59
  • 1
    @RobinSchambach I use xdebug_break() to debug – rammi22 Jul 19 '23 at 11:30

1 Answers1

1

The path mapping needs to be between your local project path on your workstation and the path inside the docker containers. Without xDebug has a hard time mapping the breakpoints from PHPStorm to the actual code inside the container.

If mapping the path correctly does not work and if its a possibility for you, i can highly recommend switching to http://devenv.sh for your development enviroment. Shopware itself promotes this new enviroment in their documentation: https://developer.shopware.com/docs/guides/installation/devenv and provides an example on how to enable xdebug:

# devenv.local.nix File
{ pkgs, config, lib, ... }:

{
  languages.php.package = pkgs.php.buildEnv {
    extensions = { all, enabled }: with all; enabled ++ [ amqp redis blackfire grpc xdebug ];
    extraConfig = ''
      # Copy the config from devenv.nix and append the XDebug config
      # [...]
      xdebug.mode=debug
      xdebug.discover_client_host=1
      xdebug.client_host=127.0.0.1
    '';
  };
}

A correct path mapping should not be needed here, as your local file location is the same for XDebug and your PHPStorm.

Jochen
  • 124
  • 5