Actions

Configuring Xdebug for PHP development/Linux

From Joomla! Documentation

< Configuring Xdebug for PHP development
Revision as of 01:42, 15 October 2012 by Enav (Talk | contribs)

Documentation all together tranparent small.png
Under Construction

This article or section is in the process of an expansion or major restructuring. You are welcome to assist in its construction by editing it as well. If this article or section has not been edited in several days, please remove this template.
This article was last edited by Enav (talk| contribs) 20 months ago. (Purge)

Quill icon.png
Page Actively Being Edited!

This article is actively undergoing a major edit for a short while.
As a courtesy, please do not edit this page while this message is displayed. The user who added this notice will be listed in the page history. This message is intended to help reduce edit conflicts; please remove it between editing sessions to allow others to edit the page. If this page has not been edited for several hours, please remove this template, or replace it with {{underconstruction}} or {{incomplete}}.

Contents

Theses instructions should work fine on any Debian based distribution such as Debian, Ubuntu, LinuxMint, Xubuntu, Kbuntu and others.

Xdebug is an extension which provides debugging and profiling capabilities, it runs in the server side and send the debugging information to any client capable of receive and read it, for this article we will install Xdebug in our local server and use Eclipse IDE as the client who will receive and interpret the debugging information. Whit Xdebug you will be able to study the behavior of your code step by step and also inspect the value of the all the variable at every execution step.

Installation

There are several ways to download and install Xdebug to your Linux box, you can do it from your software center, terminal or manual download.

Method 1: From a Linux repository

NOTE: This method is the most you will updates and security patches automatically.

Option 1: Terminal

  • Open your terminal and type
 sudo apt-get install eclipse 
  • Wait until the installation process finish

Option 2: Software center

  • Open the software center that comes with your distribution
  • Type in the search box "Eclipse IDE"
  • Select "Eclipse IDE" in the search result list
  • Click on the "install" button
  • Wait until installation processes finish

Method 2: From a downloaded copy

  • Visit this page here and download the most recent version available
  • Do a double click on the downloaded file, your package manager should do the rest of the work automatically

http://packages.debian.org/sid/php5-xdebug

Configuring Xdebug

  • Open your terminal and type
 sudo gedit /etc/php5/conf.d/xdebug.ini 
  • That command should open the text editor with the Xdebug condifuration file
  • At the end of the file content append the following text
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000

  • Save changes and close the editor
  • In you teeminal type
sudo service apache2 restart

Configuring Eclipse IDE

  • Open Eclipse IDE
  • On Eclipse go to: "Toolbar --> Window --> Preferences --> PHP --> Debug"
  • Find the option: "PHP Debugger" and set it to "Xdebug"
  • On Eclipse go to: "Toolbar --> Window --> Preferences --> PHP --> Debug --> Installed Debugger"
  • In the list make sure the port the "Xdebug" option is set to the value "9000"
  • Save changes

When a PHP project is being debugged the PHP code execution is stopped at any break point the user sets, by default this action opens up the Eclipse IDE internal browser to display the web page itself, and resulting html output. if you wish to not use the Eclipse IDE internal browser for any reason, you can always use an external browser such as Google Chrome, Chromium or Firefox to browse your page in debugging time.

To set up a different web browser follow these steps if you are OK with the Eclipse internal browser skip this part:

  • On Eclipse go to: "Toolbar --> Window --> Preferences --> General --> Web Browser"
  • Make sure the option "Use external browser" is selected
  • If your preferred browser is on the list, select it and save changes and skip the rest of this part
  • If your preferred browser is not on the list press the button "New"
  • Set a name for your new browser i.e. "chrome"
  • Set the location of your new browser i.e. "/usr/bin/google-chrome"
  • If you don't know the location of the browser open a terminal and use the command "whereis browsername" to display the browser location. Note: Replace browsername with the name of your preferred browser i.e. "whereis google-chrome" copy one of the locations if there is more than one
  • Save all changes

Testing Xdebug and Eclipse IDE

To test our brand new debugger we need to create a little Eclipse PHP project, set the debug configuration for our project and write some few lines of PHP code. This example assumes that you understand the Eclipse IDE concepts of "workspace" and "projects", if you don't, pleas read this document Configuring Eclipse IDE for PHP development/Linux#Understanding the folder structure, also for this example we will use the site web root folder as our workspace, so Eclipse IDE and the web server files share the same location for our development purposes and easy testing.

  • Open Eclipse IDE
  • On Eclipse go to: "Toolbar --> File --> New --> Other --> PHP --> PHP Project"
  • Press "next"
  • On the "Project name" set the value to "xdebug-test" or any other name you like for our test project

A