关于xdebug:Macos环境下在vscode编辑器使用xdebug调试php代码

2次阅读

共计 889 个字符,预计需要花费 3 分钟才能阅读完成。

装置 xdebug

macos 环境下,默认你曾经装置了 php 和 pecl,pecl 是 php 下装置 php 扩大的一种工具,这里我应用的 php7.3

  1. 执行以下命令装置 xdebug 扩大:
    pecl install xdebug
  2. 装置实现后执行:
    php -v
    而后你会看到相似以下返回信息:

    PHP 7.3.20 (cli) (built: Jun  4 2021 03:32:07) (NTS)
      Copyright (c) The PHP Group
      Zend Engine v3.4.0, Copyright (c) Zend Technologies
       with Xdebug v3.0.4, Copyright (c) 2002-2021, by Derick Rethans
       with Zend OPcache v7.3.20, Copyright (c), by Zend Technologies

    看到 xdebug 阐明装置胜利了, 装置胜利门路相似是:
    /usr/local/lib/php/pecl/20180731/xdebug.so

  3. 更新 php.ini 文件,门路相似:
    /usr/local/etc/php/7.3/php.ini
    复制如下内容到文件开端,这里我应用的是 9003 端口,如果你应用其余端口,记得批改,否则可能无奈监听到变动:

    ; Make sure this is the only line which assign `zend_extension` to `xdebug.so`
    zend_extension = /usr/local/lib/php/pecl/20190902/xdebug.so
    [xdebug]
    xdebug.start_with_request=yes
    xdebug.mode=debug
    xdebug.client_host = 127.0.0.1
    xdebug.client_port = 9003
    
    xdebug.show_exception_trace = On
    xdebug.remote_handler = dbgp

VSCode 设置

  1. 装置 php debug 扩大
  2. 设置 php debug 配置文件,这里端口要和 php.ini 里的端口统一
  3. 开始调试,记得这里要去网页端申请 localhost:9003 能力执行
正文完
 0