6
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

dockerのPHPでxdebugを使ってみる

Posted at

概要

xdebugをdocker環境で使えるようにしたかったので調べてみた。

Dockerを準備する

作ったコードは、下記githubにまとめているので大雑把に書きます。
※ Github: https://github.com/reflet/php5.6-xdebug

docker/httpd/Dockerfile
FROM php:5.6-apache

# install xdebug
RUN pecl install xdebug-2.5.5 && docker-php-ext-enable xdebug

# update php.ini
COPY ./php.ini /usr/local/etc/php/php.ini

WORKDIR /var/www/html

php.iniの設定

下記の設定を追加する。

docker/httpd/php.ini
[xdebug]
xdebug.idekey="PHPStorm"
xdebug.remote_host = "docker.for.mac.host.internal"
xdebug.default_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 0
xdebug.remote_enable = 1
xdebug.remote_handler = "dbgp"
xdebug.remote_port = 9000

docker-compose.yml

dockerの構成を記述します。

docker-compose.yml
version: "3.7"
services:
   httpd:
     container_name: httpd
     image: httpd:development
     build:
       context: ./docker/httpd
       dockerfile: Dockerfile
     ports:
       - "80:80"
     volumes:
       - ./src:/var/www

サーバ起動

下記コマンドでサーバを起動します。

ターミナル
$ docker-compose build
$ docker-compose up -d

IDE設定 (IntelliJ)

お使いのIDEで9000番ポートを指定する。

  • Preferences > Languages & Frameworks > PHP > Debug
    debug.png

  • Preferences > Languages & Frameworks > PHP > Servers
    server.png

  • edit-configurationsボタン
    edit-configurations.png

  • configurations設定
    configurations.png

  • 実行してみる
    run.png

以上

参考サイト

6
12
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
6
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?