LoginSignup
2
3

More than 5 years have passed since last update.

PHPのビルドインサーバーを使ったデバッグ(Atom x Xdebug)

Last updated at Posted at 2018-02-10

はじめまして。

数年のブランクを経てWebエンジニアの世界へ戻ることになりました。これを期に、見てるだけだったQiitaも使ってみようと思い、練習がてら。

前提条件

  • OS: macOS HighSierra
  • PHP: 7.0.27
  • Laravel: 5.5.24
  • エディタ: Atom 1.23.3

用意したもの

  • Xdebug

Homebrewでインストールしました。

$ brew install php70-xdebug
  • PHP-debug

AtomにPHP-debugをインストールしました。

Atom - PHP-debug
https://atom.io/packages/php-debug

Xdebugの設定

homebrewでインストールされたxdebugの設定ファイルはここ。

/usr/local/etc/php/7.0/conf.d/ext-xdebug.ini 

PHP-debugの説明の通り修正します。

[xdebug]
zend_extension="/usr/local/opt/php70-xdebug/xdebug.so"
#ここは環境やバージョンに応じて変化すると思います。
xdebug.remote_enable=1
xdebug.remote_host=127.0.0.1
xdebug.remote_connect_back=1
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_autostart=true

PHP-debugの設定

AtomのConfigファイルconfig.csonに下記を追記。

"php-debug":
  {
    ServerPort: 9000
    ServerAddress: "127.0.0.1"
  }

今回はリモートデバッグしないのでPath Mapは書きませんでした。

これでAtomの左下に追加されたPHP Debugってボタンをクリックするとデバッグウィンドウが表示されます。

適当にソースコードへブレイクポイントを仕掛けます。行番号の右側のをクリックすると、$\style{color:blue;}{\text{●}}$が表示され、ブレイクポイントが設定されました。

この状態でビルドインサーバーを起動。

$ php artisan serve

で、127.0.0.1:8000/****へアクセスします。ちゃんと止まります。うまくいきました。Xdebugがリッスンするポートとサーバーのポートは別でOKです(ここでちょっとハマった)。

未解決事象

しかし、何度かやっているうちにビルドインサーバーへアクセスするとLaravelのserver.phpが固まってしまう現象に直面。このときは、プロセス一覧からIDを見つけてkillして対応。

$ ps -rf | grep laravel

  501 20235 20226   0 11:14AM ttys000    0:00.00 grep laravel
  501 20221 20217   0 11:14AM ttys003    0:00.04 /usr/local/Cellar/php70/7.0.27_19/bin/php -S 127.0.0.1:8000 /Users/akagire/dev/laravel/server.php

$ kill 20221
#プロセスIDは時と共にに変化します...

結果的にはconfigに追記したphp-debugの設定を削除でうまくいきました。理由がわからないので気持ち悪いですが、今のところなんとか動いています。

2
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
2
3