In an earlier post I demonstrated how to install PHP5.4 using brew. Today, I required xdebug for debugging purposes and found it quite easy to install via homebrew.
Install XDebug for PHP
It’s as simple as issuing the command:
1 2 3 |
brew install php54-xdebug //or this: brew install php53-xdebug // if you installed php53 instead of php54 |
Enabling XDebug
I had to add the extension to my php.ini file:
1 |
zend_extension="/usr/local/Cellar/php54-xdebug/2.2.0/xdebug.so" |
Follow the output of the brew info output of the package you installed (either php53 or php54):
1 2 3 |
brew info php54-xdebug //or brew info php53-xdebug |
To enable remote debugging, I also added these lines:
1 2 3 4 |
xdebug.remote_enable=1 xdebug.remote_port=9000 xdebug.remote_handler="dbgp" xdebug.remote_host="localhost" |
Debugging Web Applications
In the run configuration, add “Web Application” type. Configure the server and path as usual. When setup, you shall notice the debug button is active. Setup some break points and hit the debug button.
You can also use the “Listen PHP Debug Connection” option along with some xdebug bookmarklet for quick debugging.
Debugging Command Line Scripts
To debug command line scripts, first issue this command on terminal:
1 |
export XDEBUG_CONFIG="idekey=PHPSTORM" |
PS: I added the line to my ~/.bash_profile so that I don’t have to type it every time I login to bash shell.
Turn on incoming connections by clicking the “Start Listen PHP Debug Connection” button. Set some break points and then run the script from command line.
4 replies on “Debugging with XDebug and PhpStorm on MacOS X”
you are very active in your blog.I get lot of inspiration from you.really you r hard working person.keep it up!!!!
I like to work with Sublime text and this seems to be a good toy to use with xDebug:
https://github.com/Kindari/SublimeXdebug
Thanks for the good tip 🙂
The project looks great 🙂
Going to try it out. Thanks for the pointer 😀
In your php.ini put this instead:
(replace php54-xdebug with the correct version, of course. e.g. php56-xdebug)
That way you don’t have to update the hard coded version in the file path for every homebrew xdebug update.