How To Setup and Configure PhpStorm, Xdebug, and MAMP for Debugging

I must have read 8 – 10 articles scattered about the internet when I first got PhpStorm setup to do debugging with Xdebug and MAMP. Each article seems to be missing one key piece of the puzzle. After a few days mucking with everything, I was able to get the stars to align. And it’s one of those things that, once you get it working, it just works and you don’t have to bother with it again.

However, that initial setup can be very frustrating. And since my good friend,Tom McFarlin,decided to give PhpStorm another serious look, I thought I’d document how I was able to get things setup and hopefully save him and you some time.

What I am about outline below is working with MAMP PRO 3 and PhpStorm 8, though I have had the same success with MAMP PRO 2 and PhpStorm 7. I also assume that most of this is applicable to the regular, non-pro version of MAMP, though I have not tested it.

Xdebug

Fortunately, Xdebug is already included with MAMP, so there is nothing we need to install in addition to MAMP itself. We simple need to enable it within MAMP.

MAMP

You should just be able to enable Xdebug within MAMP by checking the Activate Xdebug option under the PHP tab. And that should be it, at least for MAMP 3.

For most of you reading this, you can just stop here and move onto the PhpStorm section.

However, if you are using MAMP 2, or if you want to ensure that MAMP 3 is indeed configured correctly, you’ll first need to identify what version of PHP you’re using with MAMP. Simply navigate to the PHP tab in MAMP and take note of what you’re default PHP version is.

Or, if you’re running a more advanced setup in MAMP PRO, with different PHP versions for different hosts, head to your Hosts tab to see what PHP version you’re running for the particular host you’re wanting to debug.

With the PHP version identified, you’ll want to open and edit the corresponding php.ini file to enable Xdebug by navigating toFile > Edit Template > PHP > PHP [VERSION] php.ini.

With thephp.inifile open, you’ll want to find the[xdebug]section, which is usually at the very bottom of the file.

At the very minimum, you’ll want to have the following entered and uncommented.

xdebug.remote_autostart=1

xdebug.remote_enable=1

xdebug.remote_host=localhost

xdebug.remote_port=9000

MAMP 2 used to require a bit more configuration, specifically the definition of a zend_extension, so you might want to add all of the following of the minimum configuration does not work for you. Or if you’re using MAMP 3 and you want to enable things like coverage and profiling capabilities.

Please note that the zend_extensions path to thexdebug.sofile will vary depending on the PHP version you’re using, so make sure you look up the correct path on your filesystem.

zend_extension="/Applications/MAMP/bin/php/php5.3.29/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so"

xdebug.coverage_enable=1

xdebug.default_enable=1

xdebug.profiler_enable=1

xdebug.profiler_output_dir="/tmp"

xdebug.remote_autostart=1

xdebug.remote_enable=1

xdebug.remote_host=localhost

xdebug.remote_port=9000

PhpStorm

With PhpStorm open, navigate toRun > Edit Configurations....

Now, if I were to type out everything you’d need to do, it’d be very lengthy. Instead, I created a short GIF to demonstrate what needs to happen. In short, we need to point PhpStorm to the server we want to debug.

You’ll use whatever host and port you’ve configured within MAMP. For this example, I’ve created the hostiowagirleats.devin MAMP PRO (which is also shown in the screenshots above) and I customized my MAMP Apache port to run on port80. If you’re running just MAMP (the non-pro version) or if you didn’t create a custom host, or if you didn’t customize the ports within MAMP, then you’d probably be usinglocalhostwith a port of8888for the configuration below.

Once this is complete, you should see the Debug configuration you just created in the upper right part of PhpStorm.

Seeing Is Believing!

And that should be it!

Set a breakpoint in PhpStorm by clicking in the margin of an open PHP file, click the “bug” next to the configuration you just created to start debugging, and you should hit your breakpoint and feel like you finally have visibility into a once dark and secret world. Gone are the days of the antiquatedvar_dumpas you fumble around to discover what is going on!

Hopefully that helped connect all the dots for you and you’re also up and running.

Please let me know in the comments below if you hit any snags and I’ll try my best to help out.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,362评论 5 477
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,330评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,247评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,560评论 1 273
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,580评论 5 365
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,569评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,929评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,587评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,840评论 1 297
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,596评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,678评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,366评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,945评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,929评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,165评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 43,271评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,403评论 2 342

推荐阅读更多精彩内容