概览
本页面介绍如何配置您的环境和 PHP 应用以使用 Cloud Debugger。对于一些环境,您必须明确指定访问权限范围,以让 Cloud Debugger 代理发送数据。我们建议尽可能设置最广泛的访问权限范围,然后使用 Identity and Access Management 来限制访问权限。为符合此最佳做法,请使用 cloud-platform
选项将访问权限范围设置为所有 Cloud API。
语言版本和计算环境
Cloud Debugger 适用于以下计算环境中的 PHP 7.0 和更高版本:
App Engine 标准环境 | App Engine 柔性环境 | Compute Engine | Google Kubernetes Engine | Cloud Run | Cloud Run for Anthos | 在其他位置运行的虚拟机和容器 | Cloud Functions |
---|---|---|---|---|---|---|---|
设置 Cloud Debugger
要设置 Cloud Debugger,请完成以下任务:
验证是否为您的项目启用了 Cloud Debugger API。
在您正在使用的计算环境中安装并配置 Debugger。
选择您的源代码。
验证 Cloud Debugger API 是否已启用
要开始使用 Cloud Debugger,请确保已启用 Cloud Debugger API。默认情况下,系统会为大多数项目启用 Cloud Debugger。启用 Cloud Debugger API
App Engine 柔性环境
使用 PECL 安装
stackdriver_debugger
扩展程序:pecl install stackdriver_debugger-alpha
如果运行此步骤后
php.ini
文件中不包含extension=stackdriver_debugger.so
,请手动添加。将 Google Cloud PHP Debugger 软件包添加到
composer.json
文件中:composer require google/cloud-debugger
通过
composer.json
文件添加 Cloud Debugger PHP 扩展程序:composer require ext-stackdriver_debugger:*
在
app.yaml
文件中设置enable_stackdriver_integrations
:runtime_config: enable_stackdriver_integration: true
启用代理。
在请求中尽早将以下代码添加到您的应用中:
use Google\Cloud\Debugger\Agent; $agent = new Agent(['sourceRoot' => realpath('/app')]);
Debugger 现可用于您的应用。
Google Kubernetes Engine
GCLOUD
要使用 gcloud
启用 Debugger,请完成以下步骤:
创建集群,并为其指定以下访问权限范围之一:
https://www.googleapis.com/auth/cloud-platform
授予集群对所有 Google Cloud API 的访问权限。https://www.googleapis.com/auth/cloud_debugger
仅授予集群对 Debugger API 的访问权限。使用此访问范围来强化集群的安全性。
gcloud container clusters create example-cluster-name \ --scopes=https://www.googleapis.com/auth/cloud_debugger
在容器中安装 Cloud Debugger PHP 扩展程序。如果您安装了 PECL,则可以通过在
Dockerfile
中添加以下行来完成:RUN pecl install stackdriver_debugger_alpha
通过在您的应用中运行以下命令,以在应用中添加 Debugger 软件包:
composer require google/cloud-debugger
将以下行添加到
Dockerfile
以配置守护程序来运行 Debugger 守护程序进程:RUN php /[YOUR-APP-PATH]/vendor/bin/google-cloud-debugger -s /[YOUR-APP-PATH]
在请求中尽早将以下几行代码添加到您的应用中,以启用 Debugger 代理:
use Google\Cloud\Debugger\Agent; $agent = new Agent(['sourceRoot' => realpath('/[YOUR-APP-PATH]')]);
您现在可以在部署容器化应用时使用 Debugger 了。
控制台
如需使用 Google Cloud 控制台启用 Debugger,请完成以下步骤:
在节点池部分中,选择安全,然后选择针对每个 API 设置访问权限。
启用 Debugger。
选项:选择允许所有 Cloud API 的全面访问权限。
Compute Engine
确保使用访问权限范围选项允许所有 Cloud API 的全面访问权限创建 Compute Engine 实例,或者您具有以下访问权限范围之一:
https://www.googleapis.com/auth/cloud-platform
https://www.googleapis.com/auth/cloud_debugger
使用 PECL 安装
stackdriver_debugger
扩展程序(如果使用的是容器,请将该程序安装到映像):pecl install stackdriver_debugger-alpha
将 Google Cloud PHP Debugger 软件包添加到
composer.json
文件中:composer require google/cloud-debugger
配置守护程序以运行 Debugger 守护程序进程:
php /[YOUR-APP-PATH]/vendor/bin/google-cloud-debugger -s /[YOUR-APP-PATH]
启用代理。
在请求中尽早将以下代码添加到您的应用中:
use Google\Cloud\Debugger\Agent; $agent = new Agent(['sourceRoot' => realpath('/[YOUR-APP-PATH]')]);
Debugger 现可用于您的应用。
本地和其他位置
使用 PECL 安装
stackdriver_debugger
扩展程序:pecl install stackdriver_debugger-alpha
将 Google Cloud PHP Debugger 软件包添加到
composer.json
文件中:composer require google/cloud-debugger
运行 Cloud Debugger 守护进程进程:
php /[YOUR-APP-PATH]/vendor/bin/google-cloud-debugger -s /[YOUR-APP-PATH]
启用代理。
在请求中尽早将以下代码添加到您的应用中:
use Google\Cloud\Debugger\Agent; $agent = new Agent(['sourceRoot' => realpath('/[YOUR-APP-PATH]')]);
现在,此调试程序便可与您的应用搭配使用。
Google Cloud 控制台中的“调试”页面可以显示本地源文件,无需上传,即可进行本地开发。请参阅手动选择源代码。