Introduction
This article only covers the processes to install Notepad++ and Notepad++ DBGp plugin debugger for debugging PHP scripts.
How does the DBGp Plugin work
The web browser requests url through the http port (80) to the Apache server.
XDebug is an Apache extension (dll), like GD2 graphic library or so…
XDebug is an interface betweeen the server (Apache) and a remote debugging client (DBGp Plugin), they communicate through another port (9000).
Web browser <==> Port 80 <==> Apache + PHP + Xdebug extension <==> Port 9000 <==> DBGp Plugin-notepad++
- Notepad++ is started, DBGpplugin opens socket 9000
- Web browser requests a PHP page from Apache server. This request includes in the url a specific parameter to start remote debugging (XDEBUG_SESSION_START).
- Web server (Apache) fires up the PHP interpreter
- PHP interpreter loads XDebug module.
- XDebug module detects the specific parameter and starts remote debugging…
- XDebug connects to the “remote” debugging client (depending on xdebug configuration)
- XDebug and debug client are connected, with user interaction, commands and data are sent over the debugging port (9000)
- When debug client instructs XDebug to execute one or more php statements, PHP code is executed and possible output is sent over http Port (80) to web browser.
- When all instruction of php are executed, XDdebug disconnects from client.
- Apache closes connection to browser.
Installation steps
You should install Apache and PHP on your own (WinLamp is a good package for Windows, but there others like Xampp, you can also install Apache + PHP without a ‘package’…). For reference purpose, my PHP module is in the C:\WebServer\Apache2\modules\php directory (it may be different with others Apache + PHP packages).
1. Download the npp.X.Y.Installer.exe (V4.3 or higher) to your hard drive.
2. Double click the npp.X.Y.Installer.exe on your hard drive to install Notepad++ onto your computer. The default installation directory is C:\Program Files\Notepad++\.
3. Download DBGP plugin to your computer. It is a zipped file.
6.Unzip the file and move the dbgpPlugin.dll and README.txt to C:\Program Files\Notepad++\plugins. Be sure to read the Readme.txt for the latest information.
7. Create a php file name phpinfo.php with the following lines in it:
<?php phpinfo(); ?>
8. Load the phpinfo.php in your server. For me, that is: http://localhost/supplier/phpinfo.php. Check the php version number at the top of the page. My PHP is version 5.1.4 Also pay attention to your php.ini location. My php.ini is at: C:\WebServer\Apache2\modules\php\. Also look for your php extension directory under the Configuration – PHP Core section (you can search extension_dir). For my php, it is: C:\WebServer\Apache2\modules\php\ext\.
9. Go to http://www.xdebug.org/ to download the Xdebug Windows module for your PHP version. For me, that is PHP 5.1.2 – 5.1.6. The file is php_xdebug-2.0.0-5.1.6.dll.
10. Move the php_xdebug-2.0.0-5.1.6.dll to your php extensions directory (C:\WebServer\Apache2\modules\php\ext\ or anything else according to your extension_dir parameter in your
php.ini configuration file)
11. Open your php.ini file in any text editor and add the following lines to, just below the Windows extensions section (you can put it anywhere in the file)
zend_extension_ts="C:/WebServer/Apache2/modules/php/ext/php_xdebug-2.0.0-5.1.6.dll" xdebug.remote_enable=1 xdebug.remote_handler=dbgp xdebug.remote_host=127.0.0.1 xdebug.remote_mode=req xdebug.idekey=default xdebug.remote_log="D:/www/ourcommunity.dev/log/xdebug.log" xdebug.remote_port=9000 xdebug.show_exception_trace=0 xdebug.show_local_vars=9 xdebug.show_mem_delta=0 xdebug.trace_format=0
10. Change “C:/WebServer/Apache2/modules/php/ext/php_xdebug-2.0.0-5.1.6.dll” to your extension folder and filename. Change “D:/www/ourcommunity.dev” to your application directory.
11. Reboot your computer (the easiest way to restart apache and other programs).
Nota Bene : If your Apache Server doesn’t restart, perhaps you’ll have to comment the line of the Zend Optimizer (I had to do this)
;zend_extension_manager.optimizer_ts = "C:\xampp\php\zendOptimizer\lib\Optimizer"
12. Load the phpinfo.php file again (http://localhost/supplier/phpinfo.php). You should see the Xdebug section in the phpinfo page.
13. You should see the DBGp menu shows up in the Notepad++ plugin menu.
14. Click the “Config…” item and configure the DBGp debugger as shown (the Remote Path and Local Path is the folder where your php files resides.
15. Create a test file, debugTest.php with the following lines in it :
<?php for ( $i=1; $i<10; $i++) { echo "<br>Line $i"; } ?>
Click Debugger under the Plugin -> DBGp menu to open the Debugger window at the lower section. Add a breakpoint on line 2 (click on the 2nd line and on the BreakPoint button, the one with a red point).
16. Make sure that you can load the debugTest.php with http://localhost/supplier/debugTest.php and it should show as below.
17. Add “?XDEBUG_SESSION_START=session_name” to the end of the url in the browser. Now the browser request is: http://localhost/supplier/debugTest.php?XDEBUG_SESSION_START=session_name (you can specify whatever session_name you want : test, dummy…)
You should see the Notepad++ icon on the taskbar blinking. If you open it up, the DBGp debug window comes to live. You can use the DBGp toolbar to step into, step over and step out and run the code.
18. To see the global and local variables, select “Refresh local context on every step” and “Refresh global context on every step” in the DBGp configuration (Plugins/DBGp/Config… Np++ menu). It should be similar as the picture shown below.
19. Now you can see the global variables at the lower left hand corner. To access local variable in the program, select the variable then hit CTRL-F7. This put the selected variable into the Eval window. Click OK will show the current value of the variable, as shown below.
That is it. Good luck with your PHP project.
Special thanks to Damjan Cvetko (zobo) for answering my questions on setting up the DBGp on SourceForge.net. See the SourceForge.net Forumfor detail discussion:
Reference
- Remote Debugging with Xdebug
- essay help mastering writing skills
- custom essay written professionally
As of xdebug 2.0.5-5.3-vc6 AND PHP 5.3 the parameter (maybe relevant for php 5.2 as well):
zend_extension_ts =
should be changed to:
zend_extension =
Hi
your plugin is really great! at work we are many developpers to work on the same server, is there a way to configure the plugin for connecting on another port but 9000, like 9017 for example?
greetings, nicolas
I know this might be a bit off topic but seeing that a bunch of you own websites, where would the best place be to host? Someone recommended I use Blue Host for $6.95 a month which seems like a great deal. Anyone here on http://www.judiwa.com/2010/03/27/how-to-setup-bdgp-debugger-in-notepad-to-debug-php/ using them?
Orizen: depends on if you have ThreadSafe (TS) PHP installation or not.
Nicolas: There is a way. Find the dbgp.ini file and add a “listen_port” under “Misc” section. I should probably add a config interface for this.
Best
-Zobo
PHP is a tool that allows your website to have functionalities for business purposes. If you want to improve and upgrade, you can always get the services of a PHP programmer.