arrow_back
Back

Enable Xdebug in Docker and PHP containers

Andrew Dorokhov Andrew Dorokhov schedule 1 min read
menu_book Table of Contents

Add to the Dockerfile:

RUN echo "xdebug.client_port=9000" > /usr/local/etc/php/conf.d/xdebug.ini && \
    echo "xdebug.idekey=PHPStorm" >> /usr/local/etc/php/conf.d/xdebug.ini && \
    echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/xdebug.ini && \
    echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/xdebug.ini && \
    echo "xdebug.client_host=172.26.0.3" >> /usr/local/etc/php/conf.d/xdebug.ini

Example docker-compose.yml:

version: '2.4'
services:
  app:
    container_name: excavo.telegram.app
    build: .
    ports:
    - "80:80"
    environment:
      PHP_ENABLE_XDEBUG: 1
    volumes:
      - .:/app
      - /app/vendor/
  db:
    container_name: excavo.telegram.db
    image: mysql:5.7.29
    restart: always
    command: mysqld --sql_mode=""
    environment:
      MYSQL_DATABASE: excavo.telegram
      MYSQL_USER: excavo.telegram
      MYSQL_PASSWORD: p^DK@6*7UoiF
      MYSQL_RANDOM_ROOT_PASSWORD: 1
    volumes:
      - excavo.telegram:/var/lib/mysql
volumes:
  excavo.telegram:
    name: excavo.telegram

Set xdebug.client_host to an address your IDE can reach (often the Docker host gateway IP, not a hard-coded container IP).

IDE path mapping

Map project paths in your IDE so breakpoints resolve correctly.

  • Map /controllers and other app directories explicitly.
  • If files under vendor/ are missing, check include paths in the IDE mapping dialog.
  • Prefer mapping whole directories instead of individual files.
code

Need Help with Development?

Happy to help — reach out via the contacts or go straight to my Upwork profile.

work View Upwork Profile arrow_forward
Next Article

Docker volumes: declare, mount, and share data

arrow_forward