Debugging PHP Using xdebug
xdebug is an open source debugger available for PHP. xdebug can be used to display more information in error traces. It can also be used to collect detailed code coverage & profiling information.
You need to install following packages to prepare environment for installation of pecl module xdebug.
sudo apt-get -y install php-pear php5-dev build-essential
Now we install xdebug using pecl.
sudo pecl install xdebug
Above command will download, compile & install xdebug on your system.
Open /etc/php5/apache2/php.ini and append following line.
Be careful about that number part in the path as it could be different for you. Now restart apache by issuing following command.
sudo apache2ctl restart
Now try to view the output of your phpinfo() function. If you find xdebug word in that then it means you have successfully installed xdebug.
xdebug.collect_params accepts values from 1 to 4. Where 1 refers to less verbosity & 4 refers to maximum verbosity while displaying stack traces. The easiest way of setting this option is using function ini_set in PHP.
ini_set("xdebug.collect_params", <verbosity level>)
Get to know more stack trace options of xdebug.
Once after installing xdebug when ever you call var_dump you are actually calling xdebug version of var_dump instead of built in one. By default xdebug version of var_dump gives you friendly info on the variables you are trying to inspect.
See more options on controlling display of var_dump information.
xdebug uses DBGp protocol to communicate with external debuggers. Vim already has a plugin to do that. So you can debug php scripts from within vim.
Download php debugger plugin for vim.