- END #header -->

PHP Debugging on IntelliJ IDEA 10 with XDebug

The Overview

So after being told by my peers that print_r() was adequate, I embarked on a quest to get true PHP debugging working in a reputable IDE. Recently I’ve heard nothing but good things about IntelliJ IDEA 10, so I decided that would be my test subject. Don’t let the “J” fool you, while Java is its focus, this bad boy handles an array of languages and markups, including ActionScript, PHP, Groovy, Scala, Python/Jython, Ruby/JRuby, Clojure, Javascript, and HTML.

If you are a serious PHP developer and have not given debugging a fair chance, or a chance at all, you are killing yourself. So let’s do this thing from the ground up. WAMP, XDebug, IntelliJ, and magic. Follow these steps (for Windows) to reach my recent state of elightenment and PHP debugging bliss.

By the way, I almost gave up on IntelliJ entirely due to problems with debugging until Alex Petrescu () talked me down from the edge. I’m very grateful as IntelliJ is proving to be an excellent IDE.

Step By Step

  1. Download and install WAMP (I installed to C:\wamp)
  2. After installing WAMP, create a file named C:\wamp\www\info.php that contains the following code:
     phpinfo(); ?>
  3. Open the http://localhost/info.php in a browser to get your PHP configuration.
  4. Now view the source of the page in your browser. Copy the entire contents of the source to your clipboard.
  5. Goto the XDebug Tailored Installation Instructions and paste your PHP configuration source into the text box then click “analyse my phpinfo() output”.
  6. Follow the resulting instructions for adding XDebug to your PHP installation. Once you make those changes, make sure the new section of your php.ini looks like this (as per a C:\wamp installation):
    [XDebug]
    zend_extension=""
    xdebug.remote_enable=true
    xdebug.remote_port=9000
    xdebug.profiler_enable=1
    xdebug.profiler_output_dir="c:\wamp\logs"
  7. Download and install IntelliJ IDEA 10 Ultimate Edition (trial). It may not be necessary, but I included all the available extensions.
  8. Setup a basic PHP project in IntelliJ IDEA 10
    1. Goto File -> New Project…
    2. Select Create project from scratch and click Next
    3. Enter a name for your project and select Project Module under the Select Type heading and click Next
    4. Select “do not create source directory” and click Next
    5. Click Finish then OK when asked about starting a project without a JDK assigned.
  9. Create a PHP file to test debugging
    1. In the project panel on the left side, right click the project name and goto New -> PHP File
    2. Enter a name for your PHP file and click OK
    3. In the code panel on the right, enter the following and save the file:
      
      $a = 0;
      ?>
  10. Click the vertical bar between the project panel and the code panel next to the following line to create a red breakpoint:
    $a = 0;
  11. Copy the PHP file you created in step #9 to your WAMP www directory (C:\wamp\www)
  12. Right click on the PHP file name in the project panel, then goto Debug -> filename.php on server
  13. In the resulting window, click the dotted button next to the Server dropdown
  14. Setup your deployment settings
    1. Select Local from the access type dropdown
    2. Click the Mappings tab and under “web path on server” enter a single slash “/” to specify the WAMP root. Click OK and then OK again to finish the configuration.
  15. Right click on your PHP file in the project panel again and goto “Run on server” or “Debug on server“. I’ve had inconsistent behavior using it, so try both if one doesn’t work.
  16. If all went according to plan, a browser should open and execution should stop at your breakpoint. If you look at your debug panel on the bottom on IntelliJ you should now see your PHP globals laid out. Congrats, you made it!


The Summary

I know, its not exactly a walk in the park, but its well worth the work to not have to pollute your code with copious print_r() calls. You can now have full access over your PHP as you would with any other enterprise level language and debugger. I didn’t go into any specific detail here, but I plan in the future to discuss all the ins and outs of PHP debugging in IntelliJ IDEA 10. Its looks to be a great IDE thus far.

If you have any questions, which is likely since I ran into some inconsistent behavior, feel free to comment and I’ll try to answer back as quickly as possible. Hopefully you’ll never even need to ask.

Happy PHP debugging!

10 Responses to “PHP Debugging on IntelliJ IDEA 10 with XDebug”

  1. Quora says:

    Whats the best editor/IDE for PHP?…

    Before recently I would have suggested NetBeans or eclipse like everyone else. A few Flash and Java developers I know suggested IntelliJ IDEA 10. I must say so far I am very impressed. So much so that I put together a quick guide for setting up a PHP p…

  2. [...] Lukasavage has a new post to his blog about debugging your PHP applications with IntelliJ and XDebug on a WAMP install. If you are a serious PHP developer and have not given debugging a fair chance, [...]

  3. Tune Up Your PC » Post Topic » This Week’s Link List (January 7, 2011) says:

    [...] Tony Lukasavage describes how he reached his “recent state of enlightenment and PHP debugging bliss” using WAMP, Xdebug, IntelliJ, and magic: https://savagelook.com/blog/portfolio/php-debugging-on-intellij-idea-10-with-xdebug [...]

  4. Tom says:

    After you install WAMP, you can just go to http://localhost and there is a link provided that lets you see PHPinfo.

    I’ll have to try intelliJ out, I’ve been using Notepad++ for years.

  5. I used jEdit for a long time before giving IntelliJ a shot. Once you start using real debugging in PHP, you’ll never go back to those print_r()’s!

  6. Montreal Web Design says:

    I love IntelliJ, but you need to learn it’s shortcuts!!!

  7. Drew Sheedy says:

    Egad – I’d been using IntelliJ 9 series but 10 for php debugging is damn awesome

  8. Per Møldrup-Dalum says:

    The most important IDEA shortcut is Command-Shift-A on a Mac and Control-Shift-A on everything else. It gives you live glob search in a small text entry box through ALL available commands both with and without menu entries. So if you e.g. want to do something related to “save”, just hit Command-Shift-A and start typing. On top of this it also shows you what keyboard shortcut will accomplish the task, so you learn IDEA in the process of using it :-)

    BTW thank you for this article!

  9. Remote debugging of PHP with IntelliJ IDEA | Just enough code to be dangerous says:

    [...] debug some PHP code running under XAMPP on my OS X Lion laptop. The steps are based on those from PHP debugging on IntelliJ IDEA 10 with Xdebug and Building and Installing Xdebug on XAMPP for OS X [...]

  10. Ruslan says:

    Unfortunately it doesn’t work in Intellij IDEA 11.