使用phpstorm安装XDebug的艰难历程
- 一 下载xdebug文件
- 二 解压缩文件,然后安装xdebug扩展
- 三 配置php.ini 安装xdebug扩展
- 四 保存php.ini,重新启动PHP 检查是否成功开启了xdebug服务
- 五 配置phpstorm
- 六 配置浏览器的xdebug插件
一 下载xdebug文件
将phpinfo()的源代码复制到文本框中,xdebug会提示如何配置和下载哪个版本的xdebug。
全部下载地址:
http://www.xdebug.org/download.php
二 解压缩文件,然后安装xdebug扩展
tar -xvzf xdebug-2.3.3.tgz
cd xdebug-2.3.3
phpize
./configure
make
make install
第一个坑:运行phpize时报错
$ phpize
grep: /usr/include/php/main/php.h: No such file or directory
grep: /usr/include/php/Zend/zend_modules.h: No such file or directory
grep: /usr/include/php/Zend/zend_extensions.h: No such file or directory
Configuring for:
PHP Api Version:
Zend Module Api No:
Zend Extension Api No:
处理方法:
cd /Library/Developer/CommandLineTools/Packages/
open macOS_SDK_headers_for_macOS_10.14.pkg
然后弹框里安装
第二个坑:运行phpize时继续报错
$ phpize
Configuring for:
PHP Api Version: 20160303
Zend Module Api No: 20160303
Zend Extension Api No: 320160303
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
处理方法:
brew install autoconf
三 配置php.ini 安装xdebug扩展
在php.ini末尾加上如下代码:
zend_extension="/usr/lib/php/extensions/no-debug-non-zts-20160303/xdebug.so"
xdebug.remote_enable = On
xdebug.remote_handler = “dbgp”
xdebug.remote_host = 127.0.0.1
xdebug.remote_port = 9002
xdebug.idekey = phpstorm7
xdebug.remote_log=/tmp/xdebug.log
四 保存php.ini,重新启动PHP 检查是否成功开启了xdebug服务
五 配置phpstorm
Preferences ➡️ Languages & Frameworks
六 配置浏览器的xdebug插件
具体不上图了,百度有好多。
重点来了!!!!大坑
这个时候点击绿色小图标,页面一直在等待响应,而我一个断点都没打,到phpstorm看xdebug也没有任何反应。
查了很多文档,首先让我去看xdebug监听是否正常
lsof -i tcp:9002
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
phpstorm 4077 yanghui 55u IPv4 0x986e72ef24afb813 0t0 TCP *:dynamid (LISTEN)
phpstorm 4077 yanghui 94u IPv4 0x986e72ef201fde93 0t0 TCP localhost:dynamid->localhost:65018 (ESTABLISHED)
看起来没有问题。这个时候陷入了僵局。
去之前配置的xdebug日志观察会出现一堆毛都看不懂的东西。
[3568] Log opened at 2019-08-15 08:03:32
[3568] I: Connecting to configured address/port: 127.0.0.1:9002.
[3568] I: Connected to client. :-)
[3568] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///Users/yanghui/phpWorkSpace/laravel56/public/index.php" language="PHP" xdebug:language_version="7.1.19" protocol_version="1.0" appid="3568" idekey="phpstorm7"><engine version="2.8.0alpha1"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2019 by Derick Rethans]]></copyright></init>
[3568] <- feature_set -i 1 -n show_hidden -v 1
[3568] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="1" feature="show_hidden" success="1"></response>
[3568] <- feature_set -i 2 -n max_depth -v 1
[3568] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="2" feature="max_depth" success="1"></response>
[3568] <- feature_set -i 3 -n max_children -v 100
[3568] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="3" feature="max_children" success="1"></response>
[3568] <- status -i 4
[3568] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="status" transaction_id="4" status="starting" reason="ok"></response>
[3568] <- step_into -i 5
[3568] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="step_into" transaction_id="5" status="break" reason="ok"><xdebug:message filename="file:///Users/yanghui/phpWorkSpace/laravel56/public/index.php" lineno="10"></xdebug:message></response>
[3568] <- eval -i 6 -- aXNzZXQoJF9TRVJWRVJbJ1BIUF9JREVfQ09ORklHJ10p
[3568] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="eval" transaction_id="6"><property type="bool"><![CDATA[0]]></property></response>
[3568] <- eval -i 7 -- aXNzZXQoJF9TRVJWRVJbJ1NFUlZFUl9OQU1FJ10p
[3568] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="eval" transaction_id="7"><property type="bool"><![CDATA[1]]></property></response>
[3568] <- eval -i 8 -- KHN0cmluZykoJF9TRVJWRVJbJ1NFUlZFUl9OQU1FJ10p
[3568] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="eval" transaction_id="8"><property type="string" size="17" encoding="base64"><![CDATA[d3d3LnlobGFyYXZlbC5jb20=]]></property></response>
[3568] <- eval -i 9 -- KHN0cmluZykoJF9TRVJWRVJbJ1NFUlZFUl9QT1JUJ10p
[3568] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="eval" transaction_id="9"><property type="string" size="2" encoding="base64"><![CDATA[ODA=]]></property></response>
[3568] <- eval -i 10 -- KHN0cmluZykoJF9TRVJWRVJbJ1JFUVVFU1RfVVJJJ10p
[3568] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="eval" transaction_id="10"><property type="string" size="5" encoding="base64"><![CDATA[L2Jsb2c=]]></property></response>
[3568] <- run -i 11
[3568] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="run" transaction_id="11" status="stopping" reason="ok"></response>
[3568] <- stop -i 12
[3568] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="stop" transaction_id="12" status="stopped" reason="ok"></response>
在翻了若干篇解决方法都一样但是都没有用的文档之后,老天不负有心人啊,终于在一个角落发现了解决办法,附链接:https://*.com/questions/55153944/phpstorm-xdebug-connection-established-no-debug-window-popup-in-phpstorm
其实就是因为我的phpstorm的版本和xdebug的版本不和谐。在xdebug协议中最近更改的XML命名空间中,从xdebug 2.7开始。自phpstorm 2018.3.0起固定/支持。
解决办法: 将phpstorm升级到最新的stable 2018.3.x或将xdebug降级到2.6.x