1、本地安裝環境為docker作為PHP Web環境
2、php72 容器已經安裝好了xdebug擴展
3、php.ini 配置文件(PHP7.2映射配置)
[XDebug]
xdebug.remote_enable = 1
xdebug.remote_handler = "dbgp"
; Set to host.docker.internal on Mac and Windows, otherwise, set to host real ip
xdebug.remote_host = host.docker.internal
xdebug.remote_port = 9000
xdebug.remote_log = /var/log/php/xdebug.log
4、安裝Visual Studio Code php-debug 擴展
5、配置Visual Studio Code debug 配置文件
{
"version": "0.2.0",
"configurations": [
{
"name": "Xdebug for Project mytest",
"type": "php",
"request": "launch",
"port": 9000,
"pathMappings": {
"/var/www/wiot.tinywan.com": "${workspaceFolder}"
}
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
注意!!!:
(1)"${workspaceFolder}" 為當前VS Code打開的目錄(實際的編輯器打開的目錄路徑)
(2)"/var/www/wiot.tinywan.com" 為Docker容器的映射目錄(容器中的目錄)
6、編寫代碼,開啟debug調試
(1) Visual Studio Code debug
(3)編寫代碼,這里直接在Tp5框架新建一個控制器和方法,同時設置斷點
7、開始調試
(1)瀏覽器訪問該地址http://127.0.0.1/index/test/demo,會激活當前的Visual Studio Code編輯器
(2)查看定位信息
(3)安裝F5開始調試
很清楚的看到調試信息
結束!!!