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. ;)
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.
- PHP 5
- MySQL or some other DB (if you are planning to use a database)
InstallationI 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
# USE="apache2 gd mysql mysqli ssl" emerge dev-lang/php apache mysql dev-php5/phpdbgWhile waiting you can go and download Eclipse and the PHP plugin. Eclipse can be downloaded from http://www.eclipse.org and the PHP plugin can be downloaded from http://sourceforge.net/projects/phpeclipse/ or you can download Eclipse 3.1.2 with the PHP plugin for Linux (x86_64) here and Linux (x86) here.
Configuring ApacheAfter 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:
APACHE2_OPTS="-D DEFAULT_VHOST -D USERDIR -D PHP5"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"I put the above right under:
Options Indexes MultiViews AllowOverride None Order allow,deny Allow from all
Alias /icons/ "/var/www/localhost/icons/" Options Indexes MultiViews AllowOverride None Order allow,deny Allow from all
Configuring PHPWe 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:
extension=dbg.soNow scroll all the way to the bottom of the file and insert:
[Debugger] debugger.enabled=on debugger.profiler_enabled=on
Configuring EclipseWe 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
Debugging with EclipseAfter 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
- 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.
- 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.