May 15, 2011 · debug eclipse netbeans pdt php repchill reprap ubuntu windchill xdebug

Debugging PHP in Ubuntu

A buddy, dlachasse, and I have been learning up on PHP.  We’ve been working on making a simple PHP based PDM (engineering Product Data Management) system, which we’ve conveniently dubbed as ‘repchill.’  I hope to make formal BOM structures to the different breeds of repraps with it.

Both being newbies to PHP and web-apps, we needed to debug some sections of our scripts.  Variable monitoring, watch expressions, the ability to step in and out of sections of code–these are standard tools here!  For such a simple task, why was it so difficult?  There are millions of videos  and tutorials all over the web, yet it still took me a couple of hours to get this running successfully.  When I learned to program, it was in Visual Studio or the Excel VBA editor, and the debugger is right there out-of-the-box!  When I did C, bloodshed had the debugger built in too.  Open source isn’t always the easiest.  Of all of the information posted, the information over on the netbeans website seemed to work best.  Fear not, you can be debugging in no time too!

For those users who just want to get their debugger up and running, whether that be in Eclipse or Netbeans, follow these steps!

  1. Make sure your server is already setup with PHP enabled.  If you are running Ubuntu, installing the LAMP (linux apache mysql php) stack is easy as pie.  Click the LAMP link.  This will turn your std system into a functional dev server in minutes!
  2. Write some HTML/PHP, and put it into your /var/www directory.  This assumes you are using the default server root directory when you install such a LAMP.
  3. Create a phpinfo.php file.  The contents should be exactly:  
  4. Browse to your_server/phpinfo.php (on my machine, localhost/phpinfo.php).  I just opened it up in chrome.
  5. Open another browser window.  Visit  Copy and paste the entirety of the phpinfo page into here.
  6. Follow all of the instructions on the xdebug page.  You may need to run a ‘sudo apt-get install php5-dev’ and ‘sudo apt-get install make’ if your system is fresh.  php5 dev is the most recent as of this post.  If you’re  on an older or newer system than mine, just open up synaptic package manager in ubuntu, and search for ‘php.’  look for php#-dev.  It’s a common package in the repositories.  ALSO, this step will have you add something like zend_extension=/path/to/
to your php.ini.  This is important!  I put mine underneath the ‘Dynamic Extensions’ section in my php.ini file.  Keep the ini open.  We’ll need it later.
  1. Download netbeans package geared towards php.  It’s a .sh file, so you’ll have to make it executable before installing it.  do a ‘chmod +x [downloaded filename].sh’.  Then run a ‘./[filename].sh’ to install it!
  2. Wooof.  Not done yet.  We need to update our PHP.ini  files to enable the debugger to get dirty with the server.   you’ve should have two php.ini files.  not sure if you need to update them both, but the netbeans site seemed to hint you do.  Open both php.ini files (1. /etc/php5/apache2/php.ini, 2. /etc/php5/cli/php.ini).  If you get a permissions error, open then in terminal via a ‘gksudo gedit /etc/php5/apache2/php.ini’ etc.
  3. Way back yonder, the xdebug instructions had you add the zend_extensions =… stuff.  Immediately below that in BOTH files, add the following (no this isn’t me doing something custom to make it work, it IS the standard process)
  4. xdebug.remote_enable=on
  5. xdebug.remote_handler=dbgp
  6. xdebug.remote_mode=req
  7. xdebug.remote_host=localhost [OR WHATEVER YOUR SERVER ADDY IS, i.e.]
  8. xdebug.remote_port=9000

  9. Now, just restart your apache server. ‘sudo /etc/init.d/apache2 restart’

  10. BOOM, debuggin time!  Open netbeans.  Tool->Options->PHP->Debugging is where you can configure the debugger.  Check it out.  Make sure all looks zen and chi.
  11. Open a .php file.  Double left click to the left of the line numbers to toggle breakpoints to stop the debugger at those points, and you can monitor variable values.  Yahoo!  Use the Debug menu commands to navigate through your script.

Let me know if that helped!  Good luck

  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket
Comments powered by Disqus