`
wbj0110
  • 浏览: 1604410 次
  • 性别: Icon_minigender_1
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论

XDebugPHP in Ubuntu using Eclipse

    博客分类:
  • php
阅读更多

This guide walks you through the necessary steps to configure the Eclipse IDE for PHP debugging. This can be very handy, especially when you’re trying to resolve an issue in a complex PHP application or plug-in.

Things you’ll need

  • Eclipse
  • Eclipse PHP Development Tools (PDT)
  • Xdebug
Assumptions
This article assumes that you are configuring Eclipse and Xdebug for development on a localhost web server. If you are not, be sure to make appropriate adjustments to accommodation your needs. Likely the only changes you will need to make will be differences in connecting to your server verses localhost.

Quick Overview

For those that are unaware, Eclipse is a very popular IDE for developing in Java. However, Eclipse is much more powerful than that and can in fact easily be used for developing in many other languages including PHP.

Xdebug is a brilliant debugging extension designed for use with PHP. Once configured, Xdebug will allow you to remotely connect to your web server… or in my case connect to my development localhost web server. Rather than using crude echo and logging techniques to debug your PHP code, Xdebug allows you to literally step through and inspect values and function flows in real-time.

If you’ve ever scratched your head at a PHP script and thrown in dozens of echos or logging statements to track the execution path then you’ll really come to appreciate the benefits of using Xdebug.

Configuring Eclipse and Xdebug isn’t difficult. In fact its painless with the correct steps on hand. That’s where this guide comes in. I found myself coming across incomplete or outdated forum posts and stackoverflow questions, so I thought I’d post what worked for me.

If you already have Java and Eclipse installed, then just jump ahead to installing and configuring the PHP Development Tools and Xdebug.

Install Eclipse

This will install ~118 new packages, assuming you’ve not already installed some of them, and will total around 255 MB that need to be downloaded.

  1. Open a terminal and enter the following command to install Eclipse:
    sudo apt-get install eclipse

     

     

  2. After the download completes, open Eclipse to confirm that it installed correctly. Leave it open for our next install.
 

Install PHP Development Tools (PDT)

  1. If you don’t have Eclipse open at this point, open it up.
  2. Navigate through the menus to: Help -> Install New Software…
  3. You will be prompted with a new window asking you to select a site or enter the location of a site. You should be able to drop down the list of sites and find one labeled “–All Available Sites–”. Select this option and wait for the list below to populate.

  4. Scroll through the list until you find a category labeled “Programming Languages” and click the arrow to expand this list.

  5. Continue to scroll through the Programming languages until you find a item labeled “PHP Development Tools (PDT) SDK Feature” and check the box to the left.

  6. Click Next and continue throw the installation. You’ll have to select that you agree to the terms of installing this software.
  7. After the installation has completed, you will be asked to restart Eclipse to apply changes. Go ahead and restart Eclipse, then move on to the next install.

 

Install XDebug

  1. Open a terminal and enter the following command to install Xdebug:


    sudo apt-get install php5-xdebug
     

  2. After installation completes, there are a couple of files that need to be configured. If you copy and paste the commands below, make sure to check that the quotes that are copied over are regular quotation characters, as they may cause problems if they are not.
    1. sudo gedit /etc/php5/conf.d/*xdebug.ini 


      zend_extension=/usr/lib/php5/20100525/xdebug.so

      xdebug.remote_enable = 1
      xdebug.remote_handler = “dbgp”
      xdebug.remote_host = “localhost”
      xdebug.remote_port = 9000 

    2. sudo gedit /etc/php5/apache2/php.ini 

      Scroll to the bottom and add:

      zend_extension=/usr/lib/php5/20100525/xdebug.so

       

  3. Restart your Apache server so that the new PHP configuration settings are loaded.

    sudo /etc/init.d/apache2 restart

     

  4. Confirm that your Xdebug installation was successfully loaded by creating a simple PHP file called “phpinfo.php” and placing it in the public root of your Apache web server. Be sure to include the following in your file, save it then navigate to it in your browser:

    <?php phpinfo(); ?>

     

  5. After loading the php info page, search for “xdebug”. If you find it listed, then you have successfully installed and configured Xdebug. If not, check back over the steps listed above or consult Google.
 
Configuring your Eclipse project to connect to Xdebug
After you’ve finally gotten everything installed, you’re probably anxious to start debugging. You’re not far off. The only thing that’s left is to import your PHP script or site and establish a Debug Configuration for your project.
To import a site, simple select: File -> New -> Project… -> PHP -> PHP Project. This will open a new window where you can open PHP files from and existing location. Assuming this location is in your public root directory in Apache, you can work with these scripts in real-time.
After importing these existing files, right click on your new project and select: Debug As -> Debug Configurations…
Make sure that you’ve selected Xdebug as the Debugger type. Click Apply and then Debug. This will open a “Debug” perspective in Eclipse, allowing you to view variables and stack traces live. Assuming you’ve created a breakpoint or selected to break at the first line of the file, you should now see your PHP script paused waiting for you to debug!
 
Tip: If you’re planning to debug a large project such as a WordPress, phpBB, vBulletin or any other large web application, pointing the Debug Configuration to your index.php makes debugging much easier.
 
Done
Congrats! By now you should be beginning a new road to a much easier life of PHP development.
If you have any questions, comments or suggests feel free to let me hear them below! I’ll try to help where I can, but I can guarantee I’ll know how to solve any of the issues you may encounter. 
分享到:
评论

相关推荐

    ubuntu 下eclipse CDT搭建交叉编译开发环境

    ubuntu 下eclipse CDT搭建交叉编译开发环境 本文将详细介绍如何在ubuntu平台下使用eclipse CDT搭建交叉编译开发环境,包括准备相关软件安装包、安装软件包、应用程序编译、导入现存的makefile project、Qt 插件安装...

    ubuntu_eclipse启动设置,jdk环境变量,其他设置

    在Ubuntu系统中,Eclipse是一款广泛使用的集成开发环境(IDE),尤其适合Java开发。要成功启动Eclipse并进行有效的开发工作,需要确保JDK(Java Development Kit)已正确安装并且环境变量配置妥当。本文将详细讲解...

    ubuntu 16.04 安装 eclipse教程和总结

    ### Ubuntu 16.04 下 Eclipse 的安装与配置教程 #### 一、前言 随着软件开发领域的不断发展,集成开发环境(IDE)已经成为开发者不可或缺的工具之一。Eclipse 是一款非常受欢迎且功能强大的开源 IDE,它支持多种...

    Ubuntu中eclipse的安装

    Ubuntu中eclipse的安装 在Ubuntu系统中安装eclipse是一个非常重要的步骤,特别是在进行大数据处理和开发时。下面将详细介绍如何在Ubuntu系统中安装eclipse。 首先,需要从eclipse官网下载eclipse文件包。可以...

    Ubuntu安装eclipse.txt

    Ubuntu安装eclipse.txt

    Ubuntu-eclipse安装

    Ubuntu环境下安装Eclipse详细教程 概述:本教程将详细介绍在Ubuntu环境下安装Eclipse的步骤,包括下载Eclipse、解压、添加面板启动器和添加到菜单等步骤。 知识点1:Eclipse的下载和安装 在Ubuntu环境下安装...

    解决ubuntu macbuntu eclipse 没有菜单栏.txt

    ### 解决Ubuntu Macbuntu Eclipse没有菜单栏的问题 在使用Eclipse集成开发环境(IDE)的过程中,有时可能会遇到菜单栏缺失的问题,特别是在Ubuntu系统上使用Macbuntu主题时较为常见。本文将详细介绍如何解决Ubuntu...

    Ubuntu下Eclipse中文乱码解决.docx

    "Ubuntu下Eclipse中文乱码解决" 在Ubuntu系统中使用Eclipse时,可能会遇到中文乱码的问题,特别是在将Windows下的工程导入到Linux下的Eclipse中时。这种情况下,中文字符可能会显示为乱码,影响开发工作的效率。这...

    ubuntu opencv eclipse 配置

    在Ubuntu操作系统上配置OpenCV与Eclipse集成开发环境是一个重要的步骤,对于计算机视觉和图像处理项目的开发至关重要。本文将详细讲解如何在Ubuntu环境下完成这一配置,并介绍OpenCV中的`cvThreshold`函数及其作用。...

    ubuntu eclipseIDE(开发环境)

    ### Ubuntu 下 Eclipse IDE 开发环境配置详解 #### 一、Ubuntu与Eclipse简介 - **Ubuntu**:Ubuntu 是一个基于 Debian 的 Linux 发行版,它以其用户友好性和强大的社区支持而闻名。Ubuntu 提供了一个稳定且功能...

    配置Ubuntu下Eclipse CC++项目的开发编译环境.pdf

    根据给定的文件内容,本文将详细介绍在Ubuntu操作系统下配置Eclipse C/C++开发环境的过程及相关知识点。Ubuntu是一种基于Debian的Linux发行版,因其开源和易用性,广泛用于桌面、服务器以及嵌入式系统领域。Eclipse...

    解决 Ubuntu Eclipse 代码浮层黑色背景问题

    解决 Ubuntu Eclipse 代码浮层黑色背景问题

    Ubuntu部署eclipse环境

    ### Ubuntu部署Eclipse环境知识点详解 #### 一、概述 在Linux环境下,特别是Ubuntu系统中部署Eclipse开发环境,对于Java开发者来说是非常重要的一步。本文档详细介绍了如何在Ubuntu上安装并配置Eclipse IDE,包括...

    Ubuntu下eclipse环境搭建

    在Ubuntu系统下搭建Eclipse开发环境主要是为了进行Android应用的开发,整个过程可以分为几个步骤,包括安装Java开发工具包(JDK)、安装Eclipse开发环境、安装Android SDK、安装Android开发工具(ADT)插件,以及...

    Ubuntu下使用Eclipse开发C/C++

    ### Ubuntu下使用Eclipse开发C/C++ 在Ubuntu环境下利用Eclipse进行C/C++开发,是一项常见且实用的技能。本文将详细介绍如何在Ubuntu系统中搭建并使用Eclipse CDT插件进行C/C++项目的开发。 #### 一、预备工作 ###...

    ubuntu eclipse qt插件

    在Ubuntu操作系统上,Eclipse是一款广泛使用的集成开发环境(IDE),尤其适合进行Java开发。然而,Eclipse不仅可以用于Java,还可以通过安装特定的插件来支持其他编程语言和框架,如QT。QT是一个功能强大的跨平台...

    Ubuntu+lamp+eclipse+xdebug+虚拟主机的配置

    ### Ubuntu + LAMP + Eclipse + Xdebug + 虚拟主机的配置详解 #### 安装LAMP环境 LAMP(Linux, Apache, MySQL, PHP)环境是在Linux系统上搭建Web服务的一种常用组合。在Ubuntu系统中安装LAMP可以通过简单的命令...

Global site tag (gtag.js) - Google Analytics