LoginSignup
4
3

More than 3 years have passed since last update.

LaravelのDockerでX-debugを有効にする

Last updated at Posted at 2020-01-22

Enable X-debug on Docker for Laravel


始める前に

dockerを使用してx-debugを設定するさまざまな方法に関するチュートリアルがたくさんあります。一部は時代遅れで、一部は他のテクニックを使用します。

Before starting

There are a lot of tutorials on different ways to configure x-debug using docker, some are outdated, some use other techniques, this tutorial is on the configuration that works for me, but I don´t guarantee that it will work for you.


APIの作成方法の前のチュートリアルに従ってください

Follow previous tutorial on how to make an API

nginx.confを編集します

nginx.confファイルにはserver_nameが必要です

the nginx.conf file needs a server_name

server {
  listen 80;
  server_name localhost;
Dockerfileを編集

Dockerfileを編集して、x-debugプラグインのインストールを追加し、docker-pluginを有効にします

Edit the Dockerfile to add x-debug plugin install and enable the docker-plugin

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

#COPY xdebug.ini /etc/php/7.3/mods-available/xdebug.ini
RUN echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
     && echo "xdebug.remote_autostart=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
     && echo "xdebug.remote_connect_back = 1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
     && echo "xdebug.profiler_enable = 1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
     && echo "xdebug.remote_port=9000" >>  /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
docker-compose.yml編集

app-serverコンテナ内のdocker-composeファイルでx-debugを有効にします

Enable x-debug on docker-compose file, in the app-server container

services:
  app-server:
    build: .cloud/docker
    image: laravel-api #name of the image
    environment:
      PHP_XDEBUG_ENABLED: 1
    depends_on:
PHP Stormを構成する

PHP設定内で、プロパティを次のように設定します。

Inside the PHP settings, set the properties as follow

サーバーをセットアップする

右上のメニューから新しい構成をセットアップします

Setup a new configuration, from the upper right menu

次のウィンドウで、セットアップ新しいPHPのウェブサイト、左上隅からの+記号をクリックして、

In the next window, setup a new PHP web site, by clickin the + sign from the upper left corner

サーバーリストから[...]ボタンをクリックして、新しいサーバーを作成します。

create a new server, by clicking the [...] button from the server list.

localhostアドレスを追加し、プロジェクトをdockerサーバー(この場合は/ applicationディレクトリ)にマップします。

Add the localhost address, and map the project to the docker server, in our case, the /application directory.

これにより、PHPStormで受信したリクエストをデバッグできます。

With this, you will be able to debug incoming request on PHPStorm.

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