How to use xdebug in app development

The following environment is used for development

wsl2
phpstorm
docker: ghcr.io/juliushaertl/nextcloud-dev-php

I have configured Xdebug,
The process does not stop when I set a breakpoint.

Can you please help me?

It is hard to tell from that little information what the problem is.

You mentioned Julius’ docker setup. Did you set it up completely or just started the container?

Otherwise, I would expect the problem to be the path mappings in PHPStorm.

Christian

Thanks for the reply.

Sorry about that,
It is difficult to give the necessary information because we do not know the cause of the problem.
Keep the questions coming, please.

I have finished the tutorial on catgifs.
I placed a breakpoint in the catgifs php program though,
It is not stopping.

The path mapping looks like the image.

また、以下の質問を参考にしています。

以下のコマンドは実行しています

./php-mod-config nextcloud xdebug.mode debug

Could you please extent the log level and check the logs? There you should see if the PHP interpreter has found the debug extension and if the path mapping is actually the problem.

PS: I guess that the path mapping are wrong. Isn’t it like /var/www/HTML/apps-extra/catgifs. You need the path to nap the path of the app in the container.

1 Like

Thank you.
I feel like I’ve made some progress!

Several errors have been corrected.
After starting Docker, run the following

. /scripts/php-mod-config nextcloud xdebug.mode debug

PATHMAP

docker container

image

xdebug.log

Although the following logs were output,
I could not find out what to do with XDBUG_TRIGGER

