Skip to content

Instantly share code, notes, and snippets.

@icqparty
Forked from chadrien/README.md
Last active October 31, 2017 14:11
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save icqparty/948d0e53c117072484be to your computer and use it in GitHub Desktop.
Save icqparty/948d0e53c117072484be to your computer and use it in GitHub Desktop.
Debug PHP in Docker with PHPStorm and Xdebug

Отладка PHP-приложение c Xdebug в Docker-контейнере через редактор Intellij/PHPStorm

  1. Создайте в локальной дирриктори вашего проекта файл сборки Dockerfile со следующим содержанием:
FROM php:5

RUN yes | pecl install xdebug \
    && echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini \
    && echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/xdebug.ini
  1. Узнайте ваш IP адрес локальной машины (командой ifconfig или другой) у меня он 172.17.0.1
  2. Запустите контейнер с переменной окружения: XDEBUG_CONFIG="remote_host=172.17.0.1"
  • Способ первый через docker : docker run -e XDEBUG_CONFIG="remote_host=172.17.0.1" my-conteiner-php

  • Или через docker-compose:

    # docker-compose.yml
    foo:
      build: path/to/Dockerfile
      environment:
        XDEBUG_CONFIG: remote_host=172.17.0.1
  1. Зайдите в настройки Intellij/PHPStorm : Languages & Frameworks > PHP > Debug > DBGp Proxy и укажите соответвующие параметры:
  • Host: 172.17.0.1
  • Port: 9000

Then you're all set and can start listening for PHP Debug connections from your IDE. On the first run it will ask you to map your local directoryies to the docker directories, but after that nothing will be required anymore!

Удачной отладки!

@martinbutt
Copy link

If you are using docker-machine with VirtualBox, you can skip step two and just use

XDEBUG_CONFIG: "remote_host=10.0.2.2"

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