雖然說echo和print_r是公認(rèn)的最實(shí)用的調(diào)試工具,但是效率真的沒有可視化的直接斷點(diǎn)那么高。這里簡單介紹如果安裝及配置xdebug for vscode
一、PHP環(huán)境處的配置
1、編譯安裝
下載及編譯php,因?yàn)槲宜诘墓緋hp版本是5.4的,所以去xdebug官網(wǎng)上選了相對比較底的版本.您也可以根據(jù)你們的實(shí)際情況下載相應(yīng)的xdebug版本:https://xdebug.org/download.php
wget https://xdebug.org/files/xdebug-2.4.1.tgz tar -xvf xdebug-2.4.1.tgz cd xdebug-2.4.1/ phpize ./configure make install
make最終結(jié)束輸出:
make install最終結(jié)束輸出:
2、配置php.ini文件
這個(gè)是我的配置。為了使得可配性更強(qiáng)。我將xdebug配置寫到:/etc/php.d/xdebug.ini
[Xdebug] zend_extension="/usr/lib64/php/modules/xdebug.so" #這里改成你在make install后的路徑。 xdebug.remote_enable = true xdebug.remote_host = 10.0.5.176 #改成你的vscode所以機(jī)器的ip地址 #default port 9000 xdebug.remote_port = 9000 #如果9000端口沖突了,可以換一個(gè)。不過相應(yīng)的vscode配置也要相應(yīng)的改變 xdebug.profiler_enable = on xdebug.auto_trace = On xdebug.show_exception_trace = On xdebug.remote_autostart = On xdebug.collect_vars = On xdebug.collect_return = On xdebug.remote_handler =dbgp xdebug.max_nesting_level = 10000 xdebug.trace_output_dir = "D:/code/videochat" #我這里寫的是php代碼所在的路徑
二、配置vscode
1、使用vscode打開php工程后。安裝php-debug及生成調(diào)試配置文件,如圖所示,依次點(diǎn)擊這些按鈕
2、如下操作后,會出現(xiàn)如下選項(xiàng)框。選中php即可
3、選中后,會出現(xiàn)一個(gè)json的配置文件
修改此json文件,注意serverSourceRoot改成你服務(wù)器上,php所在的路徑。不然即使斷下來后,會出現(xiàn)找不到文件的異常
{ // 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": 9000, "stopOnEntry":false, "localSourceRoot": "${workspaceRoot}", "serverSourceRoot": "/work/videochat" }, { "name": "Launch currently open script", "type": "php", "request": "launch", "program": "${file}", "cwd": "${fileDirname}", "port": 9000 } ] }
最后,在vscode里斷點(diǎn)好后。按F5,等待請求,即可享受圖形化的調(diào)試樂趣
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。