상세 컨텐츠

본문 제목

Debugging XAMPP PHP Eclipse : 디버깅 하기

개발

by 동동주1123 2009. 4. 6. 11:31

본문




HowTo Debug PHP on XAMPP with Eclipse using PDT (recommended)

You need:

  • Eclipse 3.3
  • PDT
  • Zenddebugger
  • Web Standard Tools
  • XAMPP


  • Install the Debugger following the instructions of the readme.
 
Zend Debugger installation instructions
---------------------------------------

1. Locate ZendDebugger.so or ZendDebugger.dll file that is compiled for the
correct version of PHP (4.3.x, 4.4.x, 5.0.x, 5.1.x, 5.2.x) in the
appropriate directory.

2. Add the following line to the php.ini file under [DEBUGGER] tag:
Linux and Mac OS X: zend_extension=/full/path/to/ZendDebugger.so
Windows: zend_extension_ts=/full/path/to/ZendDebugger.dll
Windows non-tread safe: zend_extension=/full/path/to/ZendDebugger.dll

(*) the windows non-thread safe is used only with Zend Core 2.0

3. Add the following lines to the php.ini file:
zend_debugger.allow_hosts=<ip_addresses>
zend_debugger.expose_remotely=always

4. Place dummy.php file in the document root directory.

5. Restart web server

6. Example for php.ini
[DEBUGGER]
zend_extension_ts=D:\workspace\projekt\XAMPP\php\ZendDebugger.dll
zend_debugger.allow_hosts=127.0.0.1/192.168.1.100
zend_debugger.expose_remotely=always
  • Check if phpinfo(); outputs something about the zenddebugger.
  • Install PDT following the instructions on the eclipse project page.
  • Open Debug Dialog in Eclipse and make a new configuration for PHP Web Page similar to this one

Image:Phpwebpage.png

  • Debugging using the internal browser should now work.
  • For external Browsers open Preferences->General->Webbrowser and add Firefox and Internet Explorer
  • Switch to the desired browser at "Window"->"Web Browser" and start a debug session, the external browser should now open



HowTo Debug PHP on XAMPP with Eclipse using PHPeclipse

What you need

(The versions in brackets has been used for this HowTo)

  • Eclipse 3.2 (3.2.1)
  • PHPEclipse-Plugin 1.1.9 ( CVS-Snapshot net.sourceforge.phpeclipse_1.1.9.CVS-20060920.bin.dist.zip)
  • DBG 2.13.1 (dbg-2.13.1-win32.zip)
  • XAMPP 1.5.2 (xampp-win32-1.5.2.zip)

PHPEclipse Version 1.1.8 will only work with Eclipse 3.1
DBG is only avaible freely for PHP Versions up to 5.1.2 therefore an older XAMPP with the proper Version is used.

Where to get it

The proper PHPEclipse, DBG, XAMPP installation files can also be downloaded from Link2 [ file://Link2/software/PHP ]

Install xampp and dbg

  • Extract the xampp-files
  • Extract the DBG.
  • Make a new directory at xampp/apache/bin/ named extensions
  • Copy php_dbg.dll-5.1.2 to xampp/php/ext/ and rename it to php_dbg.dll
  • Open the xampp/apache/bin/php.ini for editing
  • add "extension=php_dbg.dll" to the dynamic extension section
  • comment out the zend-conguration complety (should be at the end of php.ini)
  • add the following dbg-config to the end of php.ini so the debugger will be enabled

[dbg]
debugger.enabled = On

  • Create a info.php at xampp/htdocs with the following content:

<?php
phpinfo();
?>

  • open http://127.0.0.1/info.php in you browser and check if there is a dbg section in the output with "debugger.enabled On"
  • If yes everything is fine and the debugger should work

Install PHPEclipse and set up a PHP-Project

This is a slighty changed Version of [5]

  • Extract the PHPEclipse and copy the files to your local eclipse
  • File->New->Project... and select PHP Project
  • deselect "Use default location" and choose a path at pathto/xampp/htdocs/ e.g. pathto/xampp/htdocs/php
  • Create a new PHP File (e.g. test.php) in this Project and add this example code

<?php
$msg = "This is a message";
$aThings = array('one', 'two', 'three');
foreach ($aThings as $value) {
print $msg . ' - ' . $value . ' ';
}
?>

  • Go to "Debug..." and set up a new Config at "PHP DBG Script"
  • Choose the "php enviroment" tab and select the pathto/xampp/php/php.exe as intepreter, select "remote debugging" and deselect "Open with DBGSession...".
  • Now start this Debug-Configuration and look in the debug-view which port is set (e.g. PHP Debugger at localhost:10001)
  • Set a breakpoint and open "http://localhost/php/test.php?DBGSESSID=1@localhost:10001" with your browser
  • Switch back to Eclipse and look of Eclipse stopped at you breakpoint
  • Voilà. That's all.
  • Note: It's not possible to debug a php file which is included by a symbolic link in the eclipse workspace. That means it's best to put a project inside apache's public dir and add all the php files here you want to debug. Sometimes the debugger does not stop at breakpoints. There are still some bugs in it. A possible workaround which is working for me is to put a DebugBreak(); statement in the code instead of a breakpoint. Another thing is the DBGSESSID in the URL. If it does not work properly change the ID for each debug session. (simply count it up)

Debugging Mediawiki

  • Create new PHP-Project, but deselect the "Use default location" and choose your wikipath (e.g. C:\xampp\htdocs\wiki
  • Start the debugging session with the index.php file (e.g. http://127.0.0.1/wiki/index.php?DBGSESSID=1@localhost:10001). Breakpoints in other php-files used in Mediawiki will be recognized.

관련글 더보기