[1009] Log opened at 2024-02-11 14:31:29.393662
[1009] [Config] INFO: Control socket set up succesfully: '@xdebug-ctrl.1009'
[1009] [Config] DEBUG: Checking if trigger 'XDEBUG_TRIGGER' is enabled for mode 'debug'
[1009] [Config] INFO: Trigger value for 'XDEBUG_TRIGGER' not found, falling back to 'XDEBUG_SESSION'
[1009] [Config] INFO: No shared secret: Activating
[1009] [Step Debug] INFO: Checking for client discovery headers: 'HTTP_X_FORWARDED_FOR,REMOTE_ADDR'.
[1009] [Step Debug] INFO: Checking header 'HTTP_X_FORWARDED_FOR'.
[1009] [Step Debug] INFO: Client host discovered through HTTP header, connecting to 192.168.21.1:9003.
[1009] [Step Debug] WARN: Creating socket for '192.168.21.1:9003', poll success, but error: Operation now in progress (29).
[1009] [Step Debug] WARN: Could not connect to client host discovered through HTTP headers, connecting to configured address/port: host.docker.internal:9003.
[1009] [Step Debug] WARN: Creating socket for 'host.docker.internal:9003', poll success, but error: Operation now in progress (29).
[1009] [Step Debug] ERR: Could not connect to debugging client. Tried: 192.168.21.1:9003 (from HTTP_X_FORWARDED_FOR HTTP header), host.docker.internal:9003 (fallback through xdebug.client_host/xdebug.client_port).
[1009] [Config] DEBUG: Checking if trigger 'XDEBUG_TRIGGER' is enabled for mode 'debug'
[1009] [Config] INFO: Trigger value for 'XDEBUG_TRIGGER' not found, falling back to 'XDEBUG_SESSION'
[1009] [Config] INFO: No shared secret: Activating
[1009] [Step Debug] INFO: Checking for client discovery headers: 'HTTP_X_FORWARDED_FOR,REMOTE_ADDR'.
[1009] [Step Debug] INFO: Checking header 'HTTP_X_FORWARDED_FOR'.
[1009] [Step Debug] INFO: Client host discovered through HTTP header, connecting to 192.168.21.1:9003.
[1009] [Step Debug] WARN: Creating socket for '192.168.21.1:9003', poll success, but error: Operation now in progress (29).
[1009] [Step Debug] WARN: Could not connect to client host discovered through HTTP headers, connecting to configured address/port: host.docker.internal:9003.
[1009] [Step Debug] WARN: Creating socket for 'host.docker.internal:9003', poll success, but error: Operation now in progress (29).
[1009] [Step Debug] ERR: Could not connect to debugging client. Tried: 192.168.21.1:9003 (from HTTP_X_FORWARDED_FOR HTTP header), host.docker.internal:9003 (fallback through xdebug.client_host/xdebug.client_port).
[1009] [Config] DEBUG: Checking if trigger 'XDEBUG_TRIGGER' is enabled for mode 'debug'
[1009] [Config] INFO: Trigger value for 'XDEBUG_TRIGGER' not found, falling back to 'XDEBUG_SESSION'
[1009] [Config] INFO: No shared secret: Activating
[1009] [Step Debug] INFO: Checking for client discovery headers: 'HTTP_X_FORWARDED_FOR,REMOTE_ADDR'.
[1009] [Step Debug] INFO: Checking header 'HTTP_X_FORWARDED_FOR'.
[1009] [Step Debug] INFO: Client host discovered through HTTP header, connecting to 192.168.21.1:9003.
[1009] [Step Debug] WARN: Creating socket for '192.168.21.1:9003', poll success, but error: Operation now in progress (29).
[1009] [Step Debug] WARN: Could not connect to client host discovered through HTTP headers, connecting to configured address/port: host.docker.internal:9003.
[1009] [Step Debug] WARN: Creating socket for 'host.docker.internal:9003', poll success, but error: Operation now in progress (29).
[1009] [Step Debug] ERR: Could not connect to debugging client. Tried: 192.168.21.1:9003 (from HTTP_X_FORWARDED_FOR HTTP header), host.docker.internal:9003 (fallback through xdebug.client_host/xdebug.client_port).
[1009] [Config] DEBUG: Checking if trigger 'XDEBUG_TRIGGER' is enabled for mode 'debug'
[1009] [Config] INFO: Trigger value for 'XDEBUG_TRIGGER' not found, falling back to 'XDEBUG_SESSION'
[1009] [Config] INFO: No shared secret: Activating
[1009] [Step Debug] INFO: Checking for client discovery headers: 'HTTP_X_FORWARDED_FOR,REMOTE_ADDR'.
[1009] [Step Debug] INFO: Checking header 'HTTP_X_FORWARDED_FOR'.
[1009] [Step Debug] INFO: Client host discovered through HTTP header, connecting to 192.168.21.1:9003.
[1009] [Step Debug] WARN: Creating socket for '192.168.21.1:9003', poll success, but error: Operation now in progress (29).
[1009] [Step Debug] WARN: Could not connect to client host discovered through HTTP headers, connecting to configured address/port: host.docker.internal:9003.
[1009] [Step Debug] WARN: Creating socket for 'host.docker.internal:9003', poll success, but error: Operation now in progress (29).
[1009] [Step Debug] ERR: Could not connect to debugging client. Tried: 192.168.21.1:9003 (from HTTP_X_FORWARDED_FOR HTTP header), host.docker.internal:9003 (fallback through xdebug.client_host/xdebug.client_port).
[1009] [Config] DEBUG: Checking if trigger 'XDEBUG_TRIGGER' is enabled for mode 'debug'
[1009] [Config] INFO: Trigger value for 'XDEBUG_TRIGGER' not found, falling back to 'XDEBUG_SESSION'
[1009] [Config] INFO: No shared secret: Activating
[1009] [Step Debug] INFO: Checking for client discovery headers: 'HTTP_X_FORWARDED_FOR,REMOTE_ADDR'.
[1009] [Step Debug] INFO: Checking header 'HTTP_X_FORWARDED_FOR'.
[1009] [Step Debug] INFO: Client host discovered through HTTP header, connecting to 192.168.21.1:9003.
[1009] [Step Debug] WARN: Creating socket for '192.168.21.1:9003', poll success, but error: Operation now in progress (29).
[1009] [Step Debug] WARN: Could not connect to client host discovered through HTTP headers, connecting to configured address/port: host.docker.internal:9003.
[1009] [Step Debug] WARN: Creating socket for 'host.docker.internal:9003', poll success, but error: Operation now in progress (29).
[1009] [Step Debug] ERR: Could not connect to debugging client. Tried: 192.168.21.1:9003 (from HTTP_X_FORWARDED_FOR HTTP header), host.docker.internal:9003 (fallback through xdebug.client_host/xdebug.client_port).
[1009] [Config] DEBUG: Checking if trigger 'XDEBUG_TRIGGER' is enabled for mode 'debug'
[1009] [Config] INFO: Trigger value for 'XDEBUG_TRIGGER' not found, falling back to 'XDEBUG_SESSION'
[1009] [Config] INFO: No shared secret: Activating
[1009] [Step Debug] INFO: Checking for client discovery headers: 'HTTP_X_FORWARDED_FOR,REMOTE_ADDR'.
[1009] [Step Debug] INFO: Checking header 'HTTP_X_FORWARDED_FOR'.
[1009] [Step Debug] INFO: Client host discovered through HTTP header, connecting to 192.168.21.1:9003.
[1009] [Step Debug] WARN: Creating socket for '192.168.21.1:9003', poll success, but error: Operation now in progress (29).
[1009] [Step Debug] WARN: Could not connect to client host discovered through HTTP headers, connecting to configured address/port: host.docker.internal:9003.
[1009] [Step Debug] WARN: Creating socket for 'host.docker.internal:9003', poll success, but error: Operation now in progress (29).
[1009] [Step Debug] ERR: Could not connect to debugging client. Tried: 192.168.21.1:9003 (from HTTP_X_FORWARDED_FOR HTTP header), host.docker.internal:9003 (fallback through xdebug.client_host/xdebug.client_port).
[1009] [Config] DEBUG: Checking if trigger 'XDEBUG_TRIGGER' is enabled for mode 'debug'
[1009] [Config] INFO: Trigger value for 'XDEBUG_TRIGGER' not found, falling back to 'XDEBUG_SESSION'
[1009] [Config] INFO: No shared secret: Activating
[1009] [Step Debug] INFO: Checking for client discovery headers: 'HTTP_X_FORWARDED_FOR,REMOTE_ADDR'.
[1009] [Step Debug] INFO: Checking header 'HTTP_X_FORWARDED_FOR'.
[1009] [Step Debug] INFO: Client host discovered through HTTP header, connecting to 192.168.21.1:9003.
[1009] [Step Debug] WARN: Creating socket for '192.168.21.1:9003', poll success, but error: Operation now in progress (29).
[1009] [Step Debug] WARN: Could not connect to client host discovered through HTTP headers, connecting to configured address/port: host.docker.internal:9003.
[1009] [Step Debug] WARN: Creating socket for 'host.docker.internal:9003', poll success, but error: Operation now in progress (29).
[1009] [Step Debug] ERR: Could not connect to debugging client. Tried: 192.168.21.1:9003 (from HTTP_X_FORWARDED_FOR HTTP header), host.docker.internal:9003 (fallback through xdebug.client_host/xdebug.client_port).
[1009] Log closed at 2024-02-11 14:31:29.440987

