一、準(zhǔn)備工作
1、安裝vscode里面的兩個(gè)擴(kuò)展
php Debug和Remote - SSH
2、 安裝對(duì)應(yīng)PHP版本的xdebug
去xdebug官方,復(fù)制自己的phpinfo源碼到方框里
xdebug官方網(wǎng)址:https://xdebug.org/wizard
分析完成后,會(huì)有教程教你如何安裝和編譯xdebug
二、ssh連接和xdebug配置
1、配置SSH連接
打開(kāi)vscode,點(diǎn)擊左下角的><按鈕,然后選擇Connect to Host
連接成功后,打開(kāi)你的項(xiàng)目文件夾
同樣去安裝一次xdebug擴(kuò)展
安裝好后點(diǎn)擊運(yùn)行與調(diào)試,創(chuàng)建launch.json文件,創(chuàng)建后會(huì)有內(nèi)容,注釋掉括號(hào)里面的內(nèi)容
添加如下內(nèi)容,端口號(hào)可以自行修改
"version": "0.2.0",
? ? "configurations": [
? ? ? ? {
? ? ? ? ? ? "name": "Debug current script in console",
? ? ? ? ? ? "type": "php",
? ? ? ? ? ? "request": "launch",
? ? ? ? ? ? "program": "${file}",
? ? ? ? ? ? "cwd": "${fileDirname}",
? ? ? ? ? ? "externalConsole": false,
? ? ? ? ? ? "port": 9004
? ? ? ? },
? ? ? ? {
? ? ? ? ? ? "name": "Listen for Xdebug",
? ? ? ? ? ? "type": "php",
? ? ? ? ? ? "request": "launch",
? ? ? ? ? ? "port": 9004
? ? ? ? }
2.xdebug配置
進(jìn)入/etc/php/8.1/fpm/conf.d/20-xdebug.ini
寫(xiě)入內(nèi)容
zend_extension=xdebug.so
[XDebug]
xdebug.remote_enable = on
xdebug.start_with_request = 1
xdebug.mode=trace
xdebug.collect_includes = 1
xdebug.collect_params = 1
xdebug.mode=debug
xdebug.client_host=127.0.0.1
xdebug.client_port=9001
xdebug.start_with_request=yes
xdebug.remote_log=/var/log/xdebug.log
端口號(hào)按自己的來(lái)
然后進(jìn)入你下載PHP時(shí)自帶的php.ini
一樣在最后面加入上面的內(nèi)容
最后重啟php-fpm服務(wù)和web服務(wù)文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-673515.html
三、xdebug調(diào)試,訪問(wèn)
在php代碼上打上斷點(diǎn)后點(diǎn)擊開(kāi)始運(yùn)行,瀏覽器訪問(wèn)后,回到vscode,成功進(jìn)入斷點(diǎn),接下來(lái)就可以調(diào)試了文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-673515.html
到了這里,關(guān)于vscode遠(yuǎn)程調(diào)試PHP代碼的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!