Skip to content

Instantly share code, notes, and snippets.

@DominikStyp
Last active November 23, 2023 14:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DominikStyp/f9604549097f22ab16d66cdaef758ed7 to your computer and use it in GitHub Desktop.
Save DominikStyp/f9604549097f22ab16d66cdaef758ed7 to your computer and use it in GitHub Desktop.
Docker: Install xdebug for PHP 7.4
version: '3'
services:
php:
build:
context: ./docker/8.2
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-8.2/app
extra_hosts:
- 'host.docker.internal:host-gateway'
ports:
- '${APP_PORT:-80}:80'
- '${VITE_PORT:-5173}:${VITE_PORT:-5173}'
environment:
WWWUSER: '${WWWUSER}'
LARAVEL_SAIL: 1
XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
volumes:
- '.:/var/www/html'
networks:
- sail
volumes:
- "./etc/php/dev/php.ini:/usr/local/etc/php/conf.d/dev.php.ini"
# install xdebug
# xdebug and PHP config in php.ini
RUN pecl install xdebug-3.1.3
RUN docker-php-ext-enable xdebug
[xdebug]
xdebug.remote_enable=on
xdebug.profiler_enable=true
xdebug.remote_autostart=true
xdebug.idekey=PHPSTORM
# if you enable remote_connect back you can have problems from making requests from inside the docker container
# because xdebug will try to connect to the docker host instead of your host where PHPStorm listens
xdebug.remote_connect_back=false
xdebug.remote_port=9003
# !!! THIS IS REALLY IMPORTANT to be correct, otherwise xdebug won't work in cli !!!
# IP can be fetched via:
# 1) ifconfig | grep -A 4 docker0
# 2) netstat -nr | grep '^0\.0\.0\.0' | awk '{print $2}'
# 3) route -n | grep 'UG[ \t]' | awk '{print $2}'
xdebug.remote_host=host.docker.internal
xdebug.remote_mode=req
# to enable the xdebug logs
# xdebug.remote_log="/var/www/html/log/xdebug.log"
[xdebug]
xdebug.mode=develop,debug
xdebug.discover_client_host=1
xdebug.client_port=9003
xdebug.start_with_request=yes
xdebug.connect_timeout_ms=2000
# !!! THIS IS REALLY IMPORTANT to be correct, otherwise xdebug won't work in cli !!!
# IP can be fetched via:
# 1) ifconfig | grep -A 4 docker0
# 2) netstat -nr | grep '^0\.0\.0\.0' | awk '{print $2}'
# 3) route -n | grep 'UG[ \t]' | awk '{print $2}'
xdebug.client_host=host.docker.internal
# to enable the xdebug logs
# xdebug.remote_log="/var/www/html/log/xdebug.log"
@DominikStyp
Copy link
Author

DominikStyp commented Oct 19, 2022

Docker host IP: 172.17.0.1 is coming from ifconfig output, which should be in place of docker0
Check out: ifconfig | grep -A 4 docker0

docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        inet6 fe80::42:7aff:fece:4ea5  prefixlen 64  scopeid 0x20<link>
        ether 02:42:7a:ce:4e:a5  txqueuelen 0  (Ethernet)
        RX packets 312508  bytes 12962319 (12.9 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 516999  bytes 1065088042 (1.0 GB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment