So I finally got Eclispe setup to debug my PHP5 fpm through nginx and I figured I’d share how to do it, since I was unable to find anywhere on the web that had clear step by step instructions.  These assume you have eclipse installed, as well as nginx with php5-fpm as well as the xdebug php modlue.  For me, php5-fpm was running under localhost on port 9000 on ubuntu 10.10 64bit.

  1. Setup xdebug.ini (/etc/php5/fpm/conf.d/xdebug.ini on ubuntu)

    https://gist.github.com/1049443

  2. Restart php5-fpm
  3. From eclipse:
    1. window > preferences > PHP > debug:
      Debugger: xdebug. Click configure and put port 9001 for XDebug port. And for Accept remote session (JIT) choose any.
      Uncheck “Break at first line”
    2. Next to server click PHP Servers. Click New, put in any name, and the URL you would put into your web browser to get to the page on your local system (mine for example is https://localhost.mydomain.com – I put an entry into /etc/hosts that maps localhost.mydomain.com to 127.0.0.1)
    3. window > preferences > General > We Browser:
      Clcik Use external, add your fav browser (I did new, /usr/bin/firefox).
    4.  From PHP perspective in eclipse, do run > debug configurations..
      1. Click PHP Web page and press “new launch configuration”
      2. Give it a name, choose:
        Server Debugger: XDebug
        PHP Server: <name of server u made in step 3.2 above>
        File: <the file in your workspace u want to debug – click browse button for help finding it>
        Uncheck break at first line
        Uncheck autogenerate, and put in a valid URL 

 

OK so now you should be able to press “debug” and your external browser will open (firefox in my case).  Use your browser and navigate to the php page where you have set a breakpoint. It should instantly flip to debug perspective in eclipse and hit ur breakpoint.  

Happy debugging. If you have any tricks that I don’t know about please get ahold of me and I’ll update this post.

Update 5/27/11: You gotta check out the easy x-debug plugin for Firefox. It allows you to enable remote debugging and/or profiling with 1 click. If you use this plugin, you can skip steps 3 and 4 above. Just click the start icon in firefox, then request your page. If you have a breakpoint setup in your php project in eclipse it should automatically launch the debug view.

 

 

Advertisements