Docker Php Xdebug



  1. After executing that command from your Docker container with Xdebug enabled PHP server the debugger (on your computer) should/may exit (like my vdebug does), which means that it receives some message. This behavior will confirm that port number 9000 and IP address 10.254.254.254 are correct choice and should be used in Xdebug configuration.
  2. 6th April 2021 docker, php, phpstorm, xdebug I have docker installed on my Linux host and raised a container with php-fpm and xdebug. Phpstorm is installed on Windows server.
IDProjectCategoryView StatusDate SubmittedLast Update
0001877XdebugStep Debuggingpublic2020-11-02 17:562021-03-27 13:19
ReporterTomaszKaneAssigned Toderick
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionunable to reproduce
PlatformLinuxOSKDE NeonOS Version5.19
Product Version3.0.0beta1
Summary0001877: Xdebug from docker container can't connect to client
DescriptionHi,
I try to use new Xdebug on my laptop T490 with KDE Neon and PhpSorm.
Project runs on few docker containers (below config for nginx and php)
What is missing or broke with my configuration?
Steps To Reproduceinstall xdebug-3.0.0beta1via PECL and enable it (on php 7.4 fpm container)
write xdebug config:
xdebug.mode=debug
xdebug.discover_client_host=1
xdebug.cli_color=1
xdebug.html_errors=2
xdebug.var_display_max_depth = 8
xdebug.var_display_max_children = 128
xdebug.var_display_max_data = 1024
xdebug.idekey=PHPSTORM
xdebug.log=/var/log/xdebug.log
docker-compose:
version: '3'
services:
php-7.4:
build: ./docker-images/php-7.4
image: ap/php:7.4
container_name: sp-php-7.4
expose:
- '${SSH_PORT}'
ports:
- '${SSH_PORT}:22'
environment:
- X_LEGACY_GD_LIB=${X_LEGACY_GD_LIB}
- GITHUB_API_TOKEN=${GITHUB_API_TOKEN}
- TEST_RUNTIME_PATH=/tmp/runtime
volumes:
- ~/.composer-docker/cache:/root/.composer/cache:delegated
- ~/.gitconfig:/root/.gitconfig
- ${WORKSPACE_DIR}:/var/www
- ~/.ssh:/root/ssh:ro
nginx-1.19:
build: ./docker-images/nginx-1.19
image: ap/nginx:1.19
container_name: sp-nginx-1.19
depends_on:
- php-7.4
environment:
- PHP_CGI_PASS=${PHP_CGI_PASS}
ports:
- '${NGINX_PORT}:80'
- '${NGINX_SSL_PORT}:443'
volumes:
- ./vhosts:/etc/nginx/conf.d-dist
- ${WORKSPACE_DIR}:/var/www
Browser - Firefox with Cookie:
XDEBUG_SESSION=PHPSTORM
PhpStorm with config like on attached screenshos
(with mapped project root directory)
Listening is on:
$ lsof -i :9003 | grep LISTEN
java 5130 kane 23u IPv6 3040907 0t0 TCP *:9003 (LISTEN)
/etc/hosts like:
172.17.0.1 some.address.pl
Additional Informationphp -v
PHP 7.4.8 (cli) (built: Jul 9 2020 23:21:18) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.8, Copyright (c), by Zend Technologies
with Xdebug v3.0.0beta1, Copyright (c) 2002-2020, by Derick Rethans
xdebug log:
[6] Log opened at 2020-11-02 17:20:12.510627
[6] [Step Debug] INFO: Checking remote connect back address.
[6] [Step Debug] INFO: Checking header 'HTTP_X_FORWARDED_FOR'.
[6] [Step Debug] INFO: Checking header 'REMOTE_ADDR'.
[6] [Step Debug] INFO: Client host discovered through HTTP header, connecting to 172.22.0.1:9003.
[6] [Step Debug] WARN: Could not connect to client host discovered through HTTP headers, connecting to configured address/port: localhost:9003. :-|
[6] [Step Debug] WARN: Creating socket for 'localhost:9003', poll success, but error: Operation now in progress (29).
[6] [Step Debug] WARN: Creating socket for 'localhost:9003', connect: Cannot assign requested address.
[6] [Step Debug] ERR: Could not connect to debugging client. Tried: 172.22.0.1:9003 (from REMOTE_ADDR HTTP header), localhost:9003 (fallback through xdebug.client_host/xdebug.client_port) :-(
[6] Log closed at 2020-11-02 17:20:12.868660
Operating SystemDebian
PHP Version7.4.0-7.4.4

On the previous post we created an Apache/PHP Docker Container with the Xdebug extension.
Now we are going to use that container to demonstrate how to debug a PHP file using VSCode.


I have a problem with xdebug run on docker. My phpStorm not discover xdebug and not stop even on first script line. My project is in symfony 5. Eveything apart xdebug works fine. I have connection to database and page displaying properly in web browser. I tried many things but without success. Of course What is wrong in my config?

Docker Php Xdebug

First let's create a folder for the Dockerfile and a sample PHP file. Change the current directory to this newly created folder.


With your preferred editor create two files 'Dockerfile' and 'index.php', and then copy into these files the following content:
Roline driver download.

Dockerfile


index.php


You can download the above files, as a zip file here.

Debug Php Vscode Remote


You should have the following folder and files structure.


Create the Docker Image and Container

Let's create the Docker Image, and the Container.


At this point our Container should be running and ready to receive requests at the port 4000.


We can proceed now to open VSCode.


Docker php xdebug slow

On VSCode make sure to have installed the PHP Debug extension.


Next, click on Open folder.. and locate the folder we just created above and select it.


You should see the two files 'Dockerfile' and 'index.php'
Open the 'index.php' file.


On the Line 6 of the index.php file, add a Breakpoint by clicking on the area at the left of the line numbers. A 'red' dot will appear indicating that the breakpoing has been set.
On the left navigation toolbar, click on the Run (Debugger) icon.
Then click on the create a launch.json file link.


A drop down will show up. Click on the PHP option.


Brave browser portable download. A new file named launch.json will be created on the main area, with the content shown on the screenshot below.


The launch.json contains two debugging configurations. We are going to use the one named 'Listen for Debug'
But, before we start debugging, we need to add a new item to that configuration.
We need to add the following code, which 'maps' the folder on the Server (left), with the folder on our Local machine (right)



On the top left section, click on the 'Play' icon (green triangle)
This will 'start' a debugging session on VSCode. You can see that a new toolbar appears at the top center area of the editor. This toolbar contains the 'controls' that allow us to debug our code.
You will notice too that the bottom status bar color has changed to orange.


Now, open your preferred Browser, and go to the http://localhost:4000/index.php url.


VSCode will regain the focus, and will highlight the line with the breakpoint on the index.php file.
The debugging session will be on 'pause'. You can start debugging by clicking on the icons on the top toolbar.


Downloads

test_xdebug_docker.zip

Docker Php Ext Enable






Comments are closed.