PHP vscode+XDebug 遠程斷點調試服務器上的代碼

參考連接php

http://www.javashuo.com/article/p-nkcnmrcg-n.htmlhtml

斷斷續續作php五年了,前期只在開發機器上debug,中期從不debug,有什麼問題var_dump一下,如今遇到一個fpdf的問題,無奈必須debug服務器。web

我只是記錄一下本身遇到的問題,基本徹底按照原文思路來。json

 

環境介紹:
本地:win7 + vscode
遠程:CentOS + Apache + PHP5.6 + xdebug 服務器

 

PHP的運行環境在遠程服務器中,項目代碼放在本地,使用nfs共享映射到虛擬機中運行。ssh

1.ssh到虛擬機,檢查並安裝php的xdebug擴展ide

2.配置php.ini中的xdebug函數

zend_extension=xdebug.so
[XDebug]
xdebug.remote_enable = on
xdebug.remote_autostart = 1
;xdebug.remote_host = 192.168.10.1
xdebug.remote_port = 9000
xdebug.remote_connect_back = 1
xdebug.auto_trace = 1
xdebug.collect_includes = 1
xdebug.collect_params = 1
xdebug.remote_log = /tmp/xdebug.log

「remote_enable」是容許遠程調試
「remote_autostart」遠程調試自動啓動?
「remote_host」是指定經過哪一個IP進行遠程調試,也就是你IDE所在的IP(這裏是192.168.10.1便是我本地,但當下面remote_connect_back設置了時,這個IP設置無效,因此我註釋了),
「remote_port」是在vscode中設置的監聽端口,是本地的端口哦~ 即當開始調試時,xdebug將與這個端口通信
「remote_connect_back」不知道是什麼意思,只是若是開啓此,將忽略上面的 xdebug.remote_host 的設置
其它的可自行搜索xdebug配置說明。 php-fpm

這裏因爲我使用的是寶塔,全部直接打出phpinfo spa

QQ截圖20190613002648

發現真的有好幾個不符合要求,因而將參考連接中的配置所有放了進去

2

3. 重啓php-fpm,或web環境

4.vscode中安裝插件」PHP Debug」

5.配置launch.json

{
    "name": "Listen for XDebug",
    "type": "php",
    "request": "launch",
    "stopOnEntry":false,
    "localSourceRoot": "Z://php_project/",
    "serverSourceRoot": "/home/ryan/php_project/",
    "port": 9000
},
{
    "name": "Launch currently open script",
    "type": "php",
    "request": "launch",
    "program": "${file}",
    "cwd": "${fileDirname}",
    "port": 9000
}

以上,其中」localSourceRoot」是項目代碼在本地的路徑,設置的值是當前工做區根目錄,也就是我項目根目錄。

」serverSourceRoot」是遠程虛擬機中的代碼路徑,」port」是本地IDE在debug時會監聽的端口,遠程xdebug與vscode通訊時就是使用這個端口。

以上設置完畢後就能夠開始斷點調試!!!

 

而後我試了是,並無卵用,確定是哪裏配置錯了呀,因而好吧,一個一個來,先本地debug,由於以前從沒在vscode,而是曾經在phpstrom中debug

3

zend_extension              = "E:\Develop\php-5.6.29\ext\php_xdebug-2.5.0-5.6-vc11-x86_64.dll"
;容許遠程IDE調試
xdebug.remote_enable        = true
;遠程主機
xdebug.remote_host          = 127.0.0.1
;xdebug.remote_port         = 9000 ;默認端口 9000
xdebug.profiler_enable      = on
;臨時跟蹤信息輸出
xdebug.trace_output_dir     = "E:\Develop\ApacheServer\xdebug\trace"
xdebug.profiler_output_dir  = "E:\Develop\ApacheServer\xdebug\profiler"
;其他參數
;開啓自動跟蹤。自動打開"監測函數調用過程"的功模。該功能能夠在你指定的目錄中將函數調用的監測信息以文件的形式輸出
xdebug.auto_trace           = On
;開啓異常跟蹤
xdebug.show_exception_trace = On
;開啓遠程調試自動啓動
xdebug.remote_autostart     = On
;收集變量
xdebug.collect_vars         = On
;收集返回值
xdebug.collect_return       = On
;收集參數
xdebug.collect_params       = On
;顯示局部變量
xdebug.show_local_vars      = On
;顯示默認的錯誤信息
xdebug.default_enable       = On
;用於zend studio遠程調試的應用層通訊協議
xdebug.remote_handler       = dbgp
;若是設得過小,函數中有遞歸調用自身次數太多時會報超過最大嵌套數錯
xdebug.max_nesting_level    = 10000
xdebug.idekey = PHPSTORM

博主vscode不熟,偶然間發現這個launch.json配置文件是全局的

4

因而終於能在本地debug了,debug界面好漂亮,超級簡潔

5

 

 

 

結果我在本地debug解決了問題,遠程debug仍是不行,留着這個帖子下次搞吧,別罵我

相關文章
相關標籤/搜索