Debugging PHP code

You can use the Eclipse PDT Xdebug client to debug PHP code.

Before you begin

The PHP Development Tools (PDT) 2.1 or higher must be installed in Eclipse to debug PHP code. For more information, see www.eclipse.org/pdt/.

About this task

You can remotely connect an Eclipse debug client to dynamic scripting applications. By using an Eclipse debug client, from your workstation you can stop at breakpoints, step through your code, evaluate expressions, inspect stack frames, and inspect variable values, while the PHP code runs on z/OS®.

Procedure

  1. Configure Xdebug:
    1. In Eclipse, click Window > Preferences > PHP > Debug > Installed Debuggers
    2. Select XDebug.
    3. Click Configure.
    4. From the Accept remote session (JIT) list, select prompt. From the Capture stdout list, select off. From the Capture stderr list, select off. In the Debug port field, you can change the port that is used by the debugger from the default of 9000, if necessary.
    5. Click OK, then click OK again.
    6. Create a PHP project that contains the files that you want to debug.
    7. Open the file that you want to debug, and add breakpoints in your PHP code by clicking in the gutter.
  2. In the Package Explorer pane in Eclipse, right-click your OSGi web project, then click Configure > Add PHP Support.
  3. Edit your liberty JVMPROFILE to add the following line, replacing ip_address with the IP address of your workstation, and port with the port number assigned to Xdebug in Step 1.d (the default port is 9000):
    -Dp8.debug=idekey=ECLIPSE_DBGP&remotePort=port&remoteHost=ip_address
    This ensures that the dynamic scripting application starts debug support in the PHP engine, and requests that it connects to the debug client on your workstation.
  4. Start or restart your Liberty JVM server.
  5. Run the code that contains the breakpoint, for example, by issuing an HTTP request to the appropriate URI. If you have a breakpoint in /hello.php and the context root is /example, you can run it by accessing http://hostname:port/example/hello.php in a browser.
  6. Eclipse detects the remote request to debug and prompts you to begin the debug session. Click Yes.
  7. Eclipse prompts you to map the file that is being run remotely to a file in your workspace. Select the appropriate file and click OK.
  8. You can now step through the code and inspect the context, including stack frames and variable values.

Results

You have used the Eclipse PDT 2.1 to debug a dynamic scripting application.