vscode远程调试

安装ssh

在vscode扩展插件搜索remote-ssh安装

如果连接失败,出现 Resolver error: Error: XHR failedscode 报错,可以看这篇帖子vscode ssh: Resolver error: Error: XHR failedscode错误_阿伟跑呀的博客-CSDN博客

添加好后点击左上角的加号,ssh root@目标主机ip,点击linux,输入密码即可

安装xdebug环境

在vscode中安装扩展插件PHP Debug。也需要在目标主机上安装PHP Debug

在linux中安装php,并将phpinfo的内容(php -r 'phpinfo();')粘贴到这个网站里https://link.zhihu.com/?target=https%3A//xdebug.org/wizard。

注:php版本不能过低,之前使用的5.6版本提示不能使用,后改为7.3可以正常识别。具体修改可以自行百度

接着下载Download xdebug-3.1.6.tgz

将下载的文件上传并解压tar -xvzf xdebug-3.1.6.tgz

切换到解压目录cd xdebug-3.1.6

运行phpize

如果没有phpize,则需要安装 yum install php-devel。此处可能会有报错,报错的原因可能是php版本和下载的php-devel版本不一致 。需要去官网找到对应的php版本下载对应的php-devel工具(php-devel官网:RPM resource php-devel)。下载好了后,将rpm包上传,运行rpm -ivh xxxxxx.rpm 如果提示缺少依赖,则一个个yum install 缺少的依赖即可。

接下来执行./configure

编译 make

运行cp modules/xdebug.so /usr/lib64/php/modules

创建文件touch /etc/php.d/99-xdebug.ini

将代码写入echo 'zend_extension = xdebug' > /etc/php.d/99-xdebug.ini

在xdebug目录下创建launch.json文件,写入以下内容

复制代码
"version": "0.2.0",
    "configurations": [
        {
            "name": "Debug current script in console",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "externalConsole": false,
            "port": 9004 //xdebug2.0默认9000,3.0默认9003
        },
        {
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "port": 9004
        }

配置xdebug

进入vim /etc/php.d/99-xdebug.ini

写入以下内容

复制代码
    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=9003 //端口修改为上面改的端口
    xdebug.start_with_request=yes
    xdebug.remote_log=/var/log/xdebug.log

进入下载PHP时自带的php.ini,将上面的内容同样添加进去,接着重启httpd和php服务即可

相关推荐
添砖java‘’5 小时前
vim高效编辑:从入门到精通
linux·编辑器·操作系统·vim
不吃凉粉6 小时前
Android Studio USB串口通信
android·ide·android studio
编程乐学7 小时前
安卓非原创--基于Android Studio 实现的天气预报App
android·ide·android studio·课程设计·大作业·天气预报·安卓大作业
非得登录才能看吗?9 小时前
VScode 入门(设置篇)
ide·vscode·编辑器
Costrict12 小时前
解锁新阵地!CoStrict 现已支持 JetBrains 系列 IDE
大数据·ide·人工智能·深度学习·自然语言处理·ai编程·visual studio
AlphaFinance13 小时前
Windows下Vscode连接到WSL的方法
ide·vscode·编辑器
Dobby_0513 小时前
【Go】C++ 转 Go 第(二)天:变量、常量、函数与init函数
vscode·golang·go
空影星21 小时前
Tablecruncher,一款轻量级CSV编辑器
python·编辑器·电脑·智能硬件
开发游戏的老王1 天前
虚幻引擎入门教程:虚幻编辑器的基本操作
编辑器·游戏引擎·虚幻
techdashen1 天前
圆桌讨论:Coding Agent or AI IDE 的现状和未来发展
ide·人工智能