Using XDebug for PHP Development

Well, this post is a slight shift from Mods for HESK development, as this article isn’t directly about Mods for HESK, but instead is a tool I’m now using for Mods for HESK development.  This tool, in conjunction with PhpStorm (the IDE I’m using for development), is called XDebug.  Most IDEs for other languages, such as Eclipse or IntelliJ IDEA for Java, has debugging out-of-the-box. Unfortunately, PHP doesn’t have this. This is where XDebug comes in.  Since this is a somewhat annoying process, here’s how I got working (note that I am using a Mac running OS X 10.10 Yosemite).

1. Install XDebug using Homebrew – Using Homebrew to install XDebug is the easiest way to get started. Simply run “brew install php55-xdebug” to install XDebug for PHP 5.5 (use php54 or php56 for PHP 5.4 or PHP 5.6, respecively)

2. Update php.ini for XDebug – Open php.ini using a text editor (such as TextWrangler), and add the following lines at the bottom:

xdebug.remote_host=<URL to PHP installation>
xdebug.remote_port=<port to broadcast>

Save your php.ini file and restart Apache / PHP

3. Setup PHPStorm – In PHPStorm, near the top-right is an icon of a telephone with a bug. This, when clicked, will listen for incoming XDebug sessions, and attach to your file. Once this is clicked, startup your server and navigate to your breakpoint!

This is a quick rundown and keeps out some basic parts, but it takes care of some of the annoying parts!