Debugging PHP using Xdebug and Notepad++ : Part I

January 25th, 2009 | Save to del.icio.us now(0)

I am sure all of you have used ‘echo’ and ‘print_r’ to debug PHP.

We all know that this way debugging is hard and you need to remember to remove them from production server.

Well, thanks to xdebug you can now debug, and you don’t need expensive or blotted IDE for that, just plain and simple Notepad++ can do the job.open php.ini in wamp

In this post we will setup xdebug and DBGp plugin with Notepad++.

Let’s start by installing xdebug.

  1. Download the latest release of xdebug for PHP version you are using.
  2. Copy xdebug dll file into php’s extension directory, in my case, as I use wamp, it is c:\wamp\php\ext .
  3. Now we need to configure xdebug so that it get recognized by PHP, so open php.ini
  4. Add following at the end of your php.ini file
    [xdebug]
    zend_extension_ts="c:/wamp/php/ext/php_xdebug-2.0.3-5.2.5.dll"
    xdebug.profiler_output_dir = "c:/wamp/tmp/xdebug"
    xdebug.profiler_output_name = "cachegrind.out.%p"
    xdebug.profiler_enable = 0
    xdebug.profiler_append=0
    xdebug.extended_info=1
    xdebug.remote_enable=1
    xdebug.remote_handler=dbgp
    xdebug.remote_mode=req
    xdebug.remote_host=127.0.0.1
    xdebug.remote_port=9000
    xdebug.idekey=xdebug
    xdebug.remote_log="c:/wamp/tmp/xdebug/xdebug_remot.log"
    xdebug.show_exception_trace=0
    xdebug.show_local_vars=9
    xdebug.show_mem_delta=0
    xdebug.trace_format=0
  5. Just create a folder ‘xdebug’ in ‘c:\wamp\tmp’ folder.
  6. Finally restart Apache service .

With these steps you have, finished xdebug installation, it is configured for profiling application and remote debugging. Check documentation to know what all these configuration do, and tweak according to your preference.

We will now install DBGP plugin for Notepad++. Make sure you have latest version of Notepad++ is installed.

  1. Download the latest release of DBGp Plugin.
  2. Unzip and move dbgpPlugin.dll file to plugins folder of your notepad++ installation folder, in my case the path is “C:\Program Files\Notepad++\plugins”.
  3. Check out the readme.txt file, that is bundled with plugin, to make sure we don’t miss anything.
  4. Now open Notepad++, and you should see DBGp option in plugins menu.

dbgp plugin for notepad++

Well we are now almost finished with setup, only ting remaining is to configure DBGP to listen to right port and we are done.

Goto “Plugins->DBGp->Config” to open the configuration screen of DBGp plugin.

DBGp Configuration window

Fill the details as shown in the image above. IDE KEY should be same to the one you specified in php.ini settings above. Click Ok and you are done.

To start debugging just add “?XDEBUG_SESSION_START=session_name” at end of you url. ‘session_name’ could be anything you want to keep.

Just launched PHPCamp.net a knowledge sharing website for PHP community

Related posts

  1. Step By Step Guide To Install Memcache On Linux
  2. How to use SVN and Git together to get the best of both worlds in Windows
  3. Simplified AJAX For WordPress Plugin Developers using Jquery
  4. Easy File Uploading Solution For PHP
  5. How to remove new folder exe or regsvr exe or autorun inf virus

Wondering what to do next?


(Search web development related contents)


20 Responses to “Debugging PHP using Xdebug and Notepad++ : Part I”

  1. February 5, 2009 4:34 pm Amit Patekar says

    I have gone through the article, really good article, but i am not clear about the last line in your article.

    “To start debugging just add “?XDEBUG_SESSION_START=session_name” at end of you url. ‘session_name’ could be anything you want to keep”
    And
    How to start debugging.

    Can you please explain.

  2. February 6, 2009 8:35 am Debugging PHP using Xdebug and Notepad++ : Part 2 | am i works? says

    [...] return; document.getElementById(‘a273′).innerHTML = urlinfo.total_posts; } In my previous post, I have shown how to configure Xdebug and Notepad++ for [...]

  3. February 12, 2009 12:02 pm 網站製作學習誌 » [Web] 連結分享 says

    [...] Debugging PHP using Xdebug and Notepad++ : Part I [...]

  4. March 11, 2009 10:52 am Vinothbabu says

    Nice Article mate, i think this approach would go well for small and medium sized applications. but when you come with large ones i think IDE is the best way to go for. Zend provides you a much better solution when it comes thousand lines of code to be debugged.

  5. July 4, 2009 8:52 pm mubahoro says

    Can we translate this article for other languages? For example Spanish?

  6. July 27, 2009 11:52 pm Kumar Chetan Sharma says

    Unfortunately the latest release of NP++ and the plugin are not compatible with each other.

  7. July 28, 2009 6:48 am Amit Kumar Singh says

    @chetan I don’t think so i am using latest version of Notepad++ for my debugging everyday

  8. August 15, 2009 11:38 am Xdebug Remote Debugging says

    [...] Debugging PHP using Xdebug and Notepad++ – I am sure all of you have used print statements to debug PHP. We all know that this way debugging is hard and you need to remember to remove them. Here is an easier way. [...]

  9. August 31, 2009 4:21 pm Jitendra says

    “@chetan I don’t think so i am using latest version of Notepad++ for my debugging everyday”

    Amit, could you please mention version no of your xdebug, notepad and dbgp plugin?

    I’m using xdebug: 2.0.5 with PHP 5.2
    Notepad 5.4.5 and dbgp 0.11

    When I turn on debugger, I always get “Dynamic link library initialization failed’” in notepad and debugger crashes.

  10. August 31, 2009 4:37 pm Jitendra says

    I’ve also tried it on another machine with php 5.3 and compatible xdebug and latest:Notepad 5.4.5 and dbgp 0.11 .

    This time no dll error pops up but debugger doesn’t stop at any breakpoint. I’ve wasted 3 days in figuring out the problem. Could someone please help me?

  11. September 1, 2009 4:54 pm Amit Kumar Singh says
  12. September 1, 2009 5:57 pm Jitendra says

    Amit, I’ve already seen your ‘part 2′ but I didn’t see anything specific which could solve my problem. I did exactly as you mentioned still I get above mentioned errors. Thanks.

  13. September 1, 2009 6:07 pm Amit Kumar Singh says

    Jitendra, then i am sorry i won’t be of much help.. as i need to actully see the error to tell you what is wrong.

    If you followed the steps properly and selected the right xdebug dll for you php then it should work.

  14. September 22, 2009 2:39 pm MIvan says

    127.0.0.1 is not realy a remote IP.
    How to get working with a remote server?

  15. November 22, 2009 8:45 pm opolette says

    To Jitendra :

    May be it is related to SEF. Have your setup URL rewrite ?
    If yes, try disabling it.
    use xdebug_break(); in your code (instead of just setting breakpoints using DBGp) . and see if it works.

    Best Regards

  16. December 2, 2009 12:16 am Jitendra says

    @opolette : Yes I’m using Apache rewrite but it was working fine with earlier Notepad++ version. Something somewhere went wrong and it stopped working.

    I’d try your suggestions and post the result here.
    Thanks.

  17. December 7, 2009 5:25 am David Potter says

    Thank you Jithendra for your article. The documentation for using this plugin is extremely sparse and you got me far enough to start working. With that said, I’m still having trouble getting it working properly.

    I’m using IIS 7.5 on Windows Server 2008 R2 and PHP 5.3.0 and the Firefox Xdebug plugin. Note that when using the Firefox plugin I had to remove the xdebug.idekey setting in my php.ini file.

    When I debug a simple test script, setting a breakpoint doesn’t work at all. The taskbar icon for Notepad++ flashes, but it didn’t break at the line. When I call xdebug_break(), then Notepad++ breaks.

    I tried this same procedure with a larger system (WP.osC, a derivative of osCommerce) and it doesn’t break.

    It would appear that there are some incompatibilities between the Notepad++ DBGp plugin and one of the components in use, maybe PHP 5.3.0 as a previous comment suggested. Too bad, as this is a really nice solution.

    One other problem I ran into. The keyboard shortcuts don’t appear to work at all. I tried pressing F8 to step over and nothing happened.

    If anyone has any ideas on how to solve these problems, I’d love to hear about it.

    Thanks,
    David

  18. December 22, 2009 3:55 pm Kumar Chetan Sharma says

    I stopped using NP++ the day I moved to Karmic Koala full time, now I use SciTE. You must be aware that NP++ is based on SciTE. If you install PHP-CLI package you can simply press ctrl+F7 to check your code for PHP error etc. Though its not as good as a debugger it still helps a lot. :-)

  19. July 8, 2010 8:05 pm Erico Lendzian says

    Thanks. A long time ago I managed to set up my development environment to use xdebug, but I had to re-install my box and then it was all lost.
    I tested many applications that suposedly had debug capabilities, but all of them fail at one point or the other (mainly debugging a live page opened in the browser)
    For the information of those trying to do the same, I’ll advise them to use firefox with the xdebug extension installed, and all goes perfectly. And set DBG inside Notepad++ to refresh the contexts at all time.

  20. July 25, 2010 6:25 pm Sandesh says

    Hi all,
    I am having a unique problem. Cant find the solution anywhere. First I was using Eclipse to debug PHP pages. It worked perfectly with xdebug. Once while clicking debug button I accidentally pressed the cancel button for debugging. Thats when the whole problem started.
    PROBLEM -> while clicking the debug button, my site opens in firefox browser with the address http://localhost/sitabookslive/index.php?XDEBUG_SESSION_START= but the control is not passed back to the editor to start debugging. Instead the site opens up normally and eclipse says Launching: Waiting for xdebug session.
    Now I tried the above method in Notepad++ and the same thing continues here. Even after putting breakpoints in NP++, the control doesnot pass back to NP++ , instead the site opens normally. Could someone please help me out with this. I checked the port, changed the port number, checked xdebug in phpinfo() and everything seems perfect. Netstat says the port no 9000 is in Listening status. dont know how to proceed. Any help is very much appreciated. Thank you.

Trackback URI | Comments RSS

Say Something, and Be Counted

Name (required)

Email (required)

Website

Speak your mind