PHP XDebug 本地调试

macOS XDebug 本地调试

很久没写PHP了、同样很很久没有用XDebug了,近期有个简单的场景要用到,简单记录一下关键步骤。

本地环境:

$ php -v
PHP 7.3.4 (cli) (built: Apr  8 2019 10:21:33) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.4, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.4, Copyright (c) 1999-2018, by Zend Technologies
    with Xdebug v2.7.1, Copyright (c) 2002-2019, by Derick Rethans

环境搭建

// 安装xdebug
$ pecl install xdebug
// 配置xdebug
$ vim /usr/local/etc/php/7.3/conf.d/ext-xdebug.ini
[xdebug]
 zend_extension="xdebug.so"
 xdebug.remote_enable=On
 xdebug.remote_port=9001
 xdebug.idekey=PHPSTORM
 xdebug.remote_connect_back = 1
// 重启php服务
$ brew services restart php@7.3

IDE 配置

我是在~/Downloads/xdebug/ 目录下放了一个简单的PHP文件test.php来测试,在这个目录下用php -S 127.0.0.1:7790起了个http服务,可参考进行下述配置。

IDEA的几个配置项 IDEA-PHP-Servers IDEA-PHP-XDebug IDEA-PHP-XDebug-DBGp-Proxy 开启监听 IDEA-Listening

效果演示

设置之后, 在IDE里打上断点, 在浏览器打开这个链接即可开启测试

http://127.0.0.1:7790/test.php?XDEBUG_SESSION_START=PHPSTORM

效果如下:
Debug

浏览器没有必要安装 Xdebug Helper 插件。