Setting up xdebug for PhpStorm on OSX

xdebug

Maybe it was only me, but it really took me quite long to figure out how to enable xdebug for Phpstorm and debug my php code with it, now I have to record this whole process.

1. Install PHP and xdebug

The PHP comes with the OSX isn’t optimal for what we want to do here, since we plan to use Homebrew as our package management software as much as possible. You can install PHP with following command:

$ brew install php56 php56-xdebug

2. Enable xdebug

Now the xdebug is installed, we want to enable it. The ini file for brewed PHP should be at /usr/local/etc/php/5.6/conf.d/ext-xdebug.ini. It should contain:

[xdebug]
zend_extension="/usr/local/opt/php56-xdebug/xdebug.so"

xdebug.remote_enable = 1
xdebug.remote_port = 9000

xdebug.profiler_enable = 1
xdebug.profiler_output_dir="/tmp"
xdebug.profiler_enable_trigger = 1

here the very important attributes are xdebug.remote_enable and xdebug.remote_port.

3. Configure PhpStorm

In Phpstorm the configuration for xdebug is at Preference > Languages & Framework > PHP > Debug > Xdebug remember to change the debug port to what we have in previous step and mark Can accept external connections.

PhpStorm Preference

4. Debug with Xdebug in PhpStorm

Now open your project and click on the listen to the debug button connections in PhpStorm.

Listing to the debug connections

Set a break point by click on the gutter of your code. Then start your php server and open the page you want to debug, append this query ?XDEBUG_SESSION_START=true at the end of the url, refresh page …

url

Voila, now you can debug your code in PhpStorm with xdebug!

xdebug in phpstorm