Eclipse PHP Debug
Jump to navigation
Jump to search
Eclipse for PHP
Get Eclipse classic version
<pre:> wget http://eclipse.c3sl.ufpr.br/eclipse/downloads/drops4/R-4.2.1-201209141800/eclipse-SDK-4.2.1-linux-gtk-x86_64.tar.gz tar -xzf eclipse-SDK-4.2.1-linux-gtk-x86_64.tar.gz ./eclipse/eclipse
- Workspace: "/home/MYHOME/eclipse/wtp" # check 'use this as the default'
Get PDT and WTP plugins
# open Eclipse # Help -> Install New Software # optionally uncheck 'Group items by category' to speed up the search # Work with: --All Available Sites-- # search for "pdt" # check 'PHP Development Tools (PDT) SDK Feature' # search for "web" # check 'Eclipse Web Developer Tools' # search for "javascript" # check 'JavaScript Development Tools' # search for "", clear the search field # click on 'Next >' button # click on 'Next >' button # accept the license # click on 'Finish' button # wait and restart Eclipse
Install Apache with PHP Xdebug component
su - root apt-get install apache2 php5-dev libapache2-mod-php5 php-pear pecl install xdebug find /usr/lib -name 'xdebug.so' # get the output, ex. /usr/lib/php5/20090626+lfs/xdebug.so nano /etc/php5/apache2/php.ini ### add this at the end of file ### zend_extension="THE OUTPUT OF LAST FIND COMMAND" xdebug.remote_mode="req" xdebug.remote_enable=On xdebug.remote_host="127.0.0.1" xdebug.remote_port=9000 xdebug.remote_handler="dbgp" ### end add ### /etc/init.d/apache2 restart exit
Create an external Project
chmod 777 /var/www/ # warning, involve security issues # open Eclipse # File -> New -> Project # choose PHP -> PHP Project # Project Name: "TestPDTDebug" # click on 'Finish' button # open the PDT perspective # ProjectExplorer -> TestPDTDebug -> New -> Folder # Advanced -> Link to alternate location -> "/var/www/TestPDTDebug"
Debug a PHP example
# ProjectExplorer -> TestPDTDebug -> TestPDTDebug -> New -> PHP File # File name: "index.php" ### add this in index.php ### <html> <body> <?php foreach ($_SERVER as $item_key => $item_value) { echo "_SERVER[" . $item_key . "] = " . $item_value . "<br/"; } ?> </body> </html> ### end add ### # Run -> Debug configurations # select 'PHP Web Application' # right click 'New' # Name: "TestPDTDebug_index.php" # File: "/TestPDTDebug/TestPDTDebug/index.php" # uncheck URL -> Auto Gerate' # Url: "http://localhost/" "/TestPDTDebug/index.php" # under 'Debugger' tab -> Server Debugger: XDebug # click 'Apply' # click 'Debug'