---
title: "Configuring XDebug on OSX Mountain Lion"
url: "/articles/configuring-xdebug-on-osx-mountain-lion"
type: article
date: 2012-10-17
updated: 2015-05-01
---

# Configuring XDebug on OSX Mountain Lion

#  Configuring XDebug on OSX Mountain Lion 

 By

 [  Angus Mak   ](/about/angus-mak) 

 October 17, 2012

  

Using a PHP Debugger is a great way to effectively debug your code. A debugger gives you the ability to trace your code line-by-line, with the call stack and all the variables available for inspection at run-time. In previous versions of Mac OS X, installing Xdebug could be a hassle. The recently release Mountain Lion version makes it easy by shipping with many of the tools we need for PHP debugging.

## Setting up Xdebug

OSX Mountain Lion conveniently ships with Xdebug. If you're using the earlier OSX Lion version, you can download and install Xdebug with [PECL](https://pecl.php.net/) (PHP Extension Community Library) or [Homebrew](http://mxcl.github.com/homebrew/). Once you have Xdebug installed, we need to make it available to PHP by editing the php.ini file. To do that, open up /etc/php.ini with your text editor.

If /etc/php.ini doesn't exist, create a copy of the default file with the following command:

```
sudo cp /etc/php.ini.default /etc/php.ini

```

Then find and uncomment the following lines in /etc/php.ini

```
zend_extension="/usr/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so"
xdebug.remote_enable=1

```

Restart Apache, then make sure Xdebug is loading by looking at phpinfo.

```
<?php phpinfo(); ?>

```

![phpinfo](https://www.lullabot.com/sites/default/files/field_regular_upload/phpinfo.png)

## IDE

Finally, we have to tell the IDE how to communicate with Xdebug. In this example, I'm using [PhpStorm](https://www.jetbrains.com/phpstorm/) but you can use any compatible IDE. Start by setting up a new project. Once you have it set up, we will set up the debugger here.

![Edit Configuration](https://www.lullabot.com/sites/default/files/field_regular_upload/edit_configuration.png)

First, add a new PHP Web Application

![PHP Web Application](https://www.lullabot.com/sites/default/files/field_regular_upload/web_application.png)

Add a new server, your Host will be different depending on your setup

![Server](https://www.lullabot.com/sites/default/files/field_regular_upload/new_server.png)

Your configuration should look something like this, where http://drupal7.local/ is where your drupal instance is

![Config](https://www.lullabot.com/sites/default/files/field_regular_upload/config.png)

Now we can run the Debugger

![Debug](https://www.lullabot.com/sites/default/files/field_regular_upload/debug.png)

The browser should now open up http://drupal7.local?XDEBUG\_SESSION\_START=xxxxx and the debugger should open up in Phpstorm. To make sure the debugger is working properly, let's set a break point in index.php.

![Breakpoint](https://www.lullabot.com/sites/default/files/field_regular_upload/breakpoint.png)

Refresh the browser and the debugger should invoke and stop at the break point.

![Trace](https://www.lullabot.com/sites/default/files/field_regular_upload/trace.png)

We're now ready for some PHP debugging!

 Published in:

- [  Drupal Development   ](/topics/drupal-development)

 

   You must have JavaScript enabled to use this form.

## Get in touch with us

### Tell us about your project. We'd love to hear from you!

 First Name  

 Last Name  

 Your email address  

 Your organization  

 How you heard about us  

 Tell us more 

     Leave this field blank