Setting Up Stackdriver Debugger for PHP

This page describes how to configure your environment and your PHP application to use Stackdriver Debugger. For some environments, you must explicitly specify the access scope to let the Stackdriver Debugger agent send data. We recommend setting the broadest possible access scope and then using Cloud Identity and Access Management to restrict access. In keeping with this best practice, set the access scope to be all Cloud APIs with the option cloud-platform.

Before you begin

To begin using Debugger, ensure the Debugger API is enabled.
Enable Debugger API

App Engine standard environment

The Stackdriver Debugger agent for PHP is not supported in App Engine standard environment yet.

App Engine flexible environment

  1. Install the stackdriver_debugger extension from PECL:

    pecl install stackdriver_debugger-alpha
    

    If your php.ini file does not include extension=stackdriver_debugger.so after running this step, add it manually.

  2. Add the Google Cloud PHP Debugger package to your composer.json file:

    composer require google/cloud-debugger
    
  3. Add the Stackdriver Debugger PHP extension via your composer.json file:

    composer require ext-stackdriver_debugger:*
    
  4. Enable Stackdriver integrations in your app.yaml file:

    runtime_config:
      enable_stackdriver_integration: true
    
  5. Enable the agent.

    Add the following code to your app as early in the request as possible:

    use Google\Cloud\Debugger\Agent;
    
    $agent = new Agent(['sourceRoot' => realpath('/app')]);
    

The debugger is now ready for use with your app.

Google Kubernetes Engine

GCLOUD

To enable Debugger using gcloud, complete the following steps:

  1. Create your cluster with one of the following access scopes:

    • https://www.googleapis.com/auth/cloud-platform grants your cluster access to all Google Cloud Platform APIs.

    • https://www.googleapis.com/auth/cloud_debugger grants your cluster access to only the Debugger API. Use this access scope to harden your cluster's security.

    gcloud container clusters create example-cluster-name \
           --scopes=https://www.googleapis.com/auth/cloud_debugger
    
  2. Install the Stackdriver Debugger PHP extension in your container. If you have PECL installed, this can be done by adding the following line to your Dockerfile:

    RUN pecl install stackdriver_debugger_alpha
    
  3. Add the Debugger package to your application by running the following command in your application:

    composer require google/cloud-debugger
    
  4. Add the following line to your Dockerfile to configure a daemon to run the Debugger daemon process:

    RUN php /[YOUR-APP-PATH]/vendor/bin/google-cloud-debugger -s /[YOUR-APP-PATH]
    
  5. Add the following lines of code to your app as early in the request as possible to enable the Debugger agent:

    use Google\Cloud\Debugger\Agent;
    
    $agent = new Agent(['sourceRoot' => realpath('/[YOUR-APP-PATH]')]);
    

The debugger is now ready for use when you deploy your containerized app.

CONSOLE

To enable Debugger using the console, complete the following steps:

  1. After selecting your cluster type, click More options from the Node pools pane:

    Node pool field showing red rectangle over the more options button.

  2. Select one of the following from the Security pane:

    • Allow full access to all Cloud APIs.

    • Allow access for each API and then select Enabled for Cloud Debugger.

Compute Engine

  1. Make sure your Compute Engine instances are created with the access scope option Allow full access to all Cloud APIs, or have one of the following access scopes:

    • https://www.googleapis.com/auth/cloud-platform
    • https://www.googleapis.com/auth/cloud_debugger
  2. Install the stackdriver_debugger extension (if using containers, install to the image) from PECL:

    pecl install stackdriver_debugger-alpha
    
  3. Add the Google Cloud PHP Debugger package to your composer.json file:

    composer require google/cloud-debugger
    
  4. Configure a daemon to run the Debugger daemon process:

    php /[YOUR-APP-PATH]/vendor/bin/google-cloud-debugger -s /[YOUR-APP-PATH]
    
  5. Enable the agent.

    Add the following code to your app as early in the request as possible:

    use Google\Cloud\Debugger\Agent;
    
    $agent = new Agent(['sourceRoot' => realpath('/[YOUR-APP-PATH]')]);
    

The debugger is now ready for use with your app.

Local and elsewhere

  1. Install the stackdriver_debugger extension from PECL:

    pecl install stackdriver_debugger-alpha
    
  2. Add the Google Cloud PHP Debugger package to your composer.json file:

    composer require google/cloud-debugger
    
  3. Run the Stackdriver Debugger daemon process:

    php /[YOUR-APP-PATH]/vendor/bin/google-cloud-debugger -s /[YOUR-APP-PATH]
    
  4. Enable the agent.

    Add the following code to your app as early in the request as possible:

    use Google\Cloud\Debugger\Agent;
    
    $agent = new Agent(['sourceRoot' => realpath('/[YOUR-APP-PATH]')]);
    

The debugger is now ready for use with your app.

The Debug page in the GCP Console can display local source files, without upload, for local development. See Selecting source code manually.

Bu sayfayı yararlı buldunuz mu? Lütfen görüşünüzü bildirin:

Şunun hakkında geri bildirim gönderin...

Stackdriver Debugger