Configuring Xdebug with docker compose
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 on vscode. here are my configs:
rootDir/.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
}
}
]
}
rootDir/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: {}
rootDir/dockerfile\
FROM php:7.4-apache
RUN docker-php-ext-install mysqli
RUN pecl install xdebug
Topic docker plugin-development theme-development Wordpress
Category Web