Configuring Xdebug for PHP development/Linux

From Joomla! Documentation

< Configuring Xdebug for PHP development
Revision as of 22:41, 14 October 2012 by Enav (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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 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 on any execution step.


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

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 this text

  • 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 give 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 code to do our test.

  • 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