TrafeX / docker-php-nginx

Docker image with PHP-FPM 8.3 & Nginx 1.24 on Alpine Linux
https://hub.docker.com/r/trafex/php-nginx
MIT License
1.33k stars 721 forks source link

How can I enable Xdebug? #138

Closed rolka closed 10 months ago

rolka commented 10 months ago

How can I enable Xdebug in trafex/php-nginx? I use PhpStorm. Where can I find instructions for this?

C0mp4ct commented 10 months ago

You have to extend this image and make your own.

add this xdebug config in your build step:

.docker/php/conf.d/zz-xdebug.ini

zend_extension=xdebug.so
xdebug.mode=develop,debug
xdebug.discover_client_host=true
xdebug.start_with_request=yes
xdebug.trigger_value=PHPSTORM
xdebug.log_level=0

xdebug.var_display_max_children=10
xdebug.var_display_max_data=10
xdebug.var_display_max_depth=10

xdebug.client_host=host.docker.internal
xdebug.client_port=9003

You have to copy this file to the /etc/php82/conf.d folder in build step:

Dockerfile:

FROM trafex/php-nginx:3.2.0

USER root

# Install composer from the official image
COPY --from=composer /usr/bin/composer /usr/bin/composer

ENV PHP_INI_DIR /etc/php82

RUN apk add --no-cache \
    bash \
    php82-iconv \
    php82-pecl-xdebug

RUN ln -s /usr/bin/php82 /usr/bin/php

# disable annoying logs
RUN sed -i '/\[supervisord\]/a loglevel=error' /etc/supervisor/conf.d/supervisord.conf && \
    sed -i 's/^;\?log_level = .*/log_level = error/' /etc/php82/php-fpm.conf

RUN mkdir -p /.composer; \
    chown -R nobody.nobody /.composer

USER nobody

#  custom php config
COPY .docker/php /etc/php82
TrafeX commented 10 months ago

@C0mp4ct thank you for your example, I've added it to the documentation: https://github.com/TrafeX/docker-php-nginx/blob/master/docs/xdebug-support.md