I'm trying to configure a WordPress development environment with docker-compose and Xdebug but I can't get the debugger to work with a simple break point on info.php file after starting my debugging session in VSCode.
Here are my configs:
dockerfile
FROM php:7.4-apache
RUN docker-php-ext-install mysqli
RUN pecl install xdebug
php.ini
zend_extension=xdebug.so
xdebug.profiler_enable=1
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_host=host.docker.internal
xdebug.remote_port=9003
xdebug.remote_autostart=1
xdebug.remote_connect_back=1
xdebug.idekey=VSCODE
docker-compose.yml
version: "3.9"
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
build: .
volumes:
- ./wp:/var/www/html
- ./php.ini:/usr/local/etc/php/php.ini
ports:
- "80:80"
restart: always
environment:
PHP_EXTENSION_DEBUG: 1
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {}
wp: {}
.vscode/launch.json
{
// 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": 9003,
"pathMappings": {
"/var/www/html":"${workspaceFolder}/wp"
}
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 0,
"runtimeArgs": [
"-dxdebug.start_with_request=yes"
],
"env": {
"XDEBUG_MODE": "debug,develop",
"XDEBUG_CONFIG": "client_port=${port}"
}
},
{
"name": "Launch Built-in web server",
"type": "php",
"request": "launch",
"runtimeArgs": [
"-dxdebug.mode=debug",
"-dxdebug.start_with_request=yes",
"-S",
"localhost:0"
],
"program": "",
"cwd": "${workspaceRoot}",
"port": 9003,
"serverReadyAction": {
"pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
"uriFormat": "http://localhost:%s",
"action": "openExternally"
}
}
]
}
I followed this tutorial with the exact same steps and still not able to do step debugging.
I had the same problem as you
For my case, put those config in the ini is not enough, I need to put the xdebug config into docker-compose.yml, it looks like:
services:
Wordpress:
...
environment:
XDEBUG_CONFIG: remote_host=host.docker.internal remote_port=9003 remote_enable=1
xdebug 2.7.0, php 7.0, visual code 1.72.1 (php debug ext v1.29.0)
Related
I want to ask about debugging Yii 1.1 applications. I've tried implementing the answers on StackOverflow and other websites, but my VSCode still can't debug the application, the breakpoints that have been set are never read at all. I am using Docker to run Yii.
Here are the details of the file I used.
docker-compose.yml
version: '3'
services:
web:
container_name: php72
build:
context: .
dockerfile: Dockerfile
ports:
- "8000:80"
volumes:
- ./:/var/www/html
- ./xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
networks:
- app-network
mysql:
image: mysql:8.0.31-oracle
restart: always
environment:
MYSQL_ROOT_PASSWORD: '123456'
MYSQL_USER: 'admin'
MYSQL_PASSWORD: '123456'
MYSQL_DATABASE: 'test_db'
volumes:
- db_data:/var/lib/mysql
ports:
- 3306:3306
networks:
- app-network
networks:
app-network:
volumes:
db_data:
Dockerfile
FROM php:7.2-apache
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions && \
install-php-extensions gd xdebug pdo pdo_mysql pdo_pgsql mongodb mbstring zip
EXPOSE 80
xdebug.ini
zend_extension=xdebug
[xdebug]
xdebug.mode=debug
xdebug.discover_client_host=1
xdebug.idekey=VSCODE
xdebug.start_with_request=yes
xdebug.client_port=9003
xdebug.remote_host="host.docker.internal"
launch.json
{
// 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": 9003
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 0,
"runtimeArgs": [
"-dxdebug.start_with_request=yes"
],
"env": {
"XDEBUG_MODE": "debug,develop",
"XDEBUG_CONFIG": "client_port=${port}"
}
},
{
"name": "Launch Built-in web server",
"type": "php",
"request": "launch",
"runtimeArgs": [
"-dxdebug.mode=debug",
"-dxdebug.start_with_request=yes",
"-S",
"localhost:8001"
],
"program": "",
"cwd": "${workspaceRoot}/../../",
"port": 9003,
"serverReadyAction": {
"pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
"uriFormat": "http://localhost:%s",
"action": "openExternally"
}
}
]
}
And here is my project structure:
I access my apps in a browser with localhost:8000, then I try to turn on the VSCode debugger, but this is the result:
Any help is very much appreciated.
Is there any missing configuration?
After watching several videos on how to setup Xdebug for an application running inside a docker container, I finally found the answer that works for my case.
I changed my docker-compose.yml to be like this:
version: '3'
services:
web:
container_name: php72
build:
context: .
dockerfile: Dockerfile
extra_hosts:
- "host.docker.internal:host-gateway" // Add extra host for docker
ports:
- "8000:80"
volumes:
- ./:/var/www/html // this is the remote path where my apps installed
- ./xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
networks:
- app-network
mysql:
image: mysql:8.0.31-oracle
restart: always
environment:
MYSQL_ROOT_PASSWORD: '123456'
MYSQL_USER: 'admin'
MYSQL_PASSWORD: '123456'
MYSQL_DATABASE: 'wms_test'
volumes:
- db_data:/var/lib/mysql
ports:
- 3306:3306
networks:
- app-network
networks:
app-network:
volumes:
db_data:
And as per as #LazyOne advise, since I am using Xdebug 3 I have change my xdebug.ini also to be like this:
zend_extension=xdebug
[xdebug]
xdebug.mode=develop,debug
xdebug.start_with_request=yes
xdebug.client_port=9003
xdebug.client_host=host.docker.internal
xdebug.idekey="VSCODE"
xdebug.log=/tmp/xdebug_remote.log
And the important part, after watching this YouTube video Setup Xdebug WITH DOCKER and debug in VSCode I've figured out what is missing in my previous setup, and that is the pathMapping. So I've changed my launch.json to be like this:
{
// 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": 9003,
"pathMappings": {
"/var/www/html" : "${workspaceFolder}"
}
}
]
}
And voila that work like a charm:
I'm trying to create a docker container with PHP and Xdebug to use step debugging. I use VSCode and somehow this debugger it's not working.
Apparently the Dockerfile is not been executed when I use docker compose up -d command. I assume that is because in the file it has a COPY command to copy a file (called 90-xdebug.ini) from my project to a specific directory. And after the container is up, I check the directory and the file isn't there... then I have to execute the commands in Dockerfile manually.
Anyways, after installing, I know that the installation worked because the xdebug_info() function works. But I don't know why VSCode can't debug it.
My OS is Ubuntu 20.04.5 LTS; Dockerfile, docker-compose.yml and 90-xdebug.ini are in project's root.
My Dockerfile:
FROM php:7.4-apache
COPY 90-xdebug.ini "/usr/local/etc/php/conf.d"
RUN pecl install xdebug
RUN docker-php-ext-enable xdebug
90-xdebug.ini:
xdebug.mode=debug
xdebug.discover_client_host=0
xdebug.client_host=host.docker.internal
docker-compose.yml:
services:
php-apache:
container_name: php-apache
image: php:7.4-apache
build:
context: .
dockerfile: Dockerfile
extra_hosts:
- "host.docker.internal:host-gateway"
volumes:
- ./:/var/www/html/
working_dir: /var/www/html/
ports:
- 3003:3003
entrypoint: "php -S 0.0.0.0:3003"
launch.json inside ".vscode" directory:
{
// 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": 9003
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 0,
"runtimeArgs": [
"-dxdebug.start_with_request=yes"
],
"env": {
"XDEBUG_MODE": "debug,develop",
"XDEBUG_CONFIG": "client_port=${port}"
}
},
{
"name": "Launch Built-in web server",
"type": "php",
"request": "launch",
"runtimeArgs": [
"-dxdebug.mode=debug",
"-dxdebug.start_with_request=yes",
"-S",
"localhost:0"
],
"program": "",
"cwd": "${workspaceRoot}",
"port": 9003,
"serverReadyAction": {
"pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
"uriFormat": "http://localhost:%s",
"action": "openExternally"
}
}
]
}
Extra information:
this is my program and i've put a break point on "$var = "txt1" " line, but it runs directly towards "xdebug_info()"
<?php
function fprint(string $str):void{
echo $str;
}
$var = "txt1";
fprint($var);
$var = "txt2";
fprint($var);
$var = "txt3";
fprint($var);
// echo $PHP_INI_DIR;
// echo phpinfo();
xdebug_info();
As you say (in a comment) that xdebug_info() shows that you had an active debugging connection, then that means that the debugger works. What is likely happening here is that:
you don't have any breakpoints set - in which case the debugger never breaks
more likely, that you do have a breakpoint set, but that you don't have a path mapping configured, that maps a path from inside the container (/var/www/html) to your local project route, which you can refer to with "${workspaceRoot}/html". You need to tell VS Code this path mapping by making the following configuration:
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003,
"pathMappings": {
"/var/www/html": "${workspaceRoot}/html",
}
},
I might not have gotten the exact right paths in this configuration. If you tell Xdebug to make a log file (-dxdebug.log=/tmp/xdebug.log and -dxdebug.log_level=10) it will create a log file in your container, where the contents tell you which breakpoint file name is tried to be matched against the files that PHP sees, something like:
[11] [Step Debug] DEBUG: I:
Matching breakpoint '/home/caio/dev/project/html/info.php:1'
against location '/var/www/html/info.php:2'.
If these paths don't match, adjust your path mappings.
I'm trying to debug a Laravel project in Ubuntu 20.04. There is a problem that debugger doesn't hit breakpoint just in Laravel project but in other projects Xdebug works correctly.
PHP 7.4.3
Xdebug v2.9.2
my lunch.json
{
// 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,
"log": true
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000,
"log": true
}
]}
and my php.ini:
zend_extension=”/usr/lib/php/20190902/xdebug.so”
xdebug.profiler_enable_trigger=0
xdebug.profiler_enable=0
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.remote_log="/tmp/xdebug.log"
xdebug.remote_enable=1
xdebug.remote_autostart=1
and my laravel.env:
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:foo...
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
I was in the same situation as you, and I found a solution.
Install VScode Xdebug extension
sudo apt install -y php7.4-dev php7.4-xdebug (Install Xdebug 3.*)
Set xdebug.ini
zend_extension=xdebug.so
xdebug.mode = debug
xdebug.remote_autostart = 1
; This is correct option for xdebug 3!!!
; Don't use xdebug 2 option!!!!
xdebug.client_host = localhost
xdebug.client_port = 9003
xdebug.log = /tmp/xdebug_remote.log
xdebug.log_level = 7
xdebug.start_with_request = yes
Set port 9003 in launch.json
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003,
"log": true
},
Restart php and webserver.
Check whether xdebug is installed with phpinfo();
Make test controller, route for debugging
You don't need to edit php.ini
I still don't know much about Xdebug, but I think
xdebug.start_with_request = yes is the most important.
I want to configure VS Code Xdebug plugin to work with Xdebug inside a WordPress Docker container.
I have an issue with the ports.
If I specify on the WP-with-Xdebug container in the "ports" section of the docker-compose.yml file:
- "9009:9000"
And in the environment variable XDEBUG_CONFIG on the same container:
XDEBUG_CONFIG: remote_host=172.17.0.1 mode=debug start_with_request=true client_port=9000
Then in the launch.json file of the VS Code plugin config I put this line:
"port": 9009
Then, when I run docker-compose down and then docker-compose up, I see that the docker-compose up log is good, no errors are in it. Then I click on the green Play icon before the option "Listen for Xdebug" I get the message box with:
listen EADDRINUSE: address already in use :::9009
I think that both the WP container with Xdebug in it and the VS Code plugin want to use the same port on the host 9009 to do the same think, send information to one another, but I do not understand why they do not succeed.
I did not put here the output of phpinfo() because it contains sensible information.
I use:
https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug
https://github.com/xdebug/vscode-php-debug
wpdiaries/wordpress-xdebug:latest Docker image (https://hub.docker.com/r/wpdiaries/wordpress-xdebug or https://github.com/wpdiaries/wordpress-xdebug)
Xdebug v3
latest stable version of WordPress and PHP v8.0.3
I did not try a lot but a little of this: https://github.com/mac-cain13/xdebug-helper-for-chrome and I don't think it helps me in this issue.
This is a filtered version of my docker-compose.yml:
version: '3.3'
services:
db:
container_name: "db_1"
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: "no"
environment:
MYSQL_DATABASE: "wordpress"
MYSQL_USER: "root"
MYSQL_ROOT_PASSWORD: "9821379"
wordpress:
container_name: "wordpress_1"
depends_on:
- db
image: wpdiaries/wordpress-xdebug:latest
ports:
- "80:80"
- "9009:9000"
volumes:
- type: bind
source: ./html
target: /var/www/html
volume:
nocopy: true
restart: "no"
environment:
WORDPRESS_DB_NAME: "wordpress"
WORDPRESS_DB_USER: "root"
WORDPRESS_DB_PASSWORD: "9821379"
WORDPRESS_DB_HOST: db:3306
WORDPRESS_TABLE_PREFIX: 'wp_'
XDEBUG_CONFIG: remote_host=172.17.0.1 mode=debug start_with_request=true client_port=9000
phpmyadmin:
container_name: "phpmyadmin_1"
depends_on:
- db
restart: "no"
ports:
- "8080:80"
image: phpmyadmin/phpmyadmin
environment:
PMA_HOST: db:3306
PMA_USER: "root"
PMA_PORT: 3306
PMA_PASSWORD: "9821379"
volumes:
db_data: {}
This is my launch.json file:
{
// 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": 9009,
"pathMappings": {
"/var/www/html": "${workspaceFolder}/html"
}
},
// the following is not used and not updated:
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9003
}
]
}
Articles I've tried more or less:
https://dev.to/natterstefan/docker-tip-how-to-get-host-s-ip-address-inside-a-docker-container-5anh
https://dzone.com/articles/setup-wordpress-debug-environment-with-docker-and
https://www.wpdiaries.com/wordpress-with-xdebug-for-docker/#using-a-ready-made-image
I've rebooted my laptop and the same issue appears again.
Until I get a reaction to this post I think I will read the docs here: https://xdebug.org/docs/step_debug.
I think that both the WP container with Xdebug in it and the VS Code plugin want to use the same port on the host 9009
Yes, that nails it on the head. It is Xdebug that makes the connection, so there is no reason to expose the 9000/9009 port on the WordPress containers as that is for incoming connections. You can remove that expose line.
I'm trying to debug a PHP app running on Docker with VSCode, but without success.
In the past I was able to easily debug my PHP apps with VSCode running WAMP Server, but since I started working with Docker I'm unable to get debug working. Searched for several tutorials online, checked some threads here on StackOverflow (ex.: Docker and XDebug not reading breakpoints VSCode), but I'm still not able to get this working.
Dockerfile:
FROM php:7.1.8-apache
COPY /cms /srv/app/cms
COPY .docker/cms/vhosts/vhost.conf /etc/apache2/sites-available/cms.conf
COPY .docker/cms/vhosts/vhost-ssl.conf /etc/apache2/sites-available/cms-ssl.conf
COPY .docker/cms/vhosts/certificate.conf /etc/ssl/certs/certificate.conf
COPY .docker/cms/xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini
WORKDIR /srv/app/cms
RUN docker-php-ext-install mbstring pdo pdo_mysql
RUN pecl install xdebug
RUN docker-php-ext-enable xdebug
RUN chown -R www-data:www-data /srv/app/cms
RUN openssl req -x509 -new -out /etc/ssl/certs/ssl-cert-cms.crt -config /etc/ssl/certs/certificate.conf
RUN a2ensite cms.conf
RUN a2ensite cms-ssl.conf
RUN a2enmod rewrite
RUN a2enmod ssl
xdebug.ini
[xdebug]
xdebug.default_enable=1
xdebug.remote_enable=1
xdebug.remote_port=9000
xdebug.remote_connect_back=0
xdebug.remote_host='host.docker.internal'
xdebug.idekey='VSCODE'
xdebug.remote_autostart=1
docker-compose.yml
version: '3.7'
services:
cms:
build:
context: .
dockerfile: .docker/cms/Dockerfile
image: php:7.1.8-apache
ports:
- 18080:80
- 14430:443
volumes:
- ./cms:/srv/app/cms
links:
- mysql
- redis
environment:
DB_HOST: mysql
VIRTUAL_HOST: my.app.localhost
PHP_EXTENSION_XDEBUG: 1
VSCode: launch.json
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"pathMappings": {
"/srv/app/cms": "${workspaceRoot}/my.app/cms",
},
"port": 9000
}, {
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
When I debug the app no breakpoint is being triggered. What am I doing wrong?
UPDATE:
Based on some suggestions i've updated my docker-compose.yml and my launch.json files but nothing changed.
docker-compose.yml
ports:
- 18080:80
- 14430:443
- 9000:9000 //added new xdebug default port
launch.json
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"pathMappings": {
"/srv/app/cms": "${workspaceRoot}/my.app/cms",
},
"port": 9000,
"log": true
}
]
VSCode Debug Console:
<- launchResponse
Response {
seq: 0,
type: 'response',
request_seq: 2,
command: 'launch',
success: true }
UPDATE #2:
Removed the Xdebug port (9000) from the docker-compose.yml settings. Here is the xdebug log result:
Log opened at 2018-09-30 22:21:09 I: Connecting to configured
address/port: host.docker.internal:9000. E: Time-out connecting to
client (Waited: 200 ms). :-( Log closed at 2018-09-30 22:21:09
Log opened at 2018-09-30 22:21:17 I: Connecting to configured
address/port: host.docker.internal:9000. E: Time-out connecting to
client (Waited: 200 ms). :-( Log closed at 2018-09-30 22:21:17
Log opened at 2018-09-30 22:21:18 I: Connecting to configured
address/port: host.docker.internal:9000. E: Time-out connecting to
client (Waited: 200 ms). :-( Log closed at 2018-09-30 22:21:18
Log opened at 2018-09-30 22:21:18 I: Connecting to configured
address/port: host.docker.internal:9000. E: Time-out connecting to
client (Waited: 200 ms). :-( Log closed at 2018-09-30 22:21:18
Any more suggestions?
Managed to solve my issue with the following settings:
launch.json
{
"version": "0.2.0",
"configurations": [{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"log": true,
"externalConsole": false,
"pathMappings": {
"/srv/app/cms": "${workspaceRoot}/cms",
},
"ignore": [
"**/vendor/**/*.php"
]
},
]
}
xdebug.ini
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so
xdebug.default_enable=1
xdebug.remote_enable=1
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.remote_connect_back=0
xdebug.remote_host=host.docker.internal
xdebug.idekey=VSCODE
xdebug.remote_autostart=1
xdebug.remote_log=/usr/local/etc/php/xdebug.log
Since xdebug version 3 there are breaking changes in config names.
My current working dockerfile:
RUN apt-get update; \
apt-get -y --no-install-recommends install \
php7.4-dev \
php-pear \
libcurl3-openssl-dev \
libmcrypt-dev \
libxml2-dev \
libpng-dev \
; \
pecl install xdebug; \
{ \
echo "[xdebug]"; \
echo "zend_extension=$(find /usr/lib/php/ -name xdebug.so)"; \
echo "xdebug.mode=debug"; \
echo "xdebug.start_with_request=yes"; \
echo "xdebug.client_host=host.docker.internal"; \
echo "xdebug.client_port=9001"; \
} >> /etc/php/7.4/mods-available/xdebug.ini; \
phpenmod -v 7.4 xdebug; \
VSC debug config:
"configurations": [
{
"name": "XDebug (Docker)",
"type": "php",
"request": "launch",
"port": 9001,
"pathMappings": {
"/var/www/app": "${workspaceRoot}",
}
}
]
More info: https://xdebug.org/docs/upgrade_guide
Well, I have tried all the above answers and have spend hours but got not success because in all the above answer some concepts were not clear to new x-debug user just like me. I wish that I would have know the following concepts before starting setting up x-debugger, running on a docker container or a remote server, with my VS Code's PHP Debug. I am sure this will help searching for the solution of such issue.
X-Debug Settings
I was not certain that if my machine should be considered as client host or server host, though it was obvious but when you have spent hours on configurations then simple things started to get tricky ones.
xdebug.client_host
According to X-debug Docs:
This address should be the address of the machine where your IDE or debugging client is listening for incoming debugging connections.
I think, with the above piece of text needs no explanation. Hence, setup it up as follows in our x-debug configurations i.e. xdebug.ini:
xdebug.client_host=host.docker.internal
xdebug.remote_host
This was a bit tricky config to me. Actually there is no such configurations for x-debug but I kept thinking about it. :-)
PHP-Debug Settings
hostname
I had been using different configurations except this one (as in this thread no one had mentioned this) :-) and there was no success. I then re-explored the docs of PHP Debug came to know that it must get set to localhost in my case, and gave it a try, and boom! It worked!
"hostname": "localhost"
port
The should be set same as the xdebug.client_port and default value is 9300. Repeatedly mentioned in above answers.
pathMappings
This is an other really important config when trying to setup a docker server with your VS Code PHP Debug. It is an object and must map your local directory structure to the server/container directory i.e. /home/user/proj/html: ${workspaceRoot}. I can't further explain it, it did worked for me and I have mentioned it here. I will welcome if someone explain it.
Here are my final settings:
Hope this will help and save your hours :-)
you are missing port :9000 (or :9001) in the docker-compose.yml,
which needs to be connectable, for the IDE to connect from the outside.
for VSCode the PHP Debug extension might be required to interact with xdebug.
the default launch.json only uses port: 9000 only once - and has log: true.
{
"configurations": [{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"log": true
}, {
"name": "Launch",
"request": "launch",
"type": "php",
"program": "${file}",
"cwd": "${workspaceRoot}",
"externalConsole": false
}
]
}
also see vscode-php-debug and starting the debugger.
For everyone running on the following stack:
Ubuntu
XDebug 3
Laravel Sail
docker/8.0/php.ini
[xdebug]
xdebug.discover_client_host=true
xdebug.start_with_request=yes
.env
SAIL_XDEBUG_MODE=develop,debug
# For linux only:
# you may read up about how to get the ip here: https://laravel.com/docs/8.x/sail#debugging-with-xdebug
SAIL_XDEBUG_CONFIG="client_host=172.22.0.1"
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug via Docker",
"type": "php",
"request": "launch",
"port": 9000,
"log": true,
"externalConsole": false,
"pathMappings": {
"/var/www/html": "${workspaceRoot}/www",
},
"ignore": [
"**/vendor/**/*.php"
]
},
] }
XDEBUG v3 example for Symfony
docker-compose.yml:
###> XDEBUG 3 ###
# Use your client IP here
# Linux: run "ip a | grep docker0"
# Windows (with WSL2): Run "grep nameserver /etc/resolv.conf | cut -d ' ' -f2"
# MacOS: host.docker.internal
###< XDEBUG 3 ###
environment:
XDEBUG_CLIENT_HOST: 172.17.0.1
XDEBUG_CLIENT_PORT: 9003
PHP_IDE_CONFIG: serverName=Docker
volumes:
- ./xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini
xdebug.ini
xdebug.mode=debug,coverage
xdebug.start_with_request=yes
xdebug.client_host=${XDEBUG_CLIENT_HOST}
xdebug.client_port=${XDEBUG_CLIENT_PORT}
xdebug.ini for php:7.2-fpm-alpine3.8
zend_extension=xdebug.so
[xdebug]
xdebug.cli_color = 1
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.discover_client_host = 0
xdebug.client_host=host.docker.internal
xdebug.ideKey=docker
Example config vscode modify pathMappings
launch.json:
{
"version": "0.2.0",
"configurations": [{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9003,
"log": true,
"externalConsole": false,
"pathMappings": {
"/appdata/www": "${workspaceRoot}/api",
},
"ignore": [
"**/vendor/**/*.php"
]
},
]
}