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 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试