Using PDT : User Guide : PHP Source Level Debugging
Besides the method of outputting runtime information by adding echo or var_dump functions to your code, the more sophisticated and convenient method is using a so called “Source Level Debugger”.
With the current release of Eclipse PDT (0.7 RC2) Zend Debugger is well supported. XDebug support start only recently (first successful tests started in January 2007 (see Section “Installing XDEBUG”).
In case you haven't already installed Zend Debugger, see Section “Installing the Zend Debugger” (or "Installing XDebug Debugger"). When you are sure the degugger module is correctly installed, you can go forward.
To do debugging in Eclipse PDT you need to set up a so called “Debug Configuration”. The following sections describe how to set up such a “Debug Configuration” and how to start a debug session.
Debugging with Zend Debugger
To set up a “Debug Configuration” click on Run->Debug... (see Figure “Open the Debug Configuration dialog”). Within the opened dialog click on “PHP Web Page” and click on New (see Figure “Debug Configuration with the Perspectives view”). This opens the “Create, manage, and run configuration” dialog.
Debugging Web pages
Set up your web servers
Go to Window->Preferences->PHP->PHP Servers.
Modify or add a PHP Server to reflect your settings. The document root is http://localhost if your test web server is on the same computer. If you use Apache mod_userdir you should append your username to the url if your web files are in your home directory (ie. http://localhost/~john) .
The publish information tells Eclipse where the publish directory that corresponds to the document root is. Files can only be published to drives that are mapped to the file system of the computer that is running Eclipse.
You have to select this option ONLY if your development files are not served by the web server. This may occur if your web server is on another computer within your LAN. Also, it could occur if your files are on the same computer as the web server and you decide to not work on files within your web server root. This is very important, as it is what makes sure that ZendDebugger and PDT both know which file is being debugged.
Example: Your root web space on your web server is mapped to your local X: drive and the web server URL on your LAN is http://10.10.1.20 :
Some versions don't show the "publish information" option but instead allow you to create path mappings. These are effectively the same as publish information (for telling the debugger which files are being debugged) but also allow you to have multiple mappings. The multiple mappings are helpful when you are using symlinks in your project to other resources (eg, the Zend Framework library).
Example: Your project is called TestProject. Your web server root is not mounted on your local machine. Your web server root is /path/to/htdocs and your project root has the same files (ie, subversion). You would then set a Path Mapping with "Path on server" == /path/to/htdocs and "Local Path" = /TestProject.
Example: Same setup as above, and you have a symlink on the server at /path/to/htdocs/library/Zend pointing to /some/other/path/to/Zend. Same setup as above, plus and additional mapping with "Path on server" == /some/other/path/to/Zend and "Local Path" = /TestProject/library/Zend.
Name the Debug Configuration
Within the “Name:” text field you should change the name (which is “New_configuration” per default) to a more reasonable one (see Figure “Set up Debug Configuration - File”).
Configure Server tab
Within the “Server” tab you find three entries:
- Server: Select the web server running the pages you want to debug. These PHP Servers are defined in Preferences -> PHP -> PHP Servers (see above). You can edit settings for the selected server or create a new one.
- File / Project: Select the root file for your project. This is the default PHP file when you just run http://mydomain/myproject/ . This is often index.php. Be sure to select http://mydomain/myproject/index.php, not just http://mydomain/myproject/ because with PDT 0.7 you will not be able to stop at breakpoints.
- Publish files to Server: You can't modify this setting if it is not enabled in Preferences.
For example we setup above a 10.10.1.20 web server for a client computer running windows that use the X: mapped drive to connect to the web server root. Suppose we are on a second client computer running Linux. We already set up the same server, the shared web server root directory is mounted on /mnt/www . The files will be published to the MuyProject sub-directory:
- URL: You can edit the real URL if the auto generated one is wrong
Configure Advanced tab
- Session Settings:
- Open in browser:
Debugging Zend Framework (ZF) projects
Nothing special here, just make sure you have your path mappings correct, and have dummy.php sitting beside index.php. I must note that I've only had success with Zend Core 2.5.2 (failure with 2.5.0)
An alternative to Debugging Web pages
- Debugging in Eclipse
- This assumes that you have a PHP project called "testproject".
- In this PHP project "testproject" one resource exists called "testfile.php"
- The resource "testfile.php" is accessible via "http://localhost/testproject/testfile.php"
- The resource "testfile.php" has a breakpoint in it.
- Debug Steps
- In the file menu select "RUN" > "DEBUG.."
- "PHP Web Page" > And the "New" button
- Into the "Name" field enter "PHP FILE DEBUG"
- In the "File / Project" field enter "testproject/testfile.php"
- In the "URL" field enter "http://localhost/testproject/testfile.php"
- Click on the "Debug" button
- On success, you will be taken to the debug perspective at the relevant breakpoint.
Debugging Forms (POST and GET) and Multipages Trick
This trick has been test on linux with PDT 1.0 and mozilla firefox 2.0.x
- First download and install the Zend's extension module into your browser (initially made for Zend Studio) :
Note: the link above IS NOT for the browser toolbar. The good link is http://www.zend.com/en/products/studio/downloads (you have to create an account).
- Configure to Debug with an external browser
- In the Window menu select "Web Browser" > "Mozilla"
- You can change or add an external browser via the Window menu "Preference..." > "General" > "Web Browser" to match the browser you have installed Zend's extension.
- In the Run menu select "Open Debug Dialog..." > "PHP Web Page" > "Your configuration" > "Advanced tab" and choose "Open in Browser" and "Debug All Pages"
- Debug your site
- In the Debug menu of the toolbar choose your Web Page configuration and click it
- Your external brower should open the page you want to debug and stop on the first breakpoint (if any).
- From the Zend toolbar go in the Debug menu and choose "All pages of this site"
- Go on debugging your site's pages, Eclipse PDT will handle the stuff.