LoginSignup
2
1

More than 1 year has passed since last update.

MacとVS CodeでPHPのデバッグ環境を構築

Last updated at Posted at 2022-08-20

こちらの記事を参考にPHPのデバッグ環境を作成しました。

上記の記事で大体うまくいくのですが、大事な部分を中心にメモ。

動作環境
PC:MacbookPro(2018)
OS: Big Sur(11.6.2)
エディタ:Visual Studio Code
XAMPP(PHP7.4)を使用
ターミナルはzshを使用

xdebugのインストール

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

インストール先(Installing~の後ろ)をメモっておく

/usr/local/Cellar/php@7.4/7.4.30/pecl/20190902/xdebug.so

インストール確認

php -m
中略
>
>
xdebug
>
>
中略

[Zend Modules]
Xdebug
Zend OPcache

PHPの情報をデスクトップに保存

php -i >> ~/Desktop/php_info.txt

php.iniの編集

vi /usr/local/etc/php/7.4/php.ini

インサートモードで記述ができますが、苦手な方はディレクトリ指定してエディタで開いてもOK(自分がそうなので)
その場合はcommand」+「shift」+「.」で隠しファイルを表示させてFinderでHD(デフォルト名はMacintosh HD)からディレクトリを追っていけばファイルがあります。
スクリーンショット 2022-08-20 22.01.41.png

1行目のzend_extension=の後をインストール先(1でメモしたもの)を追記し、[PHP]の後ろに設定を追記

php.ini
zend_extension="/usr/local/Cellar/php@7.4/7.4.30/pecl/20190902/xdebug.so"
[PHP]

xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_mode=req
xdebug.remote_autostart=1

;;;;;;;;;;;;;;;;;;;
; About php.ini   ;
;;;;;;;;;;;;;;;;;;;

省略

phpのバージョン確認にxdebugが表示されるか確認

php -v
Xdebug: [Config] The setting 'xdebug.remote_autostart' has been renamed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-xdebug.remote_autostart (See: https://xdebug.org/docs/errors#CFG-C-CHANGED)
Xdebug: [Config] The setting 'xdebug.remote_enable' has been renamed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-xdebug.remote_enable (See: https://xdebug.org/docs/errors#CFG-C-CHANGED)
Xdebug: [Config] The setting 'xdebug.remote_host' has been renamed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-xdebug.remote_host (See: https://xdebug.org/docs/errors#CFG-C-CHANGED)
Xdebug: [Config] The setting 'xdebug.remote_mode' has been renamed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-xdebug.remote_mode (See: https://xdebug.org/docs/errors#CFG-C-CHANGED)
Xdebug: [Config] The setting 'xdebug.remote_port' has been renamed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-xdebug.remote_port (See: https://xdebug.org/docs/errors#CFG-C-CHANGED)

Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Xdebug v3.1.5, Copyright (c) 2002-2022, by Derick Rethans
    with Zend OPcache v7.4.30, Copyright (c), by Zend Technologies

警告箇所の修正

成功はしていますがこの前に警告文が。

xdebug2⇒xdebug3に伴い、設定項目の名前が変更になったようです。

こちらを参考に変更

こちらがちょっと悩みました。

xdebug.remote_mode
For the req value (the original default), use xdebug.mode=debug with xdebug.start_with_request=trigger. If the original xdebug.remote_autostart behaviour is necessary, use xdebug.start_with_request=yes instead of trigger.

今回はこちらで確定

Before

php.ini
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_mode=req
xdebug.remote_autostart=1

After
xdebug.remote_modeは削除

php.ini
xdebug.mode=debug
xdebug.client_host=localhost
xdebug.client_port=9000
xdebug.start_with_request=yes

エラーはなくなりました。

php -v

PHP 7.4.30 (cli) (built: Jun  9 2022 09:31:00) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Xdebug v3.1.5, Copyright (c) 2002-2022, by Derick Rethans
    with Zend OPcache v7.4.30, Copyright (c), by Zend Technologies

VScodeでデバッグを行う

VS Codeの拡張機能PHP Debugを使用。

JSONファイルの作成の際に環境の選択が表示されるとのことでしたが、表示されずそのまま作成されました。


関連サイト

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