Being able to debug your php application right from your IDE is something that you can’t fully realise the power of, unless you’ve tried it. The advantages are immediately obvious: as soon as the connection from Xdebug is successful, you are blinded by variable inspection, code stepping, breakpoints, etc… Debugging heaven! It took me… a few months to finally find the time figure out how to set up everything properly, so I hope this post can help someone, somewhere. But don’t worry: it retrospect, it’s not that difficult at all.
First things first : install xdebug
On Ubuntu and Debian, it couldn’t be easier: just open a terminal and type
This will also install Apache and PHP if you don’t have them already.
Setup Xdebug on server
Done? Right, so this created a config file in /etc/php5/conf.d called xdebug.ini, which is read by php and contains xdebug’s configuration options. You’ll need to open this file for editing as root, as we need to make a few changes in there. you can copy/paste the command below in the terminal, or do it your own way.
Within this file, there will be a single line, referencing the xdebug zend extension, something like this (the path can vary slightly)
This is what we’re going to add:
Now we restart apache so that the new configuration is taken into account:
And we that we are done on the server side of things
Switch to the computer where PhpStorm is installed, and open your project. All you have to do is click on the “Accept debug connections” button, and activate Xdebug by using a browser extension. Here are four extensions to do this:
Use your preferred extension to activate Xdebug for the page you’re on. Go back to PhpStorm, and instruct it to listen to incoming debug connections by clicking on the “Listen PHP debug connections” button
Now all you have to is set a breakpoint and reload your page.
A window will popup asking you if PhpStorm should accept the connection from Xdebug
Just click debug and happy bug squishing!