MAMP
默认没有开启XDebug
,如何开启它呢?
注意MAMP
对于特定版本的php
有两个配置文件!!这一点比较坑。你需要编辑两个文件:
/Applications/MAMP/conf/php[version]/php.ini
/Applications/MAMP/bin/php/php[version]/conf/php.ini
在这两个文件中,先翻到最底部,把[xdebug]
部分第一行去掉注释,再在后面加上:
xdebug.remote_enable=1
xdebug.remote_host=127.0.0.1
xdebug.remote_connect_back=1 # Not safe for production servers
xdebug.remote_port=80
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_autostart=true
即可
- 停止 apache 服务
- 打开php.ini
- 找到上面的2个php.ini 的 zend_extension,其中remote_host 是指调试客户端的地址,即IDE所在的IP,同理remote_port 是客户端的端口,这两项在远程调试的情况下注意修改
[xdebug]
zend_extension="/Applications/MAMP/bin/php/php7.0.8/lib/php/extensions/no-debug-non-zts-20151012/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_connect_back=1 # Not safe for production servers
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_autostart=true
- 下面是客户端调试,打开phpStorm,进入File>Settings>PHP>Servers,这里要填写服务器端的相关信息,name填localhost,host填localhost,port填80,debugger选XDebug
- 进入File>Settings>PHP>Debug,看到XDebug选项卡,port填9000,其他默认
- 进入File>Settings>PHP>Debug>DBGp Proxy,IDE key 填 PHPSTORM,host 填localhost,port 填80
- 点OK退出设置。
- 打开浏览器,如果是用chrome或者Firefox可以找到对应的XDebug工具,工具的设置里的IDE KEY填上PHPSTORM,把localhost加入到白名单,以后调试的时候把工具启用就好了。如果是用其他浏览器,可以访问http://www.jetbrains.com/phpstorm/marklets/,在右边填上PHPSTORM,点generate,把下面的链接添加到收藏夹,方便调用。
- 在phpStorm里打开监听,就是一个电话一样的按钮。
- 在浏览器里打开XDebug工具,访问localhost,与phpStorm连接成功!