Setting up the Debugger

Before we start debugging, we have to configure a few options so that PHPEclipse and XDebug know where to find various components.

Specifying the PHP Interpreter Path

To begin, we must specify the PHP Interpreter Path. This may differ depending on your system. For Windows based systems, this is a path to a file called php.exe. For Linux systems, this is a path to a file simply called php. For Linux systems, this is often in /usr/bin/php. To specify the PHP Interpreter, select Preferences from the Window drop down menu. Open up the PHPEclipse selection and click on XDebug. In the settings pane on the right that appears, enter your debug port and the path to your PHP interpreter. The default debug port for XDebug is 9000, but your system may be setup differently. To verify that 9000 is the correct port, find a way to access your phpinfo() page and check the value of xdebug.remote_port. The value of xdebug.remote_port should match the debug port value.

Figure 1. XDebug Configuration Pane

XDebug Configuration Pane


When you have entered the appropriate values, click on the OK button.

Creating the Debug Configuration

Now that we have configured XDebug, we need to create a debug configuration. This will tell Eclipse how to start the debugger for your project. To do this, select 'Open Debug Dialog' from the Run drop down menu. You will be presented with a list of items which you can debug. Double click on the entry titled 'PHP XDebug Remote Script'. This will create a new configuration and allow you to specify the necessary options. You can provide a name for your debug configuration, and then you must specify the Ide Identification String. You can select anything you want for this string. It is recommended to keep it short and memorable. Ensure that you remember this value for later. In our example, we will use the string firstproject.

Figure 2. Debug Configuration Window

Debug Configuration Window


Once you have selected a configuration name and have chosen an identification string, click on the Pathmap tab. In the pathmap tab, you specify how Eclipse translates local path names to remote path names. To map a path, click on the New button to create a new map. If your web server is located on the same system that Eclipse is running on, both of these paths will be the same. In either case, under Local Path enter the path to the root of your project on the machine that Eclipse is running on. In Remote Path, enter the path to the root of your project on the machine the web server is running on.

Figure 3. Specifying the Path Map from Local to Remote Machine

Specifying the Path Map from Local to Remote Machine


Once you have specified the proper pathmap, press the Debug button to begin the debugger.

You will notice that in contrast to when we were debugging locally, remote debugging will not automatically start your script. It will simply start the debugging and begin listening for connections on the debugging port. To begin our script, we open it up in a web browser.

Figure 4. Executing our Script in the Web Browser

Executing our Script in the Web Browser


This doesn't actually start debugging your script. There is no link at this point between your script and the Eclipse debugger. We have to somehow tell PHP to look for the Eclipse debugger for processing instructions. To do this, we have to add a variable to the request string. This variable is called XDEBUG_SESSION_START and its value should match the Ide Indentification String we specified earlier. In this case, our new URL will be http://127.0.0.1/myFirstProject/index.php?XDEBUG_SESSION_START=firstproject.

Figure 5. Adding the XDEBUG_SESSION_START onto the Query String

Adding the XDEBUG_SESSION_START onto the Query String


Once you have added the variable to the URL, press enter to start debugging.

You can now resume the process of debugging as demonstrated in the local debugging tutorial. The process is the same, except that instead of the output being displayed in the console it is displayed in the browser where you loaded your script.