【Laravel 5.x】使用 Visual Studio Code + XDebug 在 Vagrant Laravel 進行除錯

安裝Xdebug

  1. Xdebug官網下載
  2. 下載 .dll 時候要注意: PHP版本與XDebug版本都要相同 TS也要選對
  3. 將下載的.dll放到「C:\php-x.x.xx\ext」目錄底下
  4. 設定「php.ini」
    [xdebug]
    zend_extension = "C:\php-7.1.15\ext\php_xdebug-2.6.0-7.1-vc14-x86_64.dll"
    ; 開啟偵錯的堆疊程序的功能,是否需要當然就是因人而異嘍
    xdebug.default_enable = "On"
    ; 針對網頁的偵錯
    xdebug.remote_enable = "On"
    xdebug.remote_autostart = "On"
    ; 除錯的協定,若是php3以前的版本,就請改為"gdb"
    xdebug.remote_handler = "dbgp"
    ; 要除錯的host name或是IP(不用加上埠號)
    xdebug.remote_host = 192.168.123.1
    ; xdebug要用到的埠號
    xdebug.remote_port = 9000
    ; 查錯的資料儲存出來,設定其存放的目錄
    xdebug.trace_output_dir = "C:\errorLog"
  5. enjoy!

設定Visual Studio Code launch.json

在自己要Debug的專案中, 調整專案底下的「launch.json」

{
    "name": "Listen for XDebug on Vagrant/Laravel",
    "type": "php",
    "request": "launch",
    "pathMappings": {
        "/home/vagrant/code/myProject": "${workspaceFolder}"
    },
    "port": 9000
}

接下來就可以開始使用 Visual Studio Code 享用 Debug了!

訂閱
通知
guest
0 留言
預約回饋
查看所有留言