4
3

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 5 years have passed since last update.

NAT接続のVMへVSCodeからリモートデバッグ

4
Posted at

NAT接続したVM上のCentOSで動くPHPのWebアプリケーションをxdebugでホストOSからリモートデバッグする、
というちょっと面倒なことをしようとしたところ、案外(?)うまくいかなかったのでメモ。

環境

  • ホスト: Windows8.1
  • ゲスト: CentOS6.4

ホスト側準備

VirtualBox

  • ネットワーク設定
    • NAT
    • xdebugのポート(9000)は ポートフォワードしない
  • 共有フォルダ設定
    • ホスト側でソースを編集したいので

VSCode

  • 拡張機能
  • launch.json 編集(pathMappingsの部分)
launch.json
{
"version": "0.2.0",
  "configurations": [
    {
      // 基本的にはデフォルトのままで大丈夫
      "name": "Listen for XDebug",
      "type": "php",
      "request": "launch",
      "log": true,
      "port": 9000,
      "pathMappings": {
         "{ゲストOS上のパス}" : "${workspaceRoot}"
      }
    }
  ]
}

ゲスト側準備

xdebug

  • インストール
    • sudo yum -y install php-pecl-xdebug --enablerepo=epel
    • リポジトリの設定などは他のサイトを参考に
  • 設定
/etc/php.d/xdebug.ini
xdebug.remote_autostart=1
xdebug.remote_enable=1
xdebug.remote_host=192.168.xx.xx #ホストOSのWAN側IPアドレス
xdebug.remote_port=9000

  • Apache再起動

いざ、デバッグ

  • VSCodeで F5 すると、無事ブレークポイントで止まりました。
4
3
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
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?