Installing and configuring the debuggers
At this point, you should have a couple of example projects set up in your workspace and be familiar with the different views in the PHP Debug perspective. This section covers getting the debuggers configured and hooked into PDT so you can start debugging the PHP files in the example projects.
Both debuggers require setup that basically includes copying an extension into a directory, configuring the php.ini file to use the extension, configuring the extension itself with a couple of configuration values, and restarting your Web server. After this work is done, you're able to start debugging your PHP Web application using either debugger.
Note: If you only want to debug PHP scripts (and not Web pages on the server) and don't have PDT already installed, the fastest way for you to get debugging your PHP script is to use the Eclipse update site at Zend.com to install the version of PDT bundled with the Zend Debugger. After installing it, you will be immediately able to debug PHP scripts inside your IDE.
The bundled Zend Debugger is easy to install because you can get it from Zend's update site, just like installing PDT from the Eclipse update site. If you download the bundled version of PDT from Zend's site, you can begin debugging scripts at once.
If you want to debug PHP Web pages on the server using the Zend Debugger, you need to install the PHP extensions and configure them in your php.ini configuration file. To install and configure the extensions:
- Download the Zend Web server extension binaries from Zend's Web site.
- Extract the ZIP file containing the binaries.
- Copy the extension binary (called ZendDebugger.dll or ZendDebugger.so) to a folder. You don't have to put them in your PHP extensions folder, but it's a good place to copy them because then all your extension binaries are in the same place. If you don't know which folder that is, see "Troubleshooting" to find out how to determine the folder.
- Update your php.ini file with the settings shown in Listing 5. You might need to
verify that you are editing the correct php.ini file —. Also, you must make
sure that the
zend_extensiondirective is the correct one. See "Troubleshooting" for more information.
Listing 5. The modified php.ini
[Zend] zend_extension="/full/path/to/ZendDebugger.so" zend_debugger.allow_hosts="127.0.0.1, 10.0.1.3" zend_debugger.expose_remotely=always
- Restart your Web server.
- Verify that the Zend Debugger has been installed correctly by using either the
phpinfo()function in a script or the
php -mcommand and look under
Listing 6. Output from the
[Zend Modules] Zend Debugger
If you don't see the module listed when trying to verify the installation, you won't be able to run the debugger through PDT, as explained in the next section. The module must be installed correctly before you can debug files on the server.
When you've verified that the module is successfully installed, proceed to the "Setting up PDT" section.
To use XDebug as a debugger for PDT, you need to download XDebug and install it just like you would if you weren't using Eclipse at all. There are very good instructions for downloading and installing XDebug in Martin Streicher's article titled "Squash bugs in PHP applications with XDebug" (see Resources). As of this writing, these instructions still apply, and this tutorial covers them only at a very high level:
- Download the binary files (Windows) or source files (Linux or Mac OS X), as appropriate.
- If you're on Mac OS X or Linux, compile the XDebug libraries. To do so, first run the
phpizecommand in the directory, then run the
makecommand, as shown below.
Listing 7. Commands for compiling XDebug
# cd [directory_with_source] # phpize # make
- Edit the php.ini file to include the module for XDebug using the appropriate
zend_extensiondirective (see "Troubleshooting" for details).
- Restart your Web server.
- Verify that XDebug was installed correctly by using the
php -mcommand or the
phpinfo()function in a script on your Web server. An example of the
phpinfo()output is shown in Figure 9. The
php -moutput is shown in Listing 8.
Figure 9. XDebug in the
Listing 8. Example
php -moutput with XDebug
[Zend Modules] Xdebug
Before you can debug using PDT and XDebug, the module must be correctly installed. If you don't see the module information, check the "Troubleshooting" section for tips.
Debugging takes a bit more work up front with XDebug than with the Zend Debugger because you may have to compile the module yourself. But now you're ready to debug both local scripts and files on the Web server.
When you've installed either of the supported debuggers, you can configure how PDT works with it, further using the preferences in Eclipse under PHP\Debug, as shown below.
Figure 10. PHP Debug preferences
Note that by default, the two debuggers are set up to listen on different ports: 10000 and 9000 for the Zend Debugger and XDebug, respectively. Depending on what you have set up in your environment, you may have to modify the settings. If you change the port settings, make sure the debuggers are not configured to be bound to the same ports (if you have both installed).