This post summarizes the steps to setup debugging using Xdebug for PHP in PHPStorm 6 (one of the best PHP IDE). This post is a more comprehensive version of this previous post.

This post is for Linux environment

1. Install Xdebug

Xdebug can be installed from the PECL repository, which is part of PEAR. PECL required php5-dev package. Use the following commands to install these prerequisites:

sudo apt-get install php5-dev
sudo apt-get install php-pear

Afterwards, Xdebug can be installed via PECL:

sudo pecl install xdebug

When installation is done, PECL will output where Xdebug is installed as follows:

Build process completed successfully
Installing '/usr/lib/php5/20090626/xdebug.so'
install ok: channel://pecl.php.net/xdebug-2.2.1
configuration option "php_ini" is not set to php.ini location
You should add "extension=xdebug.so" to php.ini

Modify your php.ini accordingly. My php.ini is located at /etc/php5/apache2/php.ini. I added the following lines to the end of my php.ini.

zend_extension=/usr/lib/php5/20090626/xdebug.so
[xdebug]
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_port=9000

Restart Apache

2. Modify PHPStorm Settings

Go into Files -> Settings -> Click on PHP. Select an interpreter. The screen should look like follows.

PHPStorm6-PHP-Settings

Click on ‘…’ for Interpreter. The Interpreters window shows up (see below). Click on the green +, and an interpreter. Choose Xdebug for debugger and click OK.

PHPStorm6 Add Interpreter

Click on Debug in the Settings Window. The settings should match what you get back from installing Xdebug.

PHPStorm-PHP-Debug-Settings

Click on Apply button and OK.

3. Debug Configuration

Go into Run -> Edit Configurations.

Screenshot-Run-Debug Configurations

Click on the “green plus” and select PHP Web Application

Next to Server, click on the “…” button and servers settings shows up. Click on the green plus to add a server setting. Use the following settings:

  • Name: can be anything
  • Host: localhost
  • Port: 80
  • Debugger: Xdebug

Screenshot-PHPStorm-Servers

Click on OK

Back in the Run/Debug Configurations window, change the Start URL to the URL of your application (see figure above), and click OK.