LoginSignup
4
7

More than 3 years have passed since last update.

Vagrant + VisualStudioCode + PHPでデバッグ環境構築

Last updated at Posted at 2019-10-15

類似する記事はゴロゴロしてますが仮想環境をかましてるお陰でけっこうハマったので備忘に...
詳しい仕組みはこちらがとても参考になります。

環境

MacOS 10.12.6
VirtualBox 6.0.12
Vagrant 2.2.5
PHP 7.1.32
VSCode 1.38.1
PHP Debug 1.13.0

手順

  • VSCodeにPHP Debugをインストール
  • Vagrant側のXdebugを設定
    • sshでログインし、Xdebugをインストールする
    • 自分の場合、 /etc/php.d/15-xdebug.iniに以下を設定
xdebug.default_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 0 // 無効にする
xdebug.remote_enable = 1
xdebug.remote_host = "10.0.2.2" // VagrantのNATアダプタのデフォルトゲートウェイ
xdebug.remote_port = 9000
  • VSCode側のデバッガの設定
    • vscode/launch.jsonは以下のようにした
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9000,
            "log":true,
            "pathMappings": {
                "/var/www/html/HogeProject": "${workspaceRoot}"  // 左:ゲストOSのパス、右:ホストOSのパス(VSCodeを開いてるプロジェクトルート)を一致させる
            }
        },
        {
            "name": "Launch currently open script",  // こっちは今回関係ない
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9000
        }
    ]
}

以上!

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