PHP RemoteDebug

The following is additional information

OK, now start by temporarily increasing the PHP xdebug log level. This can be done by ./scripts/php-mod-config nextcloud xdebug.log_level 7.

Next the question is: have you enabled listening in the IDE for incoming connections? It should look on port 9003. Alternatively, you can change the port to connect from the PHP xdebug session.

Again some basic questions:

  1. Have you used the complete docker compose setup by Julius? This is important to know so I can look up the details there and do not have to ask you a dozen questions.
  2. Can you please check in the container the path of the app. It should be installed in the NC folder, depending on your NC config. Is it mounted there? What path is the app in?
  3. Do you have a static IP address in Windows active? This might make thinks easier as no routing through WSL is needed…

Christian

Thanks for the answer.

Have you used the complete docker compose setup by Julius?

Yes, I use it.
The tutorial states the following

Step 7: Install git and nextcloud-docker-dev

  • Install the git version control system:
sudo apt install git
  • Clone the nextcloud-docker-dev development environment for Nextcloud and follow the simple master setup to download and install Nextcloud:
git clone https://github.com/juliushaertl/nextcloud-docker-dev.git
cd nextcloud-docker-dev
./bootstrap.sh
sudo sh -c "echo '127.0.0.1 nextcloud.local' >> /etc/hosts"
  • Now you can start nextcloud:
docker-compose up nextcloud proxy

My environment is in a state where I have finished the tutorial

now start by temporarily increasing the PHP xdebug log level.

. /scripts/php-mod-config nextcloud xdebug.log_level 7.
This is the log after running

xdebug.ini

; off develop debug gcstats profile trace
xdebug.mode = develop
xdebug.idekey=PHPSTORM
xdebug.trace_output_name=trace.%R.%u
xdebug.profiler_output_name=profile.%R.%u
xdebug.output_dir=/shared/xdebug

xdebug.log = /var/log/xdebug.log
xdebug.log_level=7.

; Try to discover the client host, otherwise fall back to the docker host
xdebug.discover_client_host=true
xdebug.client_host=host.docker.internal

; When you cannot specify a trigger, use "xdebug.start_with_request = yes" to autostart debugging for all requests
; https://xdebug.org/docs/all_settings#start_with_request
xdebug.start_with_request = trigger

; Set xdebug.mode trace to use this
; More details at https://derickrethans.nl/flamboyant-flamegraphs.html
xdebug.trace_format=3
xdebug.trace_output_name=xdebug.%R.%u

xdebug log

[810] Log opened at 2024-02-13 09:02:32.147743
[810] [Config] INFO: Control socket set up succesfully: '@xdebug-ctrl.810'
[810] Log closed at 2024-02-13 09:02:32.394902

The log I posted earlier was log level 10.

Next the question is: have you enabled listening in the IDE for incoming connections?

Sorry if that wasn’t an answer.
The app is located at
image

Can you please check in the container the path of the app.

catgifts are available at the location in the image
image

Do you have a static IP address in Windows active?

Not on a static IP address.

This looks good so far. Just to rule out the networking, please get your local IP address on windows. In a terminal you could type route print or just look in the system settings somewhere (sorry mainly Linux user). Take the IP and configure the default IP PHP will try by ./scripts/php-mod-config nextcloud xdebug.client_host 1.2.3.4, replacing the IP with your one.

I guess you are running the IDE in listening mode, I have no experience with PHPStorm.