準(zhǔn)備工作
1.首先你需要下載一個(gè)vscode
2.下載模塊
你需要在VScode中去下載我們所需的兩個(gè)模塊PHP Debug以及remote -ssh
3.安裝對(duì)應(yīng)版本的xdebug
需要在xdebug的官方去進(jìn)行分析,選擇適合你自己版本的xdebug
去往官方,將你自己的phpinfo()的源碼復(fù)制到它相應(yīng)的位置,讓它進(jìn)行分析出一個(gè)最適合你自己的xdebug。
https://xdebug.org/wizard
根據(jù)它官方的步驟進(jìn)行安裝。
ssh的連接以及配置
1.SSH的連接
安裝好上述的模塊后,打開(kāi)vscode,點(diǎn)擊左下角的><按鈕,然后選擇Connect to Host。
ssh連接自己想要連接的ip地址。
連接成功后,打開(kāi)你的項(xiàng)目文件夾
同樣去安裝一次xdebug擴(kuò)展
安裝好后點(diǎn)擊運(yùn)行與調(diào)試,創(chuàng)建launch.json文件,創(chuàng)建后會(huì)有內(nèi)容
我們可以將這些內(nèi)容進(jìn)行注釋。然后添加自己的內(nèi)容:
"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這個(gè)目錄下進(jìn)行修改。
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=9004
xdebug.start_with_request=yes
xdebug.remote_log=/var/log/xdebug.log
注意:這里的端口必須要保持一致。
然后重啟php-fpm和web服務(wù)。文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-678209.html
systemctl restart php-fpm
systemctl restart httpd
調(diào)試
這些操作完成后,你就可以進(jìn)行調(diào)試了。
打上斷點(diǎn),進(jìn)行調(diào)試。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-678209.html
到了這里,關(guān)于vscode調(diào)試PHP代碼的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!