• PHP vscode+XDebug 远程断点调试服务器上的代码


    参考链接

    https://www.cnblogs.com/ryanzheng/p/10575790.html

    断断续续做php五年了,前期只在开发机器上debug,中期从不debug,有什么问题var_dump一下,现在遇到一个fpdf的问题,无奈必须debug服务器。

    我只是记录一下自己遇到的问题,基本完全按照原文思路来。

    环境介绍:
    本地:win7 + vscode
    远程:CentOS + Apache + PHP5.6 + xdebug

    PHP的运行环境在远程服务器中,项目代码放在本地,使用nfs共享映射到虚拟机中运行。

    1.ssh到虚拟机,检查并安装php的xdebug扩展

    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配置说明。

    这里由于我使用的是宝塔,所有直接打出phpinfo

    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:Developphp-5.6.29extphp_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:DevelopApacheServerxdebug	race"
    xdebug.profiler_output_dir  = "E:DevelopApacheServerxdebugprofiler"
    ;其余参数
    ;开启自动跟踪。自动打开"监测函数调用过程"的功模。该功能可以在你指定的目录中将函数调用的监测信息以文件的形式输出
    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还是不行,留着这个帖子下次搞吧,别骂我

  • 相关阅读:
    css2D转换和3D转换
    css过渡和动画
    Sublime Text、webstorm等编译器快速编写HTML/CSS代码的技巧
    纯CSS制作各种各样的网页图标(三角形、暂停按钮、下载箭头、加号等)
    Vue:渲染、指令、事件、组件、Props
    CSS Grid 网格布局全解析
    flex 布局的深入研究
    数组的迭代方法(every、filter、forEach、map、some)
    You-need-to-know-css
    两列布局
  • 原文地址:https://www.cnblogs.com/mihe/p/11013854.html
Copyright © 2020-2023  润新知