Configure PhpStorm to debug PHP with Xdebug and Chrome
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.
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 Extension 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.)
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 :D
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.
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.
In this page, in the IDE Key section select the PhpStorm option from the dropdown list and close the tab.
Next we need to go to PhpStorm. :D Open up PhpStorm and create a new PHP project. Then navigate to File > Settings to get to the settings window.
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.
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.
Click on this bug icon. Don’t worry it won’t bite you. :P :D 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.
Ok. We are close to finishing this. Just a few more steps. :D 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 :D Look closely in the bellow image.
Once you hover over it a tooltip will pop out saying “Start Listening for PHP Debug Connection”.
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 :D (Green icon, look in the image below).
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 :P 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 .
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.
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.
You Might Also Like
← Previous Post
Create a Fade Animation using Blend
July 24, 2014