Install XDebug – the quick and painless way

If you find that you need to compile xdebug from source for whatever reason, have no fear! It’s actually quite simple to get it set up and running. I can get it set up on most servers in under 5 minutes. The directions below are for a local environment.

Make sure that you haveĀ git installed, since we are going to be grabbing xdebug from their git repository.

git clone git://github.com/xdebug/xdebug.git

Now just go into the directory you just downloaded.

cd xdebug

Now run the following commands (NOTE: if you you get a message that phpize is not a valid command try installing php5-dev or php5-devel):

phpize
./configure
make
sudo make install

Now you will have a file in modules called xdebug.so. Copy this to anywhere that you feel makes sense. I usually copy it to /etc/php.d or similar.

sudo cp modules/xdebug.so /etc/php.d/xdebug.so

Now edit your php.ini file. If you’re not sure where to find it run locate php.ini. Add this to the very bottom.

zend_extension = "/etc/php.d/xdebug.so"
xdebug.default_enable=1
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_autostart=0
xdebug.remote_log=/var/log/xdebug/xdebug.log

If you want pretty var_dump(), you can also add these:

xdebug.var_display_max_children=-1
xdebug.var_display_max_data=-1
xdebug.var_display_max_depth=-1

In order for the pretty var_dump to work, you also need to set html_errors to “On”. So look for that in your php.ini file and set it to On. If it’s not in there you an add this line:

html_errors = On

Restart your web server and php-fpm if you use it. Check that everything is working properly using this command:

php -i | grep xdebug