微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

记一次mac+phpstorm+xdebug的大坑

使用PHPstorm安装XDebug的艰难历程

一 下载xdebug文件

https://xdebug.org/wizard.php

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://stackoverflow.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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