How to setup local PHP debugging with PHPStorm and Xdebug

I am checking out a new IDE on the block – PHPStorm… well, new for me anyway :)

For Java and Python, Eclipse is all I need, but when coding in PHP, I am not a big IDE guy, for me, Vi is still the weapon of choice. But when it comes to debugging complex apps(yeah you can write those in PHP too :) , Vi doesn’t quite cut it. There are plugins for it to provide debugging capabilities(or rather Vimified interface to Xdebug), but half of the time it doesn’t work and the other half of the time it’s not what I am looking for. So far, I’ve been a user of Komodo IDE, I still have the old version 4 up and running here and do most of my debugging in it. It’s nice on one side, but somewhat cumbersome on the other.

Anyway, one major thing that always kept me from trying new IDEs is debugger setup. I tend to spend 10 minutes trying to setup debugging in new IDE, get frustrated, say fuck it, and get back to Komodo. This short blog post is to capture how I setup debugging in PHPStorm using Xdebug.
There is a video about this as to how to get a remote debugging working, but not much info about how to get a local one for folks who is on Linux(Ubuntu in my case).
So there we go:

Xdebug Setup

Step 0. Get phpize. If you’re on Ubuntu it’s as simple as running sudo apt-get install php5-dev
Step 1. Get Xdebug, it’s pure awesomeness. Just go here: and follow the instructions. Note: you can also try installing it from pecl or Ubuntu repository, but I had problems with these methods before.
Step 2. I recommend not to follow the last step of Xdebug install instructions where it says to add zend_extension line to the php.ini file. Cleaner way of enabling Xdebug and then configuring it is to add a file xdebug.ini to /etc/php5/conf.d/ folder with the following contents:

;xdebug configuration
zend_extension = /usr/lib/php5/20090626/
xdebug.remote_host =
xdebug.remote_enable = 1
xdebug.remote_port = 9000
xdebug.remote_handler = dbgp
xdebug.remote_mode = req

This xdebug.ini will be picked up by both CLI and Apache and makes it easier to control without messing with the central config file.
Once apache is restarted and xdebug succesfully loaded, time to look at phpStorm’s side.

Step 3. Get Xdebug helper extension for Chrome or similar for Firefox is very handy. Get one so you can enable/disable debugging sessions from the browser. Make sure you set it up such that is loads up on your local domain. For example, if your project runs on myproject.local, your setup will prob look like this:

PHPStorm Debugging Setup

This is a bit less straightforward, but here I go anyway. Here are my assumptions:
My project is running localy at http://myproject.local
It’s stored locally in /home/user/Projects/myproject/public ,which is also a DocumentRoot for myproject.local Vhost config in Apache. There are ‘library’ and ‘application’ folders outside of DocRoot however.

Step 1. In PHPStorm, setup path to web browser(File->Settings->Web Browsers). It actually detected all paths correctly except for Chrome, which I had to set manually(in my case it was in /usr/bin/google-chrome)

Step 2. Setup run configuration – Run->Edit Configurations. That screen is kinda odd, but here is how I got it going.
* Create new configuration, with type PHP on Server

* Create new server(click on the button next to “Server” dropdown). I picked server type “Local” and set webroot to “http://myproject.local“. On the “Mappings” tab I set local path to /home/user/Projects/myproject/public
* Save that server and select it in the Run Configurations
Ultimately my config looked as following:

This looks like it. Now opening up a file inside that project and ‘running’ it will actually bring up a new Chrome window with a page and put PHPStorm in listening mode on port 9000 for Xdebug connections. You’ll need to activate ‘Xdebug helper’ in that window, after that all interactions with the server will be intercepted by Xdebug and PHPStorm.

XDebug doesn’t show local variables in Komodo, NetBeans or Eclipse PDT

Lovely surprise that came sometime after upgrading Lucid Lynx(and thus to PHP 5.3.2) – Xdebug doesn’t show local variables. Fortunately that’s a known issue that is fixed in Xdebug 2.1.0RC, but since it’s not released, it is not yet in Ubuntu’s repository. This should be pretty easy to fix though :) let’s try this:

sudo apt-get install php5-dev php-pear

That’ll get us ready for manual xdebug building. Then we need to get the sources. Gotta tell you, Xdebug guys are pretty awesome – they put together this nice little tool that helps you find and build the right version:

It requires output of phpinfo() or in ‘php -i’ command and based on that gives you set by step instructions.

For standard Lucid Lynx install it boils down to the following commands:

tar -xvzf xdebug-2.1.0RC1.tgz
cd xdebug-2.1.0RC1
sudo cp modules/ /usr/lib/php5/20090626
sudo /etc/init.d/apache2 restart

Before restarting the server though(last command) you may want to double check the the following line exists in either /etc/php5/apache2/php.ini or in /etc/php5/apache2/conf.d/xdebug.ini

zend_extension = /usr/lib/php5/20090626/