LoginSignup
1
1

More than 3 years have passed since last update.

Xdebug のインストール PHP デバッグ Mac Big Sur

Last updated at Posted at 2021-05-12

Xdeubgのインストールにとてつもなく膨大な時間を費やした。

環境

  • mac OS Big Sur バージョン 11.3.1
$ brew list | grep php

php@7.4
phpmyadmin

結論

↓どおりにインストールしてエラーを解決しながらやっていくと、Xdebugをインストールできた。

Homebrew で php7.4 + Xdebug をインストール

しかし、peclでのインストールにおいてエラー発生。

pecl install xdebug
・・・エラー省略。
asm goto' constructs are not supported yet

これは、↓曰く
Command Line Tools for xcode (CLT)のバージョンの問題らしい。

https://bugs.php.net/bug.php?id=80939&edit=1

↓で確かめてみると

$ clang --version

Apple clang version 11.0.0 (clang-1100.0.33.17)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

そこで、
CLTのアップデートを行った。
ちなみに、CLTには2種類あって①システムにインストールされているCLT
②Xcodeのパッケージに埋め込まれているCLT
があるとのこと。

brew upgrade でのエラー対処からCommand Line Toolsについてまとめてみる

アップデート方法は↑の記事に書かれている通り。
一度システムにインストールされているのCLTを削除。再度インストール。

$ sudo rm -rf /Library/Developer/CommandLineTools
$ sudo xcode-select --install

晴れて、バージョンアップに成功。

$clang --version

Apple clang version 12.0.5 (clang-1205.0.22.9)
Target: x86_64-apple-darwin20.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

再度、peclでxdebugをインストールすると、成功。

$ pecl install xdebug

・・・
Build process completed successfully
Installing '/usr/local/Cellar/php@7.4/7.4.19/pecl/20190902/xdebug.so'
install ok: channel://pecl.php.net/xdebug-3.0.4
Extension xdebug enabled in php.ini

Installing '/usr/local/Cellar/php@7.4/7.4.19/pecl/20190902/xdebug.so'

の部分をメモって、php.iniに書く。

php.iniの探し方↓

$ /usr/local/opt/php@7.4/bin/php -r "echo phpinfo();" | grep "php.ini"
php.ini
zend_extension="/usr/local/Cellar/php@7.4/7.4.19/pecl/20190902/xdebug.so"

これでやっとVSCodeでのPHPをデバッグできる。

と思ったら、VSCodeでデバッグ開始しても、ブレークポイントで止まらない。
そこで、VSCodeのextensionでインストールしたPHP Debugのドキュメントを見てみると
スクリーンショット 0003-05-13 7.53.59.png

There are other ways to tell Xdebug to connect to a remote debugger, like cookies, query parameters or browser extensions. I recommend remote_autostart (Xdebug v2)/start_with_request (Xdebug v3) because it "just works". There are also a variety of other options, like the port, please see the Xdebug documentation on remote debugging for more information. Please note that the default Xdebug port changed between Xdebug v2 to v3 from 9000 to 9003. The extension still defaults to 9000, so make sure your configuration in launch.json and php.ini match.

つまり、「Xdebugのバージョンに合わせて書け」とのこと。(意訳)
あと、「Xdebugのバージョンv2からv3に合わせてポート番号が9000から9003に変わった。launch.jsonとphp.ini確かめろよ」とのこと。

筆者の場合だと以下を追記するとブレークポイントで止まるようになった。

php.ini
zend_extension="/usr/local/Cellar/php@7.4/7.4.19/pecl/20190902/xdebug.so"

[PHP]
xdebug.mode = debug
xdebug.start_with_request = yes  ←こいつをonにすることでプレー区ポイントで止まった。
;デフォルトは9003
xdebug.client_port = 9003

追記

ドキュメントに沿ってやってもできる。
https://xdebug.org/wizard

※しかし、ステップ8の、↓は、20190902というフォルダがあることを確かめる必要あり。何も考えずにコマンドを実行していたが、20190902というフォルダが作られていなかった

//20190902というフォルダがあるか確かめる
cp modules/xdebug.so /usr/local/lib/php/pecl/20190902

スクリーンショット 0003-05-15 21.24.08.png

小ネタ

↓のように、画面最下部がオレンジ色で「Launch curreently open script」 ってなっていないと、ブレークポイントを置いてのデバッグはすることはできないので注意。
左サイドバーのデバッグボタンを押して、▷の横を押して、「Listen for xdebug」か「Listen for xdebug」か選択できる。

そのせいで、結構時間を無駄にしたので、要注意。

1
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
1
1