Hey folks: D, It’s been a while since I made a post. So back with another one. This time it’s PHP. Specifically PHP debugging. Boys and girls, today we are gonna configure PhpStorm which is one heck of an IDE for PHP development, to debug PHP code with Xdebug and Chrome. With these simple steps you can easily start debugging PHP code without headache.

First open up the php.ini file and make sure you have enabled remote debugging and profiling for Xdebug. I’m using WAMP so you can get to the php.ini file using the WAMP icon on the system tray.

Open php.ini from WAMP System Tray Icon
Open php.ini from WAMP System Tray Icon

Once you open the php.ini file navigate to the bottom of the file where usually the XDebug settings are located (or you can search for XDebug and get there.) and there make sure that the XDebug Extention is installed (As you can see in the image bellow, the path to the “zend_extension” leads to where the Xdebug extension is installed.) and xdebug.remote_enable and xdebug.profiler_enable settings are as seen in the image bellow. (that means they are enabled.)

php.ini Xdebug Settings.
php.ini Xdebug Settings.

Then you need to install XDebug Helper google extension in your chrome browser. To do that, google “Xdebug Helper” and you will see a link to chrome store with the name Xdebug Helper, which is a chrome extension. Click on it you will be taken to the page. There on the top right corner you can see add to chrome button (blue color). Click on it. I’ve already added the extension to chrome so mine is green 😀

Xdebug Helper in Chrome Store
Xdebug Helper in Chrome Store

Then you need to go to chrome settings and go to Extensions tab. There you can see the Xdebug helper extension installed and it should be enabled.

Installed Xdebug Helper in Chrome Extensions
Installed Xdebug Helper in Chrome Extensions

Click on the options link as shown in the image bellow. It will take you to a new page with options to configure the Xdebug helper for chrome.

Xdebug Helper Options Link
Xdebug Helper Options Link

In this page, in the IDE Key section select the PhpStorm option from the dropdown list and close the tab.

Xdebug Helper Options Page, Select The IDE
Xdebug Helper Options Page, Select The IDE

Next we need to go to PhpStorm. 😀 Open up PhpStorm and create a new PHP project. Then navigate to File > Settings to get to the settings window.

Navigating to Settings page in PhpStorm
Navigating to Settings page in PhpStorm

On the settings window, in the Project Settings section navigate to PHP > Debug section where you have debug options for PHP, there as the bellow image shows change the Max. Simultaneous connections value to 20 and leave the default settings the same (as the image) and click ok.

PhpStorm Settings Window
PhpStorm Settings Window

Now open up a browser tab and navigate to the project you create in the local server. My project is named TestProject and you can see the URL in the bellow image. If you have installed the Xdebug Helper extension successfully you can now see a little gray bugs icon in the address bar near the top right corner.

Disabled Xdebug Helper Extension
Disabled Xdebug Helper Extension

Click on this bug icon. Don’t worry it won’t bite you. 😛 😀 You will see a menu drop down. Right now its disabled. You need to click on the Debug menu option. Once you did that you can see that the gray bug turn green. That means you are ready to debug using Xdebug Helper.

Enabling Xdebug Helper in the Browser
Enabling Xdebug Helper in the Browser

Ok. We are close to finishing this. Just a few more steps. 😀 Go to your PhpStorm IDE, in the top right corner of the IDE you can see an icon that is kinda like a telephone with no signal 😀 Look closely in the bellow image.

Listen to Xdebug Connections
Listen to Xdebug Connections

Once you hover over it a tooltip will pop out saying  “Start Listening for PHP Debug Connection”.

Enabling Listing to Xdebug Connections
Enabling Listing to Xdebug Connections

That’s right we need to listen to debug connections coming from Chrome with the help of Xdebug Helper. Click on this icon and it will turn in to a telephone that gets signal, makes sense right 😀 (Green icon, look in the image below).

Enabling Listing to Xdebug Connections
Enabling Listing to Xdebug Connections

Go to PhpStorm and set a break point somewhere in your code. Now don’t tell me you don’t know what a breakpoint is 😛 Now go to your browser and refresh your project. And BAM, in the PhpStorm IDE you will get a dialog box similar to the one in the image bellow with the title “Incoming Connections from Xdebug”. That means we are successfully listening to Xdebug .

Getting connections form Chrome
Getting connections form Chrome

Click on the accept button. Immediately you will see that the IDE stops at the break point. And if you check the browser it has stopped. Look in the bellow image. Your IDE should look like that.

Debugging Php using PhpStorm Debugging tools
Debugging Php using PhpStorm Debugging tools

You breakpoint is highlighted in blue. That means the program execution is now stopped at that point. You can see you have additional panels opened up. This is the Debug panel where you have the option to step through the code using the buttons given, Stop debugging, and continue program execution (No. 2). Also you have variables view where you can view the contents of the variables in your code. Also to the left you can see a Watch panel where you can add variables to watch.

So there you go folks. That’s it. You are now debugging PHP code. It’s easy and saves you tons of time. So guys, till we meet again, HAPPY DEBUGGING 😀 SEE YA……

Advertisements

7 thoughts on “Configure PhpStorm to debug PHP with Xdebug and Chrome

  1. Hey,
    I have done everything written in this article but my execution does not stop as described. I have ubuntu 14.04 with xdebug 2.2.3 on lampp. I am using phpstorm 8.0.

    Please help.

  2. I’ve been battling all day trying to get this working. Followed your brilliant instructions and it worked first time.

    Thank you SO MUCH!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s