2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Laravel】Xdebugを導入する(mac × MAMP)

Last updated at Posted at 2021-09-07

VSCodeの拡張機能のインストール

PHP Debugをインストールする。
(VSCoedeの拡張機能のところで、felixfbecker.php-debugと検索)

Xdebugのインストールと設定

macのMAMPにはXebugがデフォルトでインストールされれている。

Xdebugがインストールされているか確認する方法

適当なファイル(例:phpinfo.php)を作成し、以下のように記述する。

phpinfo.php
<?php
phpinfo();
?>

このページをブラウザで開き、Xdebugの記述があればインストールされている。
Xdebugについての記述が無い場合は、インストールを行う。

Xdebugのインストール方法(Xdebug3の場合)

  1. Xdebug Wizardを開く。
    https://xdebug.org/wizard

  2. 先ほどのブラウザに表示されたphpinfoを全てコピーし、Xdebug Wizardのテキスト欄に貼り付ける。

  3. 「Analyse my phpinfo() output」をクリック。

  4. InstructionsのところにダウンロードするべきXdebugが表示されるので、リンクをクリックしてダウンロードする。

  5. Instructionの「2. Move the downloaded file to ~~~~」のパスをコピーし、エクスプローラーを開いて貼り付け、このパスまで移動する。ここに、4.でダウンロードしたファイルをドラッグ&ドロップする。

  6. Instructionの「3. Edit ~~~~」のパスを辿り、php.iniを開く。「add the line」以下の「zend_extension = 」をphp.iniの一番下に追記する。(xdebug.mode=debugにしておく)

  7. サーバーを再起動し、phpinfoを開いてXdebugの記述があるか確認する。

インストール済みの場合の設定方法

  1. phpinfoの「Configuration File (php.ini) Pathのconfの前までをコピー。Finderでこのパスまで移動する。/lib/php/extensions/no-debug~~/xdebug.so この「xdebug.so」が対象のファイルなので、このファイルまでのフルパスをコピーする。

  2. phpinfoの「Configuration File (php.ini) Pathのconf/php.iniに、[Xdebug]の設定を追記する。

//Xdebug ver3の場合

[XDebug]
xdebug.mode=debug,develop,trace
xdebug.start_with_request = yes
zend_extension = C:\MAMP\bin\php\php7.4.1\ext\php_xdebug-3.0.0-7.4-vc15.dll

※zend_extensionはXdebug Wizardでコピーした値


//Xdebug ver2、またはMacの場合

[XDebug]
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_port = 9010    
zend_extension = C:\MAMP\bin\php\php7.4.1\ext\php_xdebug-2.0.0-7.4-vc15.dll

※Windowsの場合:zend_extensionはXdebug Wizardでコピーした値
※Macの場合:xdebug.soまでのパス

3.サーバーを再起動して、設定を反映させる。

VSCodeの設定

  1. デバッグの設定(サイドバーの虫のアイコン)より、「launch.json ファイルを作成します。」をクリック。「PHP」を選択する。

  2. .vscode/launch.jsonが作成されるので、以下の通り編集する。これより下は不要なので削除する。

.vscode/launch.json.php
{
  // IntelliSense を使用して利用可能な属性を学べます。
  // 既存の属性の説明をホバーして表示します。
  // 詳細情報は次を確認してください: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Listen for Xdebug",
      "type": "php",
      "request": "launch",
      "port": 9010,
                    //php.iniのポートと同じに。
      "stopOnEntry": true
    },
  ]
}

PHPのワーニングを画面表示する

※ワーニングエラーも、開発環境では確認できる方がよいので。

  1. php.iniを開き、「display_errors」と検索する。
  2. 「display_errors = On」に変更する。
  3. サーバーを再起動して、設定を反映させる。
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?