PHP调试之Xdebug的安装、配置、本地/远程调试

安装

  • 【推荐】使用pecl安装Xdebug
    pecl install xdebug
    

【手动安装】

  • Xdebug插件下载地址:https://xdebug.org/download.php

  • 如果你不想考虑自己该使用哪个版本,可以使用在线工具:https://xdebug.org/wizard.php
    访问环境的phpinfo页面,将内容复制到工具页的输入框,点击分析即可。

  • 编译安装

tar -xzf xdebug-***.tgz
cd xdebug-***
phpize
./configure --enable-xdebug
make
make install

配置

首先我们要在php.ini中加载并配置插件

;php.ini配置参考
[xdebug]
; 模块文件地址
zend_extension=xdebug.so
; 远程调试开关 bool 0/1 on/off
xdebug.remote_enable = On
; 自动触发Debug,从而无需在请求中带指定参数触发
xdebug.remote_autostart = 1
; 协议 默认: dbgp
xdebug.remote_handler = "dbgp"
; 设置回连,Xdebug将尝试连接到HTTP请求的源主机地址,从而无需指定xdebug.remote_host
;xdebug.remote_connect_back = 1
; 调试host(调试客户端即IDE所在主机的host,要可以被服务器连接到)
xdebug.remote_host = "192.168.88.78"
; 调试端口(调试客户端的监听端口,即IDE设置的DebugPort)
xdebug.remote_port = 9010
; IDE调试key
xdebug.idekey = PHPSTORM

然后我们打开PhpStorm设置
配置Xdebug

PHP调试之Xdebug的安装、配置、本地/远程调试_第1张图片
image.png

本地调试项目配置
PHP调试之Xdebug的安装、配置、本地/远程调试_第2张图片
image.png

远程调试项目配置,勾选路径对应
PHP调试之Xdebug的安装、配置、本地/远程调试_第3张图片
image.png

使用

在IDE开启监听模式,在需要的代码行打上断点。代码执行到断点即会暂停,IDE会弹出Debug窗口


PHP调试之Xdebug的安装、配置、本地/远程调试_第4张图片
image.png

有的版本是这个图标


image.png

你可能感兴趣的:(PHP调试之Xdebug的安装、配置、本地/远程调试)