zoukankan      html  css  js  c++  java
  • vscode使用xdebug断点调试php代码(无论win还是linux)

    首先推荐三个在vscode上开发PHP的插件

      PHPDebug 用于调试php,这里主要指打断点、F5等操作。xdebug跟踪、调试和分析PHP程序的运行状况

      PHP IntelliSense 是php的函数智能提示功能

      php cs fixer 可以对代码进行格式化,支持PSR规范

    下载XDebug  https://xdebug.org/download.php

    windows上 

    下载xdebug要结合php的版本、32/64位 、nts/非nts、VC14/VC15

    把xdebug.dll放到php下的ext目录

    pnp.ini 

    [XDebug]
    zend_extension=php_xdebug.dll  
    xdebug.remote_enable = 1  
    xdebug.remote_autostart = 1
    xdebug.remote_handler = dbgp     
    xdebug.remote_host= 127.0.0.1  
    xdebug.remote_port = 9001 

    vscode中

    setting.json  配置php的执行路径

    "php.validate.executablePath": "D:/phpstudy_pro/Extensions/php/php7.3.4nts/php.exe"

    launch.json  配置xdebug port端口即为xdebug设置的端口

    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9001
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9001
        }
    ]

    到此即可在windows上使用vscode加断点的方式调试php代码

    linux上

    使用vscode的Remote-SSH 插件远程打开linux上的文件,然后在linux的php上安装xdebug设置端口,即可使用vscode远程打断点的方式调试php代码

    首先在vscode上安装Remote-SSH 插件 

    配置ssh-config

    Host 192.168.xx.xx
        HostName 192.168.xx.xx
        User xuebing
        Port 10088
        #配置下面两项可免密登录
        #PreferredAuthentications publickey  
        #IdentityFile ~/.ssh/id_rsa

    关于免密登录,需要把本地的id_rsa.pub发送到远程服务器上  ssh-copy-id -i ~/.ssh/id_rsa.pub <romte_ip>

    在linux上安装xdebug,这个需要下载编译

    wget https://xdebug.org/files/xdebug-2.5.5.tgz
    tar -zxvf xdebug-2.5.5.tgz
    cd xdebug-2.5.5
    phpize
    ./configure --with-php-config=/usr/local/php7/bin/php-config
    make 
    make install

    然后配置php.ini

    zend_extension="xdebug.so"
    xdebug.remote_port= 8888
    xdebug.remote_enable = 1
    xdebug.remote_autostart = 1
    xdebug.remote_handler = dbgp
    xdebug.remote_host= 192.168.x.x    
    xdebug.remote_port = 8888
    remote_host就是你的linux服务器的ip

    vscode
    同windows
    launch.json
    port改成当前linux上xdebug监听的port即可
    setting.json 
    配置php的执行路径为当前linux服务器上的php可执行文件的路径

    写在最后:在开发时遇到一个项目需要去调用另一个项目,即业务层调api层这样的,windows上需要在配置nginx的时候,用不同的fast-cgi端口,因此往往需要提前启动一个fast-cgi端口(php-cgi.exe -b 127.0.0.1:9002),很麻烦。linux有fpm因此比windows上方便很多,如果配了xdebug,又用了php-fpm,你就可以调式所有访问php的请求了

     
  • 相关阅读:
    ASP.NET State Service
    C# winform 打印当前窗体
    js计算时间之差
    转 Javascript中event.keyCode键码值表收藏
    从客户端中检测到有潜在危险的 Request.Form
    从VS2005项目转换为VS2008项目 转载
    C# Windows DataGridView 判断CheckBox 选取的方法
    在Visual Studio 2005中调试SQL Server 2005的存储过程
    ASP.NET Ajax 中出现的 sys 未定义(sys undefined)解决方法总结
    KubeMeet 直播 | 现场直击大规模集群、混合环境下的云原生应用交付难题
  • 原文地址:https://www.cnblogs.com/xbblogs/p/12121943.html
Copyright © 2011-2022 走看看