PHP PORTABLE IDE: Notepad++ XDebug 2

 

MPG UniCenter

Uniform Server Portable PHP IDE.

Notepad++ XDebug

Previous pages included set-up, configuration and debugging of PHP CLI scripts and WebPages.


This page provides a step-by-step guide for setting up XDebug and Notepad++ on Uniform Server to debug your PHP applications. It is assumed you are testing locally and all application are running on a single PC.

The guide is split across two pages; first covers installation while second provides basic debugging techniques.

Overview

Debugging a website running on a local server requires effectively a second server and client. This second sever and client taps into your prime server and web site providing debugging and control of that site and server.

The second server is created using a PHP extension (php_xdebug.dll) it seamlessly installs code to provide communication between Apache and a client (Notepad++ with DBGpplugin installed) over port 9000. In addition code is installed to monitor browser requests arriving on the standard Apache port 80.

Sequence of events

Assumes Uniform Server running (Apache server running).

  • Step A) Start Notepad++.
  • Step B) Notepad++'s client DBGp plugin opens socket 9000 (listens on port 9000)
  • Step C) In a browser enter address of PHP page to be debugged.
  • Step D) Browser requests this page from Apache server over port 80
  • Step E) Apache runs the PHP interpreter
  • Step F) PHP interpreter runs its extensions including the XDebug module.


  • Step G) XDebug module starts remote debugging.
  • Step H) XDebug connects to debugging client over port 9000


  • Step I) User uses client for debugging. Commands and data are sent over port 9000
  • Step J) Client can instruct XDebug to execute one or more php statements. Your PHP code is executed this may output data over http Port (80) to web browser.


  • Step K) When all your PHP code has been executed, XDdebug disconnects from client.
  • Step L) Followed by Apache closing connection to browser.

 

Note 1: Debugging is initiated from a browser. XDebug determines if the page is displayed in Notepad++ if not downloads it.

Note 2: If XDebug starts debugging a new age that page is download if not already displayed in Notepad++.

Note 3: During debugging browser shows page loading

Note 4: After step A) you can directly load, edit and save the page to be debugged. After enabling the debug client at step B) you can set breaks points and then imitate a debug session via the browser Step C. Next page covers this in more details.

Top

XDebug download and install

Xdebug is the extension for PHP that helps debugging PHP scripts by providing debug information for details see XDebug website.

Windows binaries are located on this download page

You can download either VC6 or VC9 versions of Uniform Server hence its worth downloading both VC6 and VC9 thread-safe binaries binaries of XDebug.

Install

Installing XDebug on Uniform Server is just a matter of copying the dll to extensions folder.

For example:

US 5.6.15-Nano

  • Copy file C:\us_portable_ide_temp\php_xdebug-2.1.0-5.3-vc6.dll
  • To folder <path>\UniServer\usr\local\php\extensions

US 6.0.5-Carbo

  • Copy file C:\us_portable_ide_temp\php_xdebug-2.1.0-5.3-vc9.dll
  • To folder <path>\UniServer\usr\local\php\extensions

Top

PHP Configuration file

On Uniform Server the following three files require editing:

  • UniServer\usr\local\php\php.ini
  • UniServer\usr\local\php\php.ini_delvelopment_nano
  • UniServer\usr\local\php\php.ini_production_nano

Add the following block at the end of each file:

[xdebug]
zend_extension=<full path to extention>/php_xdebug-2.1.0-5.3-vc9.dll
xdebug.remote_autostart=on
xdebug.remote_enable=on
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.idekey=default
  • Section [xdebug] loads and configures XDebug
  • Line: zend_extension= Loads the XDebug extension
  • Remaining lines configure XDebug to run automatically when a script is run.
  • Some lines set default values hence are not required. However leaving them in-place does no harm and makes it slightly clearer as to what is set and for what reason.

Section [xdebug] parameters

xdebug.remote_autostart=on

Default value: 0 (off) Normally you need to use a specific HTTP GET/POST variable to start remote debugging. When this setting is set to 1 (on), Xdebug will always attempt to start a remote debugging session and try to connect to a client, even if the GET/POST/COOKIE variable was not present.

xdebug.remote_enable=on

Default value: 0 (off) This switch controls whether Xdebug should try to contact a debug client which is listening on the host and port as set with the settings xdebug.remote_host and xdebug.remote_port. If a connection can not be established the script will just continue as if this setting was 0.

xdebug.remote_host=127.0.0.1

Default value: localhost Selects the host where the debug client is running. Use a host name or an IP address. This setting is ignored if xdebug.remote_connect_back is enabled.

xdebug.remote_port=9000

Default value: 9000 The port to which Xdebug tries to connect on the remote host. Port 9000 is the default. Many clients use this port number, it is best to leave this setting unchanged.

xdebug.remote_handler=dbgp

Default value: dbgp The DBGp protocol is supported by Notepad++ client.

xdebug.remote_mode=req

Default value: req Xdebug will try to connect to the debug client as soon as the script starts.

xdebug.idekey=default

Default value: *complex* Controls which IDE Key Xdebug should pass on to the DBGp debugger handler. The default is based on environment settings. First the environment setting DBGP_IDEKEY is consulted, then USER and as last USERNAME. The default is set to the first environment variable that is found. If none could be found the setting has as default .

Note:

The following function is useful for debugging

  • xdebug_break() it emits a break-point to the debug client.

Add the function to your script it makes the debugger break on the specific line as if a normal file/line break-point was set on this line. This function is covered on next page.

Top


Test Server Configuration

Check XDebug loads as follows:

  • Start Uniform Server
  • Click Administration Link
  • From menu on left click phpinfo() link
  • Scroll down you will see the following section
This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with eAccelerator v1.0-snv425, Copyright (c) 2004-2010 eAccelerator, by eAccelerator
    with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans <--- Confirms XDebug loaded

Ensure the last line is shown, confirms XDebug has been loaded.

Leave the server running.

Top

Notepad++ DBGp client configuration

Configuring the DBGp client is straight forward. Steps shown below:


  • Open DBGp configuration window Plugins>DBGp>Config...
  • Step A) Check Bypass all mapping (Local windows setup)
  • Step B) Check Refresh local context on every step
  • Step C) Check Refresh global context on every step
  • Step D) Check Break at first line when debugging starts
  • Step E) Click OK

 

Top

Docking Problem

There is a minor problem when opening both console and debugging windows. These are initially docked and overlap each other preventing access to tabs on the debugging window.

Solution

  • Start Notpad++
  • Step A) Click reduce size and resize application window so it fills top half of screen.


  • Step B) Click Debugger Opens debug window.
  • Step C) Left click on title bar (blue bar), keep mouse key pressed and drag away from Notepad++ edit window. Resize debug window as appropriate.


  • Step D) Click Show Console Dialog opens console widow.
  • Step E) Left click on title bar, keep mouse key pressed and drag away from Notepad++ edit window. Resize console window as appropriate.


Note:

Closing Notepadd++ saves these new windows positions. Next time Notepad++ is run console and debugging widows remain un-docked.

 

Top

Test Configuration

The following confirms correct operation:

  • Assumes Uniform Server running
  • With Notepad++ running open both console and debug windows as shown above.
  • In your browser either refresh admin page or enter http://localhost/index.php
  • Notepadd++ icon will flash.
  • The edit window will now contain index page or admin page
  • Debugging window displays various values.
  • Browser shows page continuously loading.
  • Close Notepad++ this breaks the connection and browser loads page

Apart from a few refinements our IDE is complete and ready for debugging scripts running on a server.

Top

Important Commonality

At this stage you will have noticed duplication between pages XDebug 1 and XDebug 2 this is intentional.

It emphases there is no configuration difference between running PHP on a server or as a CLI script. Apart from path to extensions folder the XDEBUG block is identical in both cases.

Configuration of Notepad++’s debugging client is also identical for debugging both CLI and server-side scripts.

Top

Summary

Top