0
1

More than 1 year has passed since last update.

Windows+WSL2+Ubuntu+Docker+PhpStorm で Xdebug 使ったり使わなかったりしたい

Last updated at Posted at 2021-11-11

本番環境、Localの開発環境。LocalでXdebug使いたいときなどなど。環境を切り替えてテストしたりコーディングしたり等などしたいという欲望

Dockerfile
#全共通なを記述
FROM php:8.0-fpm as production
RUN apt-get update \
    && apt-get install -y curl zip ....
#以下略

#上記の全共通に追加でLocalのみを記述
FROM production as local
RUN apt-get update \
    && apt-get install -y vim procps \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# local環境に追記でXdebugを使いたい
FROM local as xdebug
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
COPY conf/conf.d/xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini
RUN pecl install xdebug \
    && docker-php-ext-enable xdebug.so \
    && echo "xdebug.idekey = PHPSTORM" >> $PHP_INI_DIR/conf.d/xdebug.ini \
    && ....
    # 以下略

Targetの指定を変更することで、すきなときにすきなように環境をbuildできて幸せになれる
target: production
target: local
target: xdebug

docker-compose.yml
  php-fpm:
    container_name: xxx.php-fpm
    build:
      context: ../docker/php-fpm
      target: local  # production|local|xdebug
    image: xxx/php-fpm
    volumes:
      - ../src:/var/www:cached
    environment:
      TZ: "Asia/Tokyo"
      LOG_CHANNEL: 'stack'
    networks:
      - backend
conf/conf.d/xdebug.ini
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_host=host.docker.internal
xdebug.client_port=9003
xdebug.log=/var/log/xdebug.log
xdebug.start_upon_error=yes
xdebug.discover_client_host=false

あとはお好きなように...

$ docker-compose up -d --build
0
1
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
0
1