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

VSCodeでPHPをデバッグできる環境の設定方法

1
Last updated at Posted at 2026-06-27

VSCodeでPHPをデバッグできる設定で実際の操作手順の備忘録

前提

  • OSはWindows11(バージョン25H2)
    image.png

  • VSCodeエディタがインストール済(1.126.0)
    image.png

  • XAMPPがCドライブ直下にインストール済(v3.3.0/PHP8.2.12)

  • DocumentRootが"C:\xampp\htdocs"である

操作手順

  1. VSCode設定ファイル(settings.json)の編集
  2. VSCode拡張機能「PHP Debug」のインストール
  3. PHPデバッグツール「XDebug」のインストール
  4. 「XDebug」とPHPを関連付け
  5. デバッグを行う

1. VSCode設定ファイル(settings.json)の編集

VSCodeのコマンドパレット(CTRL+Shift+P)を開き"settings.json"と打ちEnter
image.png
settings.jsonが開くので以下の例のように編集する

{
    "files.autoSave": "afterDelay",
    "php.debug.executablePath": "C:\\xamp\\php\\php.exe"
}

2. VSCode拡張機能「PHP Debug」のインストール

VSCodeの拡張機能(CTRL+Shift+x)を開き"PHP Debug"と打つ
"PHP Debug"がリストに現れたらそれを選択してインストールをクリック
ボタンが「アンインストール」に変わったらインストール完了
image.png

3. PHPデバッグツール「XDebug」のインストール

1)PHP詳細情報(phpinfo)を表示

C:\xampp\htdocs配下にphpinfo.phpというファイルを作り、その中身に以下のPHPコードを記載する

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

XAMPPを起動してApacheをスタートして
image.png

ブラウザを開いてアドレスバーに

http://localhost/phpinfo.php

と打ってEnter
現在動作しているPHPの詳細情報が表示されるので、この画面の文字をすべてコピーする(画面の適当な場所でクリックしたのち全選択(CTRL+a)してコピー(CTRL+c)する)
image.png

2)「XDebug」のDLLファイル生成

ブラウザでhttps://xdebug.org/wizard.php を開き、先ほどコピーした文字をテキストボックスに貼り付け、
image.png
「Analyse my phpinfo() output」ボタンをクリックし、表示されたDLLファイルをダウンロード。
image.png

ダウンロードしたDLLファイルを"C:\xampp\php\ext"に移動する

4. 「XDebug」とPHPを関連付け

XAMPPのApache行のconfigボタンをクリックしてphp.iniを開く
[PHP]に追記する

php.ini
[PHP]
....
;zend_extension=opcache
xdebug.mode=debug
xdebug.start_with_request=yes

[XDebug]をファイル末尾に追加する

php.ini
[XDebug]
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 1
xdebug.remote_port = 9003
zend_extension = "php_xdebug-3.5.3-8.2-ts-vs16-x86_64.dll"

5. デバッグを行う

VSCodeの実行とデバッグ(CTRL+Shift+D)を開く
デバッグ開始の右リストから"Listen for Xdebug"が選択されていることを確認して
デバッグ開始ボタンをクリックする

image.png

プログラムコードの左側番号でブレイクポイントにしたい箇所をクリックする

image.png

処理を実行させてブレイクポイントで停止すれば成功!!

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?