dou8mwz5079 2014-10-10 16:47
浏览 244
已采纳

使用XDebug和PHPStorm,MAMP Pro,OS X进行本地命令行调试

Previously I had MAMP v2.x working great with XDebug. It was configured so I could toggle it on and off for each browser connection using the following bookmarked JavaScript:

javascript:(/**%20@version%200.5.2%20*/function()%20{document.cookie='XDEBUG_SESSION='+'PHPSTORM'+';path=/;';})()

javascript:(/**%20@version%200.5.2%20*/function()%20{document.cookie='XDEBUG_SESSION='+''+';expires=Mon,%2005%20Jul%202000%2000:00:00%20GMT;path=/;';})()

I could also debug scripts executed on the command line with bash turning debugging on and off with:

export XDEBUG_CONFIG="idekey=PHPSTORM"
unset XDEBUG_CONFIG

I've upgraded to MAMP Pro 3.x and have debugging working from a browser and can turn it on and off with the JS bookmarks. However, I've been unable to get debugging to work from terminal. The default install for MAMP is for XDebug to autostart. I do not want that since it prevents access to other sites on the server during debugging so I've modified the config. Here's what I have:

[xdebug]
 MAMP_Xdebug_MAMP
 xdebug.remote_enable=on
 xdebug.remote_log="/var/log/xdebug.log"
 xdebug.remote_host=localhost
 xdebug.remote_handler=dbgp
 xdebug.remote_mode=req
 xdebug.remote_port=9000
 xdebug.idekey="PHPSTORM"

So that my script uses the correct php binary I've sym linked /usr/bin/php to /Applications/MAMP/bin/php/php5.4.30/bin/php

I've also tried turning xdebug.remote_autostart back on to see if I could get debugging from terminal working. No go.

The web has lots of info on how to do remote command line debugging but I've found nothing that helps on local command line debugging.

I'm looking for ideas on how I can get local command line debugging working with MAMP Pro 3.x.

SOLUTION UPDATE: I ran a script with phpinfo() from cli and saw that for some reason when calling php from the command line, it loads a different php.ini. I added the following to /Applications/MAMP/bin/php/php5.4.30/conf/php.ini and it now works!

zend_extension="/Applications/MAMP/bin/php/php5.4.30/lib/php/extensions/no-debug-non-zts-20100525/xdebug.so"
xdebug.remote_enable=on
xdebug.remote_log="/var/log/xdebug.log"
xdebug.remote_host=localhost
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_port=9000
xdebug.idekey="PHPSTORM"

Thanks to @Niloct for sparking the idea that led me to the solution though I am ashamed I did not think of it at first. :/

  • 写回答

1条回答 默认 最新

  • duansai1314 2014-10-10 18:17
    关注

    In PHP setup directory, be sure the configuration xdebug.ini is in conf.d directory so cli and webserver get xdebug activated:

    MacBook:5.5 teixeira$ pwd
    /usr/local/etc/php/5.5
    
    MacBook:5.5 teixeira$ ls
    conf.d               php-fpm.conf         php.ini
    pear.conf            php-fpm.conf.default
    
    MacBook:5.5 teixeira$ ack -i xdebug
    conf.d/ext-xdebug.ini
    1:[xdebug]
    2:zend_extension="/usr/local/Cellar/php55-xdebug/2.2.4/xdebug.so"
    3:xdebug.remote_enable = 1
    4:xdebug.remote_host = 127.0.0.1
    5:xdebug.remote_port = 9005
    6:xdebug.remote_handler = dbgp
    7:xdebug.profiler_enable=0
    8:xdebug.profiler_enable_trigger=1
    9:xdebug.idekey=PHPSTORM
    10:xdebug.remote_log="/tmp/xdebug.log"
    

    then issue php -i | grep xdebug to check if it's loaded in CLI.

    ALSO, triple check the port, notice that I'm using 9005 because of conflict I had with php-fpm.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口