Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJenny Swift
21,999 PointsDebugging PHP with Breakpoints/Trouble with Xdebug
Hi, how can I debug PHP code using breakpoints and watch expressions with the ablity to step through the code line by line, please? (Just like I can debug Javascript with the Firefox debugger.)
I have tried the following:
At first, Sublime Text would crash after the code had finished being run. Then after using it a little bit, Sublime Text started crashing whenever I started a debugging session, obviously meaning I couldn’t do any debugging.
According to the documentation, pressing f8 again after starting a debugging session should bring up the menu with the option to continue, and this option is not there.
It is not stopping on my breakpoints. I’m not sure if this problem is related to Codebug or Xdebug.
3 Answers
Mike Costa
Courses Plus Student 26,362 PointsHey Jenny,
I use CodeBug every so often, but haven't used any ST2/3 plugins with it. Codebug has some great documentation for installing xdebug and getting the debug IDE up and running.
http://codebugapp.com/support/documentation/#Installing-Xdebug-on-Mac-(MAMP)
I'd suggest making sure xdebug is set up properly in the php.ini file and that the xdebug file exists in the place MAMP thinks it resides.
Tomas Smalakys
5,501 PointsHi Jenny,
I use NetBeans IDE with xDebug coming together.
Also, you can try Chrome Development Tools.
Jenny Swift
21,999 PointsOkay, thanks Tomas!
Jenny Swift
21,999 PointsHi Mike, thanks for the reply!
I followed the instructions in the documentation, but it still doesn't work. This is what the end of my php.ini file looks like:
[xdebug] xdebug.remote_enable=1 xdebug.remote_handler=dbgp xdebug.remote_port=9000 xdebug.remote_autostart=1 xdebug.remote_connect_back=1 ;xdebug.remote_host=192.168.1.108 zend_extension="/Applications/MAMP/bin/php/php5.5.3/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so"
And I also checked the xdebug.so file is in the correct location.
And Xdebug appears to be setup in MAMP-in phpinfo there is a table of lots of Xdebug values that looks something like it does in the Codebug documentation.
Mike Costa
Courses Plus Student 26,362 PointsAt this point, I'd output the php info on one of your pages so see if the correct php.ini file is being used.
echo phpinfo();
Use this echo statement in one of your local scripts (but never use it in a production environment) and see which version of php is being used. It will provide info with which ini file is being read by MAMP (Configuration File path) and right above PHP CREDITS, you should see an image that says powered by Zend Engine. Inside that box, you should see "with Xdebug v2.2.4, Copyright (c) 2002-2014, by Derick Rethans" (or something similar) if xdebug is being read properly from the php.ini file.
Jenny Swift
21,999 PointsI followed your instructions and this is what I see:
PHP Version 5.5.3
Configuration File (php.ini) Path : /Applications/MAMP/bin/php/php5.5.3/conf
Loaded Configuration File: /Applications/MAMP/bin/php/php5.5.3/conf/php.ini
This program makes use of the Zend Scripting Language Engine: Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans (This message is above the Configuration heading.)
Mike Costa
Courses Plus Student 26,362 PointsOk, it sounds like you have xdebug set up properly. Have you tried putting the xdebug function call in your script and then reloading your page?
xdebug_break();
Put that function call somewhere in your script, and then start codebug. Reload the page and see if codebug picks up on the function call.
Jenny Swift
21,999 PointsCodebug is picking up on the xdebug_break function call. I put it in my code, started codebug, reloaded my page and when I do, my Mac switches over to codebug, and the very first line of PHP code is highlighted. If I then click on the continue button, the line below
xdebug_break();
becomes highlighted.
However, the breakpoints I set in codebug are not working. I click on the line number on the left, and a red circle appears. But when I click continue codebug doesn't pause on that line.