Techmania

July 2, 2008

Debugging PHP in Eclipse using XDebug

Filed under: Development,FOSS,Linux — mifan @ 12:44 pm

My previous post touched upon the basics of getting Eclipse PDT (PHP Development Tools) up and running for PHP development. In this post, we’ll be looking at getting PHP debugging capabilities into our PHP dev environment. Again, I’ll be focusing on Ubuntu Linux – 8.04 LTS to be specific: however, with minor changes, this can be used on any platform.

Of course, there are simpler methods of debugging PHP scripts: a var_dump is quite handy in terms of simple debugging – however, having the right tools at hand for development means that we can spend more time in actual development than writing debug statements every once in a while – anyways, that’s my take.

XDebug is a remote debugger. Here we’ll take a look at getting XDebug working with Eclipse PDT providing a full debugging client. The first step would of course be to get Eclipse PDT up and running (refer previous post if needed). Once done, the next step would be to get Xdebug for our PHP environment set up – in my case, PHP5. On Ubuntu, this can be achieved by:
apt-get install php5-xdebug
This should install Xdebug for PHP5. Next, we’d configure Xdebug by editing the PHP configuration file. Most systems require the configuration items be added to the main php.ini, or the appropriate conf file. In Ubuntu 8.04 LTS, a separate configuration file,xdebug.ini, is created for Xdebug. Open this file using your favorite text editor (vim in my case):
sudo vim /etc/php5/conf.d/xdebug.ini
Add the following lines after the zend_extension= or zend_extension_ts= conf value.

xdebug.remote_enable=On
xdebug.remote_host="localhost"
xdebug.remote_port=9000
xdebug.remote_handler="dbgp"

And restart your web-server. In my case, Apache:
/etc/init.d/apache2 restart
To try out the debugger, open a PHP project in Eclipse (if you are importing an existing project via CVS, remember to add it as a PHP project using the New Project Wizard). In Window->Preferences->General->Web Browser, select external web browser, and set it to point to your default web browser. Next go into the debug section, by Window->Preferences->PHP->Debug, and set the PHP Debugger option to XDebug (by default this is set to the Zend Debugger). Note the chekbox “Break at first line” in this page as well – you can change this later on, as required. After you’ve applied your changes, go into the Debug menu, by Run->Open Debug Dialog… Here, make sure the Server Debugger is set to XDebug, and that the PHP server points to http://localhost or an appropriate server location. The file section should point to the file to be debugged, relative to your workspace (Note: if your project is missing from the list, check whether you’re project is configured as a PHP project – I’ve noticed that non-PHP projects fail to appear on this list). Thus if your file is index.php, the relative path maybe something/www/index.php etc.
Next, check the URL section to see whether it points to the correct location – if not, make sure you uncheck the “Auto-Generate” check box, and enter in the correct location. Apply the changes and close the dialog box.
A view of the Debug dialog is here:
EclipsePDT Debug Dialog
You should now be ready to debug your application. Click on Run->Debug or F11 to enable debugging – Eclipse should switch to the Debug View, and the page should start loading in your external browser. If “Break at First Line” checkbox was checked previously, then the program would have “stopped” at the first line – you can step into or step over subsequent lines using the controls on your top left corner. Alternatively, you can place breakpoints at various locations and stop code execution there as well. The variables tab should give you the variables and their values at various times. I good guide from which I borrowed from is here. Get creative – start debugging.
A view of the debugger in operation is here:
EclipsePDT XDebug for PHP

