본문 바로가기
프로그램 (PHP,Python)

XAMPP + Eclipse 이용한 PHP 디버깅 (XDebug)

by 날으는물고기 2009. 6. 9.

XAMPP + Eclipse 이용한 PHP 디버깅 (XDebug)

XAMPP 에 포함되어 있는 XDebug 를 이용해서 이클립스에서 편하게 디버깅 할 수 있도록 설정하는 방법입니다. 설정이 그리 어렵지 않지만 몇가지 문제때문에 어려워하는 분들이 계실까봐 글을 남깁니다.

보통 웹프로그래밍을 할때에는 작성 후 브라우저를 통해 결과를 확인하는 작업을 하게 되는데, 이클립스를 통해 디버깅을 하게되면 이클립스 하단에 바로 결과값이 나와 개발의 효율과 편의를 도모할 수 있습니다.
단, XDebug 는 ZendOptimizer 와 함께 사용할 수 없습니다. 개발을 위해 주로 로컬 서버에서만 사용할 목적이기 때문에 Zend 를 사용 못하는건 그리 큰 문제가 되지 않으리라 생각됩니다.

XAMPP 는 현재 1.7.1 버전까지 나와 있으며 XAMPP 다운로드 사이트에서 받을 수 있습니다. (해당 페이지에서 자신의 OS 에 맞는 버전을 선택해서 설치하면 됩니다. 설치버전/무설치버전/무설치,무설정 버전을 골라 받으세요.)

※ 이 글은 디버깅 설정 방법이 목적으므로, XAMPP 설치나 php.ini 설정 방법 등 자세한건 다루지 않습니다.
※ 아래 예에서 경로 입력시 각자 자신이 설치한 경로에 맞게 수정해서 설정하시기 바랍니다.

  1. php.ini 파일을 열어 설정을 변경해야 합니다. (중요!)
    extension 설정하는 부분에서 php_xdebug.dll 이 있는데 혹시 세미콜론(;)을 제거해서 로드하신 분은 앞에 세미콜론을 붙여주세요. (주석처리 하여 사용하지 않는것입니다.)

    ;extension=php_xdebug.dll


    php.ini 파일 끝 부분에 위치한 Zend 와 XDebug 설정을 찾아 아래처럼 바꿔줍니다.

    [Zend]
    ;zend_extension_ts = "D:\Server\xampp\php\zendOptimizer\lib\ZendExtensionManager.dll"
    ;zend_extension_manager.optimizer_ts = "D:\Server\xampp\php\zendOptimizer\lib\Optimizer"
    ;zend_optimizer.enable_loader = 0
    ;zend_optimizer.optimization_level=15
    ;zend_optimizer.license_path =


    [XDebug]
    ;; Only Zend OR (!) XDebug
    zend_extension_ts="D:\Server\xampp\php\ext\php_xdebug.dll"
    xdebug.remote_enable=true
    xdebug.remote_host=127.0.0.1
    xdebug.remote_port=9000

    ;xdebug.remote_handler=dbgp
    ;xdebug.profiler_enable=1
    ;xdebug.profiler_output_dir="D:\Server\xampp\tmp"


    ※ XDebug 에서 프로파일링을 사용하려면 아래 xdebug.profiler_* 의 앞에 세미콜론을 없애고 경로를 올바르게 지정하면 됩니다.
     

  2. eclipse 에서 디버깅 설정을 해준다.
    1. 'Run > External Tools > External Tools Configurations...' 선택

       
    2. 'Program' 을 선택, 더블클릭 하거나, 화면 왼쪽 상단에
       새로 추가 아이콘을 선택.

      아래에서 경로는 PHP 가 설치된 폴더를 선택하면 됩니다.

      Location : D:\Server\xampp\php\php.exe
      Arguments
      : -f "${resource_loc}" -c "D:\Server\xampp\php\php.ini"


      클릭하면 더 크게 볼 수 있습니다.
       

쉽게 설정이 완료되었습니다.
Run 버튼을 눌러 실행해보면 화면 하단부 'Console' 창에 결과가 나옵니다.

※ 주의할점은 프로젝트에 포함된 파일이 아니라면 디버깅시 이클립스에서 오류가 납니다. =_=


아래는 일부러 오류를 만들어 디버깅 한 장면 입니다.

디버깅한 장면



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

You need:

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


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

 

  • 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.

출처 : http://smwforum.ontoprise.com/
728x90

댓글