Overview
This page describes how to configure your environment and your
PHP application to use Cloud Debugger.
For some environments, you must explicitly specify the access scope to let the
Cloud Debugger agent send data.
We recommend setting the
broadest possible access scope and then using 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
.
Language versions and compute environments
Cloud Debugger is available for PHP versions 7.0 and higher on the following compute environments:
App Engine Standard environment | App Engine Flexible environment | Compute Engine | Google Kubernetes Engine | Cloud Run | Cloud Run for Anthos | VMs and Containers running elsewhere | Cloud Functions |
---|---|---|---|---|---|---|---|
Setting up Cloud Debugger
To set up Cloud Debugger, complete the following tasks:
Verify the Cloud Debugger API is enabled for your project.
Install and configure the Debugger on the compute environment you're using.
Select your source code.
Verifying the Cloud Debugger API is enabled
To begin using Cloud Debugger, ensure that the Cloud Debugger API is enabled. Cloud Debugger is enabled by default for most projects.Enable Cloud Debugger API
App Engine flexible environment
Install the
stackdriver_debugger
extension from PECL:pecl install stackdriver_debugger-alpha
If your
php.ini
file does not includeextension=stackdriver_debugger.so
after running this step, add it manually.Add the Google Cloud PHP Debugger package to your
composer.json
file:composer require google/cloud-debugger
Add the Cloud Debugger PHP extension via your
composer.json
file:composer require ext-stackdriver_debugger:*
Set
enable_stackdriver_integrations
in yourapp.yaml
file:runtime_config: enable_stackdriver_integration: true
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:
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 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
Install the Cloud 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
Add the Debugger package to your application by running the following command in your application:
composer require google/cloud-debugger
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]
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 by using the Google Cloud console, complete the following steps:
On the Node pools section, select Security, and then select Set access for each API.
Enable Debugger.
Optional: Select Allow full access to all Cloud APIs.
Compute Engine
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
Install the
stackdriver_debugger
extension (if using containers, install to the image) from PECL:pecl install stackdriver_debugger-alpha
Add the Google Cloud PHP Debugger package to your
composer.json
file:composer require google/cloud-debugger
Configure a daemon to run the Debugger daemon process:
php /[YOUR-APP-PATH]/vendor/bin/google-cloud-debugger -s /[YOUR-APP-PATH]
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
Install the
stackdriver_debugger
extension from PECL:pecl install stackdriver_debugger-alpha
Add the Google Cloud PHP Debugger package to your
composer.json
file:composer require google/cloud-debugger
Run the Cloud Debugger daemon process:
php /[YOUR-APP-PATH]/vendor/bin/google-cloud-debugger -s /[YOUR-APP-PATH]
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 Google Cloud console can display local source files, without upload, for local development. See Selecting source code manually.