59 Comments »

  1. Dear,

    I’m using Firefox 3.0, Version: 3.3.2 on Ubuntu. After all config, i press F11 to debug. Firefox is opened, it create a new tab with name is Untitled an show download dialog require I download *.php file. And Eclipse doesn’t not with to debug view.

    Help me!
    Thanks,

    Comment by trunghpb — November 14, 2008 @ 3:32 pm | Reply

  2. #trunghpb I’ve got exactly the same problem. Can’t find a solution anywhere. did you have any luck?

    Comment by Sky — November 15, 2008 @ 11:53 pm | Reply

  3. I fixed this by reinstaling and pointing window>preferences>Php>php executables to my php5 file rather than php.In my case /usr/bin/php

    Comment by Sky — November 16, 2008 @ 4:24 pm | Reply

  4. I’m having the same problema as trunghbp and Sky, but I cannot change that setting, when I try to modify it Eclipse says: “This is a predefined PHP executable configuration which cannot be modified”

    Comment by Fran — March 20, 2009 @ 2:46 pm | Reply

  5. Tried this. After trying for a while to get zend going, I came across this post and gave xdebug a shot. Surprisingly easy, I’m glad to finally be able to debug php. You should post this on the Ubuntu help wiki. Thanks dude.

    Comment by ricardo — July 2, 2009 @ 2:38 am | Reply

  6. Thanks for the article.

    One thing that surprises me is the requirement to configure the Eclipse feature to get to the “file to be debugged”. I have projects with large numbers of files. Am I supposed to create a new configuration for each file I want to debug? Seems incredibly complex to do. Wouldn’t Eclipse be capable of just taking the name of the script I’m clicking on *dynamically* and then apply the debug mechanism to it?
    You might not have any involvement in this plugin, and I’m certainly not accusing anyone (just to make sure). I’m just wondering if I’m the only one having this problem and if there is a solution…

    Thanks,

    Yannick

    Comment by ywarnier — July 22, 2009 @ 8:07 pm | Reply

  7. […] Debugging PHP in Eclipse using XDebug – Eclipse Debugging […]

    Pingback by Xdebug Remote Debugging — August 15, 2009 @ 6:08 am | Reply

  8. Thanks for your help! i’ve been trying to get it working for a long time, but my efforts were fruitless. This guide made it really easy!

    Comment by Bram — August 27, 2009 @ 6:31 pm | Reply

  9. I followed your instructions, but my debug go straight on to the end and does not stop at breakpoint…I am on Kubuntu 9.04 but the config file is the same as 8.04…any help please? Two days I am working on it…

    Comment by Alex — September 15, 2009 @ 5:04 pm | Reply

  10. sorry, lost subscription…

    Comment by Alex — September 15, 2009 @ 5:07 pm | Reply

  11. That worked for me!
    Thank you so much 😉

    Comment by Faber — October 4, 2009 @ 7:57 am | Reply

  12. it is really helpfull , thanks a lot

    Comment by harsha halgaswatta — January 16, 2010 @ 8:54 pm | Reply

  13. Thanks! saved me a lot of time

    Comment by Assaf Karmon — March 7, 2010 @ 6:50 pm | Reply

  14. THANK YOU! You have the most coherent and helpful guide to setting up PHP debugging in Eclipse on Ubuntu, and I really appreciate it. 🙂
    — Jennifer Hodgdon

    Comment by Jennifer Hodgdon — April 16, 2010 @ 8:01 pm | Reply

  15. Agree, this was really helpful! I had a problem though where Eclipse would not open a browser window whenever I tried to debug. I could debug fine in NetBeans, so I knew the problem wasn’t with XDebug, but rather with Eclipse. Checked the Eclipse log (workspace/.metadata/.log) and saw:

    !MESSAGE The debug port 10000 is in use. Please select a different port for the debugger.

    Odd, since 10000 is the port assigned to Zend Debugger, and I had set things up to use XDebug. At any rate, after switching the Zend Debugger to an unused port (10000 is the default port for webmin), I was able to successfully launch a browser and use Xdebug as usual.

    Comment by Kristin Stromberg — May 19, 2010 @ 12:51 am | Reply

    • thank you thank you thank you!!!!!!!!!!!!!!!!!!!!!!!!
      I was struggling since weeks!!!!

      Comment by mike — December 29, 2010 @ 10:43 am | Reply

    • I’m about to crying…I believed I was lost but now I see the light…thank you! 🙂

      Comment by ironman_xx — June 9, 2012 @ 8:19 pm | Reply

  16. when you lost:
    1. save current php.ini file as php.ini.old
    2. open php.ini-dist and save as php.ini
    3. download and save in correct position the exact Xdebug version.
    4. add required lines at the end with full path.
    5. restart your web-server

    this work for me

    thanks all

    Comment by Shimon — June 17, 2010 @ 7:44 am | Reply

  17. It’s nice post.
    Thanks you so much.

    Comment by Pankit — July 2, 2010 @ 5:40 am | Reply

  18. I had the same problem as Alex reported before: The debugger didn’t stop or “catch” the breakpoints, only the first line (since I had checked the option to stop on first line in the Run configuration).

    By enabling logging (added the line
    xdebug.remote_log=”/tmp/xdebug.log”
    in /etc/php5/conf.d/xdebug.ini), I found out what was happening.

    Solution was: I had changed location of my www folder (to /home/[username]/www instead of /var/www), and forgot to update the path mapping in
    Run > Debug configuration > “Server” tab > “Configure button” beside PHP Server config line > “Path mapping” tab
    After changing this it works!

    Btw, I also have to include the following line in the xdebug.ini file:
    zend_extension=/usr/lib/php5/20090626+lfs/xdebug.so
    (exact path can be different depending on php version)

    Comment by Samuel Lampa — July 13, 2010 @ 4:31 pm | Reply

  19. Btw, I should mention about this bug with Eclipse Helios, which is reported to cause the same problem: https://bugs.eclipse.org/bugs/show_bug.cgi?id=312951
    Therefore, I’m sticking with Eclipse Galileo PDT SR2 for now (works fine, with both xdebug 2.0.5 and 2.1.0).

    Comment by Samuel Lampa — July 13, 2010 @ 4:34 pm | Reply

  20. Figured out now that I needed to use the latest version of PDT (2.1.0) in order for local variables to be properly tracked (You need to download it from the SVN server and compile it from source).

    Comment by Samuel Lampa — July 13, 2010 @ 7:01 pm | Reply

  21. Thank YOU Samuel Lampa!
    It works for me on Ubuntu 10

    Comment by exor — August 30, 2010 @ 10:11 am | Reply

  22. I have a IIS/xdebug/Eclipse configuration.

    It stops when I set it to stop at the first line. But then all my breakpoints doesn’t break the exectution proces… I’ve finally figured out that problem was in Eclipse project name – it doesn’t like a dash (‘-‘) char in the project name/folders. So everything has been fixed with simple renaming of the project name.

    Comment by Igor Kostin — October 18, 2010 @ 2:35 am | Reply

  23. BTW, I use the latest Eclipse Helios version and recommend everybody to update your Eclipse since there are many important fixes and improvements.

    Comment by Igor Kostin — October 18, 2010 @ 2:37 am | Reply

  24. Good story.. you have to check Adult Toy Store.

    Comment by theerotictoystore — December 3, 2010 @ 5:39 am | Reply

  25. thanks, it worked for me

    Comment by Rocky — February 11, 2011 @ 2:40 pm | Reply

  26. I didn’t have the xdebug.ini settings so XDebug kept crashing whenever I would attempt to view a variable in Eclipse. Thanks for the tip!

    Comment by Marlon — February 15, 2011 @ 3:52 am | Reply

  27. Thanks for the article. It was useful.

    Comment by Merce — May 18, 2011 @ 11:04 am | Reply

  28. I use the latest Eclipse Helios version and recommend everybody to update your Eclipse since there are many important fixes and improvements.

    Comment by adult toys — November 1, 2011 @ 5:21 pm | Reply

  29. , IBD.
    .
    , . .
    5000 , IBD- , .
    .

    Email: 0458727@gmail.com
    , .

    .ibd. Bonder Gel, 14 . 732,375
    .ibd. Clear Gel, 14 . 732,375
    .ibd. Clear Gel, 56 . 1559,25
    .ibd. Clear Gel, 226 . 3945,375
    .ibd. Builder Gel Clear, 14 . 732,375
    .ibd. Builder Gel Clear, 56 . 1795,5
    .ibd. Builder Gel Pink, 14 . 732,375
    .ibd. Builder Gel Pink, 56 . 1795,5
    .ibd. Builder Gel Ultra White, 14 . 732,375
    .ibd. Builder Gel Ultra White, 56 . 1795,5
    .ibd. Builder Gel White, 14 . 732,375
    .ibd. Builder Gel Natural, 14 . 732,375
    .ibd. French X-treme Builder Gel Clear, 14 . 732,375
    .ibd. French X-treme Builder Gel Blush, 14 . 732,375
    .ibd. French X-treme Builder Gel Blush, 56 . 1795,5
    .ibd. French X-treme Builder Gel Pink, 14 . 732,375
    .ibd. French X-treme Builder Gel White, 14 . 732,375
    .ibd. French X-treme Builder Gel White, 56 . 1795,5
    .ibd. Ultra Seal Clear, 14 . 784,35
    .ibd. Ultra Seal Clear, 113 . 2263,275
    .ibd. Intense Seal, 14 . 732,375
    .ibd. Intense Seal, 236 . 3260,25
    .ibd. Builder Gel Clear 95 . 2740,5
    .ibd. Clear Gel, 30 . 1323
    .ibd. Builder Gel Clear, 30 . 1323
    .ibd. Builder Gel Pink, 30 . 1323
    .ibd. Builder Gel Pink, 95 . 2740,5

    .ibd. Introductory Gel Kit 1559,25
    .ibd. Professional Gel Kit 4862,025
    .ibd. Sweet Confection Gel Polish Kit 2268
    .ibd. Precious Metals Gel Polish Kit 2268
    .ibd. Holiday Gel Polish Collection 1677,375

    —--
    .ibd. Gel Polish Up All Night, 7 . 420,525
    .ibd. Gel Polish Extreme Black, 7 . 420,525
    .ibd. Gel Polish Autograph, 7 . 420,525
    .ibd. Gel Polish Tangerine Dream, 7 . 420,525
    .ibd. Gel Polish Glitter Shimmer, 7 . 420,525
    .ibd. Gel Polish Pamper Me, 7 . 420,525
    .ibd. Gel Polish Copper, 7 . 420,525
    .ibd. Gel Polish Rose Gold, 7 . 420,525
    .ibd. Gel Polish Holly Berry, 7 . 420,525
    .ibd. Gel Polish Stainless Steel, 7 . 420,525
    .ibd. Gel Polish Sun Ray, 7 . 420,525
    .ibd. Gel Polish Ruzh f Nuar, 14 . 236,25
    .ibd. Gel Polish Silver Bells, 7 . 420,525
    .ibd. Gel Polish Party Till Dawn, 7 . 420,525
    .ibd. Gel Polish Techno Ruby, 7 . 420,525
    .ibd. Gel Polish Cognac, 14 . 236,25
    .ibd. Gel Polish All Terrain, 14 . 236,25
    .ibd. Gel Polish Titanium, 7 . 420,525
    .ibd. Gel Polish Gracial Mint, 7 . 420,525
    .ibd. Gel Polish Apricot Creme, 7 . 420,525
    .ibd. Gel Polish Eternal Daydream, 14 . 236,25
    .ibd. Gel Polish Tango, 14 . 236,25
    .ibd. Gel Polish Chocolate Gloss, 14 . 236,25
    .ibd. Gel Polish Rustic, 14 . 236,25
    .ibd. Gel Polish Fairytale Romance, 14 . 236,25
    .ibd. Gel Polish Glass Slipper, 14 . 236,25
    .ibd. Gel Polish Spicy Terracotta, 14 . 236,25
    .ibd. Gel Polish Natural Elegance , 14 . 236,25

    Comment by vikosha0458727 — December 21, 2011 @ 3:40 pm | Reply

  30. Thank you it worked for me 🙂

    Comment by pavi2p — March 3, 2012 @ 10:26 am | Reply

  31. Доброе утро!

    Comment by SashaMebel — March 26, 2012 @ 4:53 am | Reply

  32. Thanks a heap! Awesome guide!

    Comment by acewolk — May 9, 2012 @ 11:34 am | Reply

  33. It’s nice guiedlines.Last 5 years i used dreamviewer for php devlopment.And many times i found difficulties.

    Comment by uday Satardekar — June 29, 2012 @ 4:59 am | Reply

  34. I prefer Codelobster PHP Edition
    It is my favourite free PHP debugger.

    Comment by Ruslik — January 29, 2013 @ 12:53 pm | Reply

  35. Wonderful goods from you, man. I’ve understand your stuff previous to and you’re just extremely wonderful.

    I really like what you’ve acquired here, really like what you’re stating and the
    way in which you say it. You make it enjoyable and you still care for to keep
    it smart. I can’t wait to read much more from you. This is actually a great website.

    Comment by Property And Liability Insurance — May 14, 2013 @ 12:13 pm | Reply

  36. Yes! Finally something about payday loan blog.

    Comment by http://www.cangm.com/ — May 19, 2013 @ 6:02 am | Reply

  37. Excellent, what a web site it is! This blog gives valuable
    information to us, keep it up.

    Comment by url shortner — May 24, 2013 @ 9:31 pm | Reply

  38. For the reason that the admin of this website is working,
    no question very shortly it will be famous, due to its quality contents.

    Comment by laser spine institute — June 5, 2013 @ 6:02 pm | Reply

  39. I like the helpful information you provide in
    your articles. I will bookmark your weblog and check again
    here regularly. I’m quite certain I will learn lots of new stuff right here! Good luck for the next!

    Comment by Canvas modern Art — June 16, 2013 @ 8:00 am | Reply

  40. Small businesses are able to obtain tax forms to their employees
    faster by to be able to print these documents for the children, in lieu
    of employees waiting for their tax forms to arrive inside mail.
    It is best to uncover the difficulties early enough before they get compounded and harder to correct.
    Two in the major benefits to buying a middle with the road application include affordability and simplicity of use.

    Comment by payroll services — June 17, 2014 @ 12:38 pm | Reply

  41. I’d like to thank you for the efforts you’ve put in writing this blog.

    I really hope to see the same high-grade blog posts from you in the future as well.
    In truth, your creative writing abilities has encouraged me to get my own blog now 😉

    Comment by how many kilograms in a pound — July 26, 2014 @ 1:38 am | Reply

  42. I like the helpful info you provide in your articles.
    I will bookmark your weblog and check again here
    regularly. I’m quite sure I’ll learn plenty of new stuff right here!
    Best of luck for the next!

    Comment by Michele — August 3, 2014 @ 5:31 am | Reply

  43. I’m not sure exactly why but this blog is loading very slow for me.
    Is anyone else having this issue or is it a problem
    on my end? I’ll check back later and see if the problem still exists.

    Comment by Theodore — August 4, 2014 @ 1:47 am | Reply

  44. Undeniably believe that which you stated. Your favorite reason seemed to be on the internet
    the simplest thing to be aware of. I say to you, I definitely get annoyed
    while people think about worries that they plainly don’t know about.
    You managed to hit the nail upon the top as well as defined out the whole thing without having side-effects ,
    people could take a signal. Will probably be back to get more.
    Thanks

    Comment by how many kilograms in a pound — August 6, 2014 @ 1:34 am | Reply

  45. Superb blog! Do you have any suggestions for aspiring writers?
    I’m hoping to start my own website soon but I’m a little lost
    on everything. Would you recommend starting with a free platform like WordPress or go for a
    paid option? There are so many options out there that I’m completely
    confused .. Any suggestions? Thanks a lot!

    Comment by www.rebelmouse.com — August 16, 2014 @ 2:38 am | Reply

  46. It’s remarkable to pay a visit this web page and reading the views of all colleagues about this paragraph, while I am also zealous of getting knowledge.

    Comment by how many kilograms in a pound — September 7, 2014 @ 8:44 pm | Reply

  47. Excellent website. Plenty of helpful info here. I am sending it to some buddies ans also sharing in delicious.
    And obviously, thanks for your effort!

    Comment by emergency east london locksmith — September 21, 2014 @ 3:19 am | Reply

  48. There are a few simple things you can consider as a GM when you begin to organize and
    plan your game that will keep you from finding yourself in the sticky situation I
    found myself in all those years ago. Where is it set —
    science fiction world, fantasy world, futuristic world. Chances are once you start playing
    and getting used to all the fun and time-saving innovations, you’ll end
    up spoiled.

    Comment by playoverwatchbeta.pw — November 27, 2014 @ 2:47 pm | Reply

  49. I all the time used to ead post in news papers but now as I am a user of internet therefore from now I am using net for posts, thanks to web.my site – strategie roulette, Keith,

    Comment by Clay Hogan — June 5, 2016 @ 11:59 am | Reply

  50. At this moment I am ready to do my breakfast, afterward having my breakfast coming yet again to read other news.Feel free tto visit my site – roulette betting system

    Comment by Theodore Kinsey — July 3, 2016 @ 4:56 pm | Reply

  51. Great web site you’ve got here.. It’s hard to find quality writing like yours these days.I truly appreciate individuals like you! Take care!!Review my web blog – agenjudiresmipialadunia

    Comment by Collin Gilman — August 16, 2017 @ 2:14 pm | Reply

  52. Yes! Finally someone writes about sbobet judi bola.Feel free to visit my weblog … cara daftar judi online

    Comment by Barbra Benavidez — August 16, 2017 @ 2:19 pm | Reply

  53. I’m not positive the place you’re getting your information, but great topic. I needs to spend some time learning much more or figuring out more. Thank you for wonderful information I used to be in search of this info for my mission.Here is my web page http://www.artikelgoal.com

    Comment by Liza Braman — November 2, 2017 @ 7:04 am | Reply

  54. Since the admin of this site is working, no uncertainty very shortly it will be famous, due to its feature contents.Here is my homepage agen judi online piala dunia

    Comment by Leta Birch — November 3, 2017 @ 6:59 am | Reply

  55. I’m not certain the place you’re getting your info, however good topic.I must spend some time finding out more or working out more.Thank you for fantastic info I was looking for this information for my mission.My homepage … judi tembak ikan Online

    Comment by Gerardo Snowball — November 12, 2017 @ 8:00 am | Reply

  56. Sesuatu yang paling membingungkan pada zaman perjudian sekarang ialah dalam memilih agen taruhan sbobet terpercaya dari SBOBET,kami selaku agen besar kemudian terpercaya dalam dunia judi online siap membantu awak dalam mengakses dan mengasihkan panduan kepada anda di bermain SBOBET, akses ekspress yang kami berikan merupakan hal nyata tanpa bohong belaka.Telah banyak pejudi online yang bergabung berbareng kami dalam bermain CASINO SBOBET judi bola online, kedatangan anda kami akan kerap tunggu dengan senang hati dan operator kami sering siap membantu anda bila mengalami kesulitan. SBOBET gak sembarangan dalam memberikan jaringan kepada Agen Judi SBOBET Casino Online judi online karena hanya agen betting online terpercaya dan mempunyai reputasi baik seperti kami yang dipercaya SBOBET di dalam menyediakan permainannya yaitu CMIDN.SBOBET memiliki banyak pengagum terutama penggila taruhan football online, dari kalangan putra muda bahkan orang tua memilih SBOBET sebagai spouse mereka dalam bermain bet bola online, SBOBET patut memiliki banyak agen lebih besar dan terpercaya dalam situasi ini kami adalah diantaranya, promo-promo sering kami berikan kepada anda member anyar ataupun member lama, oleh karena itu buat apa anda menunggu lagi cepat bergabung berbareng kami dan rasakan serunya taruhan bola online BOLA TANGKAS bersama kami agen popular.Kami agen judi popular memiliki dukungan penuh dri SBOBET dalam memberikan hubungan dalam bermain Judi Adulador Online, Keamanan dan ketentraman dalam betting adalah perkara penting bagi kami, dengan tidak memandang masalah kecil ataupun besar kami sebagai agency taruhan online profesional sering mengatasi hal seperti tersebut dengan cepat.

    Comment by Temeka Billingsley — April 9, 2018 @ 4:00 pm | Reply

  57. Thanks for sharing your thoughts on %meta_keyword%.RegardsAlso visit my web site … نظام فارس الجديد

    Comment by Hermine Fitzsimons — July 20, 2018 @ 7:04 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a reply to www.rebelmouse.com Cancel reply

Blog at WordPress.com.