Skip to content

Instantly share code, notes, and snippets.

@kdes70
Forked from icqparty/README.md
Created April 6, 2017 11:48
Show Gist options
  • Save kdes70/7e7492ab503d71d37cffd14c6de23d02 to your computer and use it in GitHub Desktop.
Save kdes70/7e7492ab503d71d37cffd14c6de23d02 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!

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

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