Debugging With Eclipse and PHPdbg in Linux

Using a debugger to help find errors will save you a consider amount of time. Eclipse is a great IDE because not only is it platform independent, but you can use it to program in many different languages. The features and plugins seem endless which is an added bonus. The main reason why I like it is that it works on Linux. ;)


  • PHP 5
  • Apache
  • PHPdbg
  • MySQL or some other DB (if you are planning to use a database)


I am running Gentoo Linux in 64-bit mode, so a lot of packages are masked. In this case I had to unmask the package by:
# echo "dev-php5/phpdbg ~*" >> /etc/portage/package.keywords
Now we can install everything, you're USE variable may include more than what I have. Whatever the case, what I have is all I need to get Eclipse to debug.
# USE="apache2 gd mysql mysqli ssl" emerge dev-lang/php apache mysql dev-php5/phpdbg
While waiting you can go and download Eclipse and the PHP plugin. Eclipse can be downloaded from and the PHP plugin can be downloaded from or you can download Eclipse 3.1.2 with the PHP plugin for Linux (x86_64) here and Linux (x86) here.

Configuring Apache

After everything is done downloading and compiling, we need to configure apache to use PHP and tell it to make our workspace available. On Gentoo we must edit the /etc/config.d/apache file. Open of that file and find the APACHE2_OPTS line and make sure that the line reads as:
The next file we need to edit is going to be the /etc/apache2/httpd.conf and add the following:
Alias /eclipse "/path/to/workspace/dir"

Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all

I put the above right under:
Alias /icons/ "/var/www/localhost/icons/"

Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all

Configuring PHP

We need to make modificationst to the php.ini file. There are a few of them in the /etc directory. We want to modify the /etc/php/apahce2-php5/php.ini file. Open of the file and scroll down until you get to the area where there are modules being listed. Once there add the following line:

Now scroll all the way to the bottom of the file and insert:

Configuring Eclipse

We need to set Eclipse to set the localhost in the preferences:
  • Go to Window->Preferences
  • On the right side of the Preferences window. Go to PHPeclipse Web Development->Project Defaults
  • Set the Localhost field to http://localhost/eclipse
That's it, now we can start debugging!

Debugging with Eclipse

After you have done some coding and you need to debug the code, you're going to need to open up the Debug Perspective:
  • Window->Open Perspective->Debug
  • Run->Debug
  • Under the Configurations side (left pane), click on the PHP DBG Script then click New
  • Give the configuration a name.
  • Click on the File tab and select the project and file that you wish to debug.
There are some settings that we need to tweak under the Environment tab. Under the Interpreter tab, we need to point to the php program. Jump over to the Remote Debug tab and make sure that the only thing that is checked there is the Remote Debug option. Now click on the Debug button and point your browser to: http://localhost/eclipse/{project_name}/{file_name}?DBGSESSID={sessid}@localhost:{port}
  • project_name would be the name of the project you're working on.
  • file_name is the file that you're trying to debug.
  • sessid is the id of the session that you're working with. You can have multiple instances of the debugger running. The sessid starts at one.
  • port is the port you want to connect to. With multiple instances of the debugger running, each instance is assigned a different port which is +1 from the last currently run instance.
In my example I would open up my browser and point it to http://localhost/eclipse/MPCDSL/manage.php?DBGSESSID=1@localhost:10001 if I had another session open at the same time then the address would be http://localhost/eclipse/MPCDSL/manage.php?DBGSESSID=2@localhost:10002