Skip to content

Commit

Permalink
feat: add xdebug to cli container
Browse files Browse the repository at this point in the history
  • Loading branch information
juanlopez4691 committed Jun 8, 2024
1 parent d1666a5 commit ce2ce13
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
29 changes: 29 additions & 0 deletions .docker/wp-cli/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
ARG PHP_VERSION

FROM wordpress:cli-php${PHP_VERSION:-8.1}

# Switch to root user to ensure we have the necessary permissions
USER root

RUN apk add --update linux-headers

# Install Xdebug
RUN apk --no-cache add pcre-dev ${PHPIZE_DEPS} \
&& pecl install xdebug \
&& docker-php-ext-enable xdebug \
&& apk del pcre-dev ${PHPIZE_DEPS}

# Configure Xdebug
RUN { \
echo 'xdebug.mode=debug'; \
echo 'xdebug.start_with_request=yes'; \
echo 'xdebug.client_host=host.docker.internal'; \
echo 'xdebug.client_port=9003'; \
echo 'xdebug.log=/tmp/xdebug.log'; \
} > /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

# Ensure the configuration is loaded
RUN echo 'zend_extension=xdebug.so' >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

# Switch back to the default user (if necessary)
USER www-data
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ the Usage section).

## How to Use Xdebug

Xdebug is enabled by default. To use it with Visual Studio Code, you have to
Xdebug comes pre-installed and activated in the wp and cli containers, allowing
debugging of website requests and WP-CLI commands.

To use Xdebug it with Visual Studio Code, you have to
include `?XDEBUG_SESSION=TRUE` in the URL you are browsing, and you have to use
this `launch.json` settings:

Expand Down
9 changes: 8 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,14 @@ services:

cli:
container_name: ${NAME}-cli
image: wordpress:cli-php${PHP_VERSION:-8.2}
build:
context: .
dockerfile: .docker/wp-cli/Dockerfile
args:
PHP_VERSION: ${PHP_VERSION:-8.1}
environment:
XDEBUG_MODE: develop,debug
XDEBUG_CONFIG: "client_host=host.docker.internal"
volumes_from:
- wp
links:
Expand Down

0 comments on commit ce2ce13

Please sign in to comment.