PHP PORTABLE IDE: Notepad++ XDebug 2
US PHP IDE : Introduction | Notepad++ | Install PHP | NppExec Config | PHP extensions | Run Menu | XDebug 1 | Debugging 1 | XDebug 2 | Debugging 2
|
|
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).
|
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.
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.
- Download XDebug 5.3 VC6 (32 bit) (php_xdebug-2.1.0-5.3-vc6.dll) and 5.3 VC9 (32 bit) (php_xdebug-2.1.0-5.3-vc9.dll)
- Save to folder C:\us_portable_ide_temp - Any temporary folder will do
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
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] 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.
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.
Notepad++ DBGp client configuration
Configuring the DBGp client is straight forward. Steps shown below:
|
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
Closing Notepadd++ saves these new windows positions. Next time Notepad++ is run console and debugging widows remain un-docked. |
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.
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.