Configuring PHP Debugging in IntelliJ IDEA with XDebug

I’ve been doing PHP WordPress coding in Sublime Text and was getting the job done, but if I wanted to get serious with PHP coding after a 15 year absence I wanted a more web-aware IDE.  I played in Eclipse for a bit and it was fine, but I think the IDE I am going to go with is JetBrains’ IntelliJ IDEA Ultimate. And if I wanted to get serious with PHP in IntelliJ IDEA I had to configure it for real-time debugging, setting breakpoints, exploring variables and all of that good stuff.

This post walks us through the process of configuring our Linux Apache Server to support debugging with XDebug and how to connect to our XDebug server in IntelliJ IDEA.

End Game

We’ll start with the end game, why we’re doing this.  Here’s an IntelliJ PHP Application running WordPress in debug mode. See the break point? The PHP variables below?  Nice, huh?  We’ll no doubt explore more features of IntelliJ PHP Debugging in future posts.

Configuring XDebug with Apache

XDebug makes this an amazingly simple process. Copy, paste, type a few commands as instructed, restart Apache, and we’re Golden.

We begin by generating a phpinfo() page.  PHP usually creates a http://localhost/test.php page in the LAMP setup. Test.php was present on one of my PCs but not on another. Easy enough thing to create either way.

Next paste the HTML into the XDebug.ORG Wizard. It will tell you what your PHP Debug situation is and what you need to do to install XDebug. Real easy.

Step #4 is to run phpize, which I didn’t have on my system. The XDebug install instructions cover that as well. A simple php5-dev install is all that’s required.

One point on using local domain names like I do, you need to add a couple of lines to your [XDebug] section in PHP.INI.  The first line is part of the XDebug install. We need to enter the second two lines to enable remoting and specify the default port of 9000.

Now restart apache.

We can now run and paste phpinfo() into the Wizard which will confirm we’re rockin’ with the latest version of XDebug.

Configuring IntelliJ IDEA

We have a small bit of configuration work to do in IntelliJ now, beginning with Editing the Configuration.

Next we’re going to click on the “+” and add a PHP Web Application.

In the PHP Web Application we’re going to specify a PHP Server. My development site url is http://nixmash, so my PHP Web App looks like the following.

With the resulting display looking like this.

Now the only thing left to do is to set a breakpoint and click “DEBUG!”