Platform.sh User Documentation

Using Xdebug

Upsun Beta

Access our newest offering - Upsun!

Get your free trial by clicking the link below.

Get your Upsun free trial

Xdebug is a real-time debugger extension for PHP. While usually used for local development, it can also be helpful for debugging aberrant behavior on the server.

As configured on Platform.sh, it avoids any runtime overhead for non-debug requests, even in production, and only allows connections via SSH tunnels to avoid any security issues.

Note that Xdebug runs only on your app containers. So you can’t use it for worker containers.

Also, note that if you use a custom start command, Xdebug is automatically disabled.

Before you begin Anchor to this heading

The following table shows the PHP versions where Xdebug is available on Grid environments:

5.4 5.5 5.6 7.0 7.1 7.2 7.3 7.4 8.0 8.1 8.2 8.3
Avail Avail Avail Avail Avail Avail Avail Avail Avail Avail

You also need:

  • The Platform.sh CLI
  • A Xdebug-compatible IDE installed on your machine. For setup instructions, consult your IDE’s Xdebug documentation, such as that for PHPStorm.

1. Set up Xdebug Anchor to this heading

Xdebug runs as a second PHP-FPM process used only for debugging requests, leaving the normal process unaffected.

To enable Xdebug, add the following to your app configuration:

.platform.app.yaml
runtime:
    xdebug:
        idekey: YOUR_KEY

YOUR_KEY can be any arbitrary alphanumeric string.

When that key is defined, Platform.sh starts a second PHP-FPM process on the container that’s identically configured but also has Xdebug enabled. Only incoming requests that have an Xdebug cookie or query parameter set are forwarded to the debug PHP-FPM process. All other requests are directed to the normal PHP-FPM process and thus have no performance impact.

If you have enabled the router cache, you need to explicitly add the Xdebug cookie (XDEBUG_SESSION) to the cookie allowlist. Depending on the cookies already listed, the result should look similar to the following:

.platform/routes.yaml
"https://{default}/":
    # ...
    cache:
        enabled: true
        cookies: ['/^SS?ESS/', 'XDEBUG_SESSION']

Xdebug has several configuration options available. They can be set the same way as any other PHP setting. For a full list of available options, consult the Xdebug documentation.

2. Use Xdebug Anchor to this heading

Open a tunnel Anchor to this heading

To open an SSH tunnel to the server from a local checkout of your app, run the following CLI command :

platform environment:xdebug

That SSH tunnel allows your IDE and the server to communicate debug information securely.

By default, Xdebug operates on port 9003. Generally, it’s best to configure your IDE to use that port. To use an alternate port, use the --port flag.

To close the tunnel and terminate the debug connection, press Ctrl + C.

Install an Xdebug helper Anchor to this heading

While Xdebug can be triggered from the browser by adding a special query parameter, the preferred way is to use a browser plugin helper. Helpers are available for Firefox and Chrome. Their respective plugin pages document how to trigger them when needed.

3. Configure your IDE Anchor to this heading

Follow the instructions for your IDE, such as those for PHPStorm.

The common steps for setup usually include:

  1. Configuring the Xdebug debug port and making sure it’s set to the expected value (9003 as default or the value you chose with --port when opening the tunnel).
  2. Making sure that external connections are allowed.
  3. Adding a new server for your Platform.sh environment. The Host should be the hostname of the environment on Platform.sh you are debugging. The Port should always be 443 and the Debugger set to Xdebug.
  4. Ensuring path mappings is enabled. This lets you define what remote paths on the server correspond to what path on your local machine. In the majority of cases you can just define your app root to map to app.
  5. Listening for connections.
  6. Starting debugging. While in listen mode, start the platform xdebug tunnel. Use the Xdebug helper plugin for your browser to enable debugging. Set a break point in your app, then load a page in your browser. The request should pause at the break point and allow you to examine the running app.

What’s next Anchor to this heading

Learn more about how to set up Xdebug on Dedicated server clusters.

Is this page helpful?