PHP, Zend Debugger, Eclipse

By Paulus, 25 November, 2007

A while ago I wrote how you can configure Eclipse, PHP on a Linux machine to debug PHP pages using phpdbg. At first this worked very well but after a while break point wouldn't work and I would have to restart the session. Another problem that I was having was that the session information was saved. I got around this by clearing out the session information in Firefox. This continued until one day when I tried to start a new debug session and all I got was this:

At that point I decided to dump phpdbg and start using the Zend Debugger. Getting the extension to work properly took some time. After many hours of searching the Internet I managed to find a decent site to work off of. Unfortunately, it was aimed at the Windows platform. Getting PHP and eclipse configured was half the battle that I faced.

I had recently updated PHP from 5.2.1 to 5.2.4. For some reason the latest version of PHP had a habbit of hanging when I tried to receive information or view all loaded modules, PHP would hang.

$ php -i

for information, or to see all the modules that are being loaded:

$ php -m

I ended up having to mask PHP and recompile Apache with the mpm-prefork use flag:

# echo ">=dev-lang/php-5.2.3-r3" >> /etc/portage/package.mask
# echo "www-servers/apache mpm-prefork" >> /etc/portage/package.use

I orignally had the mpm-worker use flag enabled for Apache. I switched it to prefork after reading some problems that people were having with the Zend Optimizer. By switching to prefork, this got everything working.

In the future to make sure that PHP is configured correctly use the php command:

$ php -c /etc/php/apache-php/php.ini -d zend_extension=/usr/lib64/php5/lib/php/extensions/no-debug-zts-20060613/ZendDebugger.so -m

The -c specifies what configuration files to use. The -d flag allows you to specify ini entries via the command line. Finally, the -m flag, which lists all the modules that are being loaded.

Installing PDT

The first step is installing the PDT plugin. You can do this by opening Eclipse then:

Help->Software Updates->Find and Install

Add a new Remote Site with the URL of http://downloads.zend.com/pdt. Depending on your IDE, you may need to install additional plugins for this to work.

Next, you need to find all php.ini files within the plugins directory of the Eclipse folder. In each file that you find, add the following line:

extension_dir = /usr/lib64/php5/lib/php/extensions/no-debug-zts-20060613/

Your extension path may be different for you.

Installing Zend Debugger

Click here to download the extension binaries. Once you've downloaded them, uncompress them and copy the version of the debugger that matches the version of php you have installed. Since I have 5.2.1 installed, I would copy the ZendDebugger.so file that's located in the 5_2_x_comp directory to where PHP is looking for it's extensions.

$ php -i | grep extension_dir | awk '{ print $3 }'

To find which php.ini file that needs to be edited, make a simple PHP page, and in it use the phpinfo() function to determine which configuration file it's using. Once you have determined which file it's using, open it with your favorite editor and add the following lines at the bottom of the file:

[Zend]
zend_extension = /usr/lib64/php5/lib/php/extensions/no-debug-zts-20060613/ZendDebugger.so
zend_debugger.allow_hosts = 10.1.1.2, 127.0.0.1
zend_debugger.expose_remotely = always
zend_debugger.connector_port = 10001
If you have PHP compiled with the threads use flag, then the extension directive should include a _ts at the end of it. The port can always be changed if you have something that runs on the default port, which is 10000.

Inside the Zend Debugger folder there is a file called dummy.php. This file needs to be copyed to the server's root directory.

After you have made your changes you need to restart apache. To see if the install worked type:

$ php -m

if it worked then you'll see:

[Zend Modules]
Zend Debugger

Configuring Eclipse

Go to Window->Prefrences. In the new window that popped up, in the left pane of the window go to PHP->PHP Servers. Create a new server that reflects your needs.

If you needed to change the port in which the Zend Debugger runs on, then you're going to have to tell Eclipse which port to use. This is found in the Prefrences window and under PHP->Debug.

Open up a file that you want to debug then go to Run->Open Debug Dialog. Anything that you need to change is going to be in the Server tab.

  • Make sure that the Server Debugger is set to Zend.
  • PHP Server should be selected to the server you wish to use. Normally you're only going to have one configured.
  • File / Project, click on Browse to select the file or project you wish to debug.
  • URL is the address that's going to open when you click on the Debug window at the bottom of the window.