VScdoe斷點調試php

環境:MAC + nginx(brew安裝) +mysql5.7 +php7.2(brew安裝)php

一、安裝XDebug擴展大多數人遇到的一個問題就是如何找對本身環境php匹配的XDebug版本,這個問題主要分紅兩個步驟:
(1)查找版本(google下) (2)下載對應版本https://xdebug.org/download.phpmysql

二、配置php.ini文件的XDebug模塊
好了,完成步驟1,如今只須要再配置一下XDebug模塊就安裝完成了
XDebug主要配置的有下面的配置,固然你也能夠另外添加更多的XDebug配置nginx

[XDebug]
zend_extension = /usr/local/lib/php/pecl/20170718/xdebug.so     ; 若是步驟1的第二個小步驟沒進行的話,這裏就要填全路徑了
xdebug.remote_enable = 1    ;開啓遠程調試功能
xdebug.remote_autostart = 1    ;這個配置是比較重要的一個配置
xdebug.remote_handler = "dbgp"
xdebug.remote_port = "9001"   ;端口號,默認是9000,個人9000被佔用!
xdebug.remote_host = "127.0.0.1" ;遠程調試的ip地址,即你本身的本機ip
在配置xdebug.remote_autostart = 1時這裏遇到一個坑,就是XDebug的默認端口號是9000.若是不配置端口號使用默認端口號就會和nginx的端口號衝突,因此下面要配置一下端口號爲9001,要否則會致使調試的時候假死的狀況

配置完上面的配置,而後重啓環境,而後再打印出phpinfo()的信息,而後搜索一下XDebug是否存在,若是存在那麼就安裝成功了。

三、vscode中安裝插件: php debug,安裝完而後去到調試頁面,配置一下json文件,這裏記得端口號要對應上面XDebug的9001端口:sql

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9001
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9001
}
]
}json

四、而後客戶端打開對應的網頁,好比:http://127.0.0.1:8080/site.phpphp7

五、在site.php中打好斷點,而後運行Listen for xdebug,刷新網頁便可追蹤到斷點對應的代碼行ide

相關文章
相關標籤/搜索