Debugging with XDebug and PhpStorm on MacOS X

Auteur(s) de l'article

So you have phpstorm and you want to debug your app step by step using Xdebug?

Install Xdebug for PHP

Homebrew make things simple. You will also need homebrew-php to have PHP-related formula.
brew install php54-xdebug
When the installation is done, brew give you some info:
To finish installing xdebug for PHP 5.4:
  * /usr/local/etc/php/5.4/conf.d/ext-xdebug.ini was created,
    do not forget to remove it upon extension removal.
  * Restart your webserver.
  * Write a PHP page that calls "phpinfo();"
  * Load it in a browser and look for the info on the xdebug module.
  * If you see it, you have been successful!
If you miss it and clear your terminal, you can get those info back with the following command.
brew info php54-xdebug
I'm using php-fpm so I just retart php-fpm.
To check xdebug was installed I used the php-cli, you can also use phpinfo(). Both should contain the xdebug configuration.
php -i | grep xdebug

Configure XDebug and PHPStorm

I had to change the default port of xdebug because 9000 is taken by php-fpm on my machine.
So configure /usr/local/etc/php/5.4/conf.d/ext-xdebug.ini like that:
And also change the port on phpstorm : 

Launch a debug session

On phpstorm from the menu: Run -> Start listen PHP debug connections.
Screenshot showing the Xdebug parameters to setup : Debug port = 10000
With Firefox and you can quickly enable xdebug. On the addon's preferences set the IDE key to "PHPSTORM" (or the one you set in the phpstorm's preferences if you changed it). You then just have to refresh the page, phpstorm should then automatically start a debug session.