Google Cloud サービスにアクセスするためのクライアント ライブラリである PHP 用 Google Cloud クライアント ライブラリを使用すると、記述する必要のあるボイラープレート コードが減ります。このライブラリは、高レベルの抽象化によってわかりやすい API を提供します。また、PHP 固有のスタイルに従い、標準ライブラリとうまく連携し、コードベースとの緊密な統合を実現します。その結果、重要なコードの作成により多くの時間を割くことができるようになります。
ライブラリをローカルにインストールするには:
composer require google/cloud
Google Cloud CLI を使用して、認証をローカルで処理できます。ローカル アプリケーションで一時的に独自のユーザー認証情報を使って API にアクセスするには、次のコマンドを実行します。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-09-04 UTC。"],[[["\u003cp\u003eDependencies for PHP applications can be declared in a \u003ccode\u003ecomposer.json\u003c/code\u003e file, which App Engine uses to install them via \u003ccode\u003ecomposer\u003c/code\u003e before starting the application.\u003c/p\u003e\n"],["\u003cp\u003eAny Linux-compatible PHP package can be utilized, and dependencies can be pinned to specific versions by committing the \u003ccode\u003ecomposer.lock\u003c/code\u003e file.\u003c/p\u003e\n"],["\u003cp\u003eA variety of web frameworks such as Symfony, Laravel, CodeIgniter, WordPress, Drupal, and Joomla! can be integrated by adding them to \u003ccode\u003ecomposer.json\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe Google Cloud Client Library for PHP can be installed to access Google Cloud services and reduce boilerplate code, requiring \u003ccode\u003ecomposer require google/cloud\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003ePrivate repositories can be accessed by configuring them in \u003ccode\u003ecomposer.json\u003c/code\u003e and providing the necessary credentials in an \u003ccode\u003eauth.json\u003c/code\u003e file located in the project root.\u003c/p\u003e\n"]]],[],null,["# Specifying dependencies\n\nYou can declare dependencies for PHP in a standard [`composer.json`](https://getcomposer.org/doc/01-basic-usage.md#composer-json-project-setup) file. For example: \n\n {\n \"require\": {\n \"google/cloud\": \"^0.72\"\n }\n }\n\nYou can use any Linux-compatible PHP package in App Engine. The runtime\nlooks for a [`composer.json`](https://getcomposer.org/doc/01-basic-usage.md#composer-json-project-setup) file in your application's source\ndirectory and uses [`composer`](https://getcomposer.org) to install any dependencies before\nstarting your application.\n\nFor information about the PHP versions that are supported in this runtime,\nsee [The PHP Runtime](/appengine/docs/flexible/php/runtime).\n\nInstalling and running locally\n------------------------------\n\nUse [composer](https://getcomposer.org) to install your dependencies locally: \n\n composer install\n\nTo pin your dependencies to their current version, commit the\n[`composer.lock`](https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control) file to your application.\n\nYou can test your application using your web server of choice. App Engine flexible environment uses\n[NGINX](https://www.nginx.com/resources/wiki/start/index.html) in production.\nTo quickly run your application, you can use\n[PHP's built-in web server](http://php.net/manual/en/features.commandline.webserver.php).\n\nInstalling a web framework\n--------------------------\n\nBy default, NGINX is configured to serve all requests through `index.php`. A\nframework is not required, but is encouraged. You can use any web framework with\nApp Engine flexible environments, including the following:\n\n- [Symfony](https://symfony.com/)\n- [Laravel](https://laravel.com/)\n- [CodeIgniter](https://www.codeigniter.com/)\n- [WordPress](https://wordpress.com/)\n- [Drupal](https://drupal.com/)\n- [Joomla!](https://www.joomla.com/)\n\nTo use a particular web framework, just add it to `composer.json`: \n\n {\n \"require\": {\n \"symfony/symfony\": \" ^3.0\"\n }\n }\n\nInstalling the Cloud Client Libraries\n-------------------------------------\n\nThe [Google Cloud Client Library for PHP](https://googleapis.github.io/google-cloud-php/#/)\nis a client library for accessing Google Cloud services that\nreduces the boilerplate code you have to write. The library provides high-level,\neasy to understand API abstractions. It embraces idioms of PHP,\nworks well with the standard library, and has tighter integration with your\ncodebase. All of this means you spend more time creating code that matters to\nyou.\n\n1. Install the library locally:\n\n composer require google/cloud\n\n2. You can handle authentication locally by using the [Google Cloud CLI](/sdk/docs).\n If you want your local application to temporarily use your own user credentials\n for API access, run:\n\n gcloud auth application-default login\n\n For details on configuring Cloud Client Libraries for PHP to handle authentication\n automatically, see [Authenticate to Cloud services using client libraries](/docs/authentication/client-libraries).\n\nUsing private repositories\n--------------------------\n\nTo use libraries in private repositories, you must complete the following tasks:\n\n- Configure the repository.\n- Give `composer` the secret to access the private repository.\n\nThe following example illustrates how to access a private repository in GitHub.\n\n1. Configure the repository in `composer.json` using `vcs` for the type:\n\n \"repositories\": [\n {\n \"type\": \"vcs\",\n \"url\": \"https://github.com/username/private_package\"\n }\n ]\n\n2. Create a file named `auth.json` in your project root directory:\n\n {\n \"github-oauth\": {\n \"github.com\": \"\u003cyour-github-auth-token\u003e\"\n }\n }\n\nYou can obtain the GitHub auth token from GitHub's administrative UI.\n\nHere is another example that illustrates how to access a private repository for\nBitbucket.\n\n1. Configure the repository in `composer.json` using `vcs` for the type:\n\n \"repositories\": [\n {\n \"type\": \"vcs\",\n \"url\": \"https://bitbucket.org/username/private_git\"\n }\n ]\n\n2. Create a file named `auth.json` in your project root directory:\n\n {\n \"bitbucket-oauth\": {\n \"bitbucket.org\": {\n \"consumer-key\": \"\u003cyour-oauth-consumer-key\u003e\",\n \"consumer-secret\": \"\u003cyour-oauth-consumer-secret\u003e\"\n }\n }\n }\n\n| **Note:** Since the `auth.json` file contains secrets, you should configure `document_root` to point to a subdirectory in your project root so your secret isn't publicly served."]]