4
3

More than 5 years have passed since last update.

PhpStormからDocker for Windows上のコンテナでXdebugのリモートデバッグをする

Last updated at Posted at 2018-08-01

はじめに

ブレークポイントが使いたいだけの人生だった。

Xdebug入りのコンテナイメージ準備

公式のphp:7.1-apache をベースに下記のDockerfileを用意

Dockerfile
FROM php:7.1-apache
RUN pecl install xdebug-2.7.0alpha1
RUN docker-php-ext-enable xdebug
RUN echo 'xdebug.remote_enable = 1\n\
xdebug.idekey = "PHPSTORM"\n\
xdebug.remote_host = [ローカルPCのIP]\n\
xdebug.remote_autostart = 1\n\
xdebug.remote_connect_back = 0' >> /usr/local/etc/php/php.ini

Docker Composer向けのYAML準備

無くても問題無いがDockerfileを用意したので合わせて用意

docker-compose.yml
version: '3'
services:
  app:
    build: .
    volumes:
      - "./../:/var/www/html"
    ports:
      - "8080:80"

ディレクトリ構成

こんなイメージ

docker-compose up -d でコンテナを起動する。

PhpStormの設定

下記のXdebugとDBGp Proxyのポートを9000に設定し、IDE Keyはphp.iniで設定した物を指定する。

2018-08-01_23h34_08.png

2018-08-01_23h34_44.png

ブレークポイントを設定してブラウザからアクセス

2018-08-01_23h41_08.png

ブレークポイントが使える人生になった。

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3