第一步:进入“https://xdebug.org/wizard.php”,测试你的环境应该下载什么版本的xdebug
进入网址后复制粘贴。phpinf()内的所有内容:

粘贴后,点击analyse my phpinfo()output

其中第4步注意,要把整体复制到你的php文件目录中,我的是在“/usr/local/Cellar/xdebug-2.7.2”
在此文件中cd /xdebug-2.7.2
第2步中要求安装"autoconf","automake"。最简单的方法是先安装一个“homebrew",然后在终端中运行:brew install autoconf 和 brew install automake 方法快速。
第5步运行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:
场景
mac下,执行 phpize 安装PHP扩展时报错
解决
依次执行下面两条命令, 安装header包
cd /Library/Developer/CommandLineTools/Packages/
// 不同的mac系统, 可能名字不一样
open macOS_SDK_headers_for_macOS_10.14.pkg
安上面方法解决就可以了
到了第8步时,又出现问题。没有权限进行复制。(最好使用macos自带的xdebug.so,它同时也是在这个要复制到的目录里)
此时使用系统自带的xdebug.so。由于macos安全机制,即使复制过去,也没有办法使用。
https://jimfrenette.com/2018/12/xdebug-for-mac-os-x-php/
解决方法是:重启电脑按住command+R进行恢复模式。
输入:csrutil disable 禁止此特性。就可以进行cp。(使用完后如果要恢复此功能“csrutil enable,将会导致系统无法访问xdebug.so)”

第9步使用终端vi 进行编辑。
内容还加入以下内容:
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.idekey = PHPSTORM
xdebug.remote_handler = dbgp
xdebug.remote_host= localhost
xdebug.remote_connect_back = 1
xdebug.remote_port = 9000
xdebug.scream = 0
xdebug.show_local_vars = 1
进行完第10步就可以了 sudo su apachectl restart
成功后如下图:


本文详细介绍了在MacOS环境下安装Xdebug扩展的过程,包括解决常见错误如phpize安装失败、权限问题及如何配置php.ini使Xdebug生效。

1849

被折叠的 条评论
为什么被折叠?



