Installing via Package ManagerIf your distro includes Xdebug in the package repositories, this is probably the easiest way to install it and keep it up to date. For Ubuntu:
sudo apt-get install php5-xdebugFor Arch:
sudo pacman -S xdebugThis will install into the default location for PHP extensions ie /usr/lib/php/modules/. You will need to enable the module by adding the following line to your php.ini if it's not already there:
Installing via PECLPECL is a part of PEAR, so install that first:
sudo apt-get install php-pearPECL also requires the PHP development libraries, which have to be installed separately on Ubuntu. On many distros, such as Arch Linux, you can skip this step.
sudo apt-get install php5-devNow you're ready to get Xdebug:
sudo pecl install xdebugThis will download and compile the Xdebug module. When it finishes successfully, it will tell you where the xdebug.so module was installed, which is fine, but it also tells you to to add a line in php.ini to enable the extension. This last part is automatically output by PECL whenever it's finished compiling a module, and in this case, it's not quite right: Xdebug must actually be loaded as a Zend extension not a regular one.
To do this, you must add the following line to php.ini:
zend_extension="/path/to/xdebug.so"Use the path that PECL gave when it had finished compiling xdebug, which will be something like this:
Configuring Line-by-line DebuggingIn order to enable debugging features such as stepping through code from your IDE, you'll need to configure Xdebug for remote sessions. Create the following section in the 'Module Settings' section within php.ini:
[xdebug] xdebug.remote_enable=on xdebug.remote_handler=dbgp xdebug.remote_port=9000Note that these settings assume you'll be debugging on the local machine, i.e. any address that resolves to 127.0.0.1 e.g. localhost. If you want to debug on another machine, specify it with the following additional line:
xdebug.remote_host=MACHINENAMECheck this page for a list of all of the Xdebug options that you can set in php.ini. Another thing you might want to get at this point is the 'easy Xdebug' Firefox extension as it allows you to enable and disable debug sessions from your browser (rather than just from your IDE).
Now restart your web server so that php.ini is reloaded. You can check it's installed correctly by looking for it in the output of phpinfo() as in the screenshot below.
Configure the IDENow we just need to make sure our IDE is set up to accept connections from Xdebug. The exact steps to follow will depend on the IDE you use.
NetbeansNetbeans should already be set up correctly:
Start the debugger with the Debug Project button on the toolbar:
EclipseGo to Window > Preferences, and select the Debug section within the PHP options (don't get confused with the separate Run/Debug options which we don't need to worry about here). Now select XDebug as your debugger. If you aren't using localhost for your development server, you can change that also. Leave the PHP Executable as it is, and click OK:
You can now start a debugging session from within Eclipse by right-clicking on a page, and choosing Debug As > PHP Web Page.