Skip to content

Instantly share code, notes, and snippets.

@ssi-anik
Created July 18, 2021 09:16
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssi-anik/fbd5e1c52bfb925c6eb316bece2d9431 to your computer and use it in GitHub Desktop.
Save ssi-anik/fbd5e1c52bfb925c6eb316bece2d9431 to your computer and use it in GitHub Desktop.
xdebug 3, docker integrate with PhpStorm
version: '3.8'
services:
nginx:
image: nginx:1.13.6
ports:
- 8989:80
volumes:
- .:/var/www/html
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
links:
- php
php:
build:
context: .
dockerfile: ./docker/php/Dockerfile
args:
# Available [trace|debug|profile]. Use Comma separated available values for multiple mode
# Use "off" to disable xdebug
#- XDEBUG_MODES=debug,trace
- XDEBUG_MODES=off
# Set the following values to overwrite the existing settings.
# Uncomment the following line and change value.
- REMOTE_HOST=host.docker.internal # Host machine IP
- REMOTE_PORT=9003 # IDE/Editor's listener port
- IDE_KEY=docker # IDE's filter/listener key
volumes:
- .:/var/www/html
# Use sudo if required.
# RUN: mkdir -p /tmp/xdebug
# RUN: chmod -R 777 /tmp/xdebug
# Log files will be written in this directory
- /tmp/xdebug:/tmp/xdebug
FROM sirajul/php74-fpm:latest
RUN pecl install xdebug
#RUN docker-php-ext-enable xdebug
RUN mkdir -p /home/xdebug
COPY ./docker/php/xdebug-debug.ini /home/xdebug/xdebug-debug.ini
COPY ./docker/php/xdebug-default.ini /home/xdebug/xdebug-default.ini
COPY ./docker/php/xdebug-off.ini /home/xdebug/xdebug-off.ini
COPY ./docker/php/xdebug-profile.ini /home/xdebug/xdebug-profile.ini
COPY ./docker/php/xdebug-trace.ini /home/xdebug/xdebug-trace.ini
ARG XDEBUG_MODES
ARG REMOTE_HOST="host.docker.internal"
ARG REMOTE_PORT=9003
ARG IDE_KEY="docker"
ENV MODES=$XDEBUG_MODES
ENV CLIENT_HOST=$REMOTE_HOST
ENV CLIENT_PORT=$REMOTE_PORT
ENV IDEKEY=$IDE_KEY
COPY ./docker/php/fpm-entrypoint.sh /home/fpm-entrypoint
RUN chmod +x /home/fpm-entrypoint
WORKDIR /var/www/html
ENTRYPOINT ["/home/fpm-entrypoint"]
#!/usr/bin/env bash
set -e
echo "Copying default XDEBUG ini"
cp /home/xdebug/xdebug-default.ini /usr/local/etc/php/conf.d/xdebug.ini
if [[ $MODES == *"profile"* ]]; then
echo "Appending profile ini"
cat /home/xdebug/xdebug-profile.ini >> /usr/local/etc/php/conf.d/xdebug.ini
fi
if [[ $MODES == *"debug"* ]]; then
echo "Appending debug ini"
cat /home/xdebug/xdebug-debug.ini >> /usr/local/etc/php/conf.d/xdebug.ini
echo "Setting Client Host to: $CLIENT_HOST"
sed -i -e 's/xdebug.client_host = localhost/xdebug.client_host = '"${CLIENT_HOST}"'/g' /usr/local/etc/php/conf.d/xdebug.ini
echo "Setting Client Port to: $CLIENT_PORT"
sed -i -e 's/xdebug.client_port = 9003/xdebug.client_port = '"${CLIENT_PORT}"'/g' /usr/local/etc/php/conf.d/xdebug.ini
echo "Setting IDE Key to: $IDEKEY"
sed -i -e 's/xdebug.idekey = docker/xdebug.idekey = '"${IDEKEY}"'/g' /usr/local/etc/php/conf.d/xdebug.ini
fi
if [[ $MODES == *"trace"* ]]; then
echo "Appending trace ini"
cat /home/xdebug/xdebug-trace.ini >> /usr/local/etc/php/conf.d/xdebug.ini
fi
if [[ "off" == $MODES || -z $MODES ]]; then
echo "Disabling XDEBUG";
cp /home/xdebug/xdebug-off.ini /usr/local/etc/php/conf.d/xdebug.ini
else
echo "Setting XDEBUG mode: $MODES"
echo "xdebug.mode = $MODES" >> /usr/local/etc/php/conf.d/xdebug.ini
fi;
php-fpm
; Remote debugging
xdebug.client_host = localhost
xdebug.client_port = 9003
xdebug.discover_client_host = false
xdebug.idekey = docker
[xdebug]
zend_extension = xdebug.so
xdebug.cli_color = 1
xdebug.start_with_request = yes
xdebug.output_dir = "/tmp/xdebug"
xdebug.log = "/tmp/xdebug/xdebug-log.log"
[xdebug]
zend_extension = xdebug.so
xdebug.mode = off
; Profiler
xdebug.profiler_output_name = cachegrind.out.%c-%t
; Trace
xdebug.trace_output_name = "trace.%c-%t"
xdebug.trace_format = 0
xdebug.collect_return = true
xdebug.trace_options = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment