Your one-stop resource for debugging PHP applications.
Monitor This Page for Changes
and receive an email whenever a new debugger is added to this site.
This introduction to PHP debugging assumes you have a computer running a webserver that can execute PHP scripts. You will need such an environment. If not, please see XAMPP for details. If you have a webserver and a PHP server module running, and know how to find your way around your php.ini file and get the output from phpinfo(), you can skip this intro, and jump to Choosing a Debugger Module.
Here are a few things you need to know, before attempting to setup an environment for debugging PHP scripts.Getting Information about PHP.
You will need to get your PHP configuration information using the phpinfo() function.
Copy the following code to a file called php-info.php, and place it in your web server document directory. Make sure it is in a safe place not accesible to the public, as this could be a security risk. phpinfo() outputs alot of information that a hacker would like to see.
Load the php-info.php file into your web browser. You should see ALOT of php configuration information like in the screenshot below. This will help you install and configure the PHP debugger modules correctly.
Here is an exanple of what the first part of the output from phpinfo() looks like:
Note in the above example, the Xdebug module has been found and loaded by PHP.Finding your php.ini file.
php.ini is PHP's configuration file. You need to modify this file to configure PHP to use the DBG or Xdebug debugger modules.
Look at the above output from phpinfo(). Notice the sixth
Configuration file (php.ini) Path /usr/local/php-5.2.4/lib
This is where PHP is looking for it's php.ini configuration file.
The seventh entry down:
Loaded Configuration file /usr/local/php-5.2.4/lib/php.ini
tells you that PHP has found a php.ini file in this location. This is the active PHP configuration file. Any alterations to this file will affect how PHP works.
The reason PHP is looking in the above location for it's php.ini file is because I compiled PHP with the '--prefix=/usr/local/php-5.2.4' configure option, and the default location for php.ini when you compile PHP yourself is in --prefix/lib/, unless you specify another place where PHP is to look for it's php.ini file.
So if you are not compiling PHP yourself, and using a standard pre-compiled installation of PHP, then the php.ini file will be somewhere different. Other common locations for php.ini are:Configuration file (php.ini) Path /etc
Loaded Configuration file /etc/php.ini
The Apache PHP module only reads php.ini once when the server starts. To tell PHP to re-read the php.ini file to make any changes take effect, you will need to stop and start the server. A restart may not be sufficient. Stopping and starting the server always works.Finding your PHP extension modules directory.
When PHP starts, it looks for any dynamic modules that need to be loaded. These modules generally all live together in the 'extension modules' directory.
There are two configuration options in php.ini that instruct PHP where to look for loadable extension modules.
The first option is:
; Directory in which the loadable extensions (modules) reside.
; extension_dir = /path/to/your/php/extensions
extension_dir = /usr/local/php-5.2.4/lib/php/extensions/no-debug-non-zts-20060613
This is just the directory path to the extensions directory, without the names of the modules to be loaded. Standard modules are loaded by name with the 'extension=modulename.so' option, further down in the php.ini file.
The other extension loading directive is:
;zend parser extensions
xdebug.remote_enable = on
The zend_extension option usually contains the full path to the extension_dir directory, and the name of the module to be loaded. You need to know where these php.ini configuration options are in your php.ini file. Most modules are loaded as 'normal' extensions. Some modules, such as the Xdebug module, need loading as 'zend_extension' modules. Don't worry about this - it's all fully documented in the installation instructions on the forum.
Choosing a Debugger Module.
The next step is to decide which PHP debugger module to install. At the moment there are two choices - DBG or Xdebug.
My favourite is Xdebug, as it also uses the DBG protocol, which means it should be a nice drop-in replacement for DBG, but I have not tested this yet, except with ProtoEditor which works fine in DBG client mode with Xdebug 2.0.2.