Specifying dependencies

You can declare dependencies for PHP in a standardcomposer.json file. For example:

{    "require": {        "google/cloud": "^0.72"    }}

You can use any Linux-compatible PHP package in App Engine. The runtimelooks for acomposer.json file in your application's sourcedirectory and usescomposer to install any dependencies beforestarting your application.

For information about the PHP versions that are supported in this runtime,seeThe PHP Runtime.

Installing and running locally

Usecomposer to install your dependencies locally:

composer install

To pin your dependencies to their current version, commit thecomposer.lock file to your application.

You can test your application using your web server of choice. App Engine flexible environment usesNGINX in production. To quickly run your application, you can usePHP's built-in web server.

Installing a web framework

By default, NGINX is configured to serve all requests throughindex.php. Aframework is not required, but is encouraged. You can use any web framework withApp Engine flexible environments, including the following:

To use a particular web framework, just add it tocomposer.json:

{    "require": {        "symfony/symfony": " ^3.0"    }}

Installing the Cloud Client Libraries

TheGoogle Cloud Client Library for PHP is a client library for accessing Google Cloud services thatreduces the boilerplate code you have to write. The library provides high-level,easy to understand API abstractions. It embraces idioms of PHP,works well with the standard library, and has tighter integration with yourcodebase. All of this means you spend more time creating code that matters toyou.

  1. Install the library locally:

    composer require google/cloud
  2. You can handle authentication locally by using theGoogle Cloud CLI.If you want your local application to temporarily use your own user credentialsfor API access, run:

    gcloud auth application-default login

    For details on configuring Cloud Client Libraries for PHP to handle authenticationautomatically, seeAuthenticate to Cloud services using client libraries.

Using private repositories

To use libraries in private repositories, you must complete the following tasks:

  • Configure the repository.
  • Givecomposer the secret to access the private repository.

The following example illustrates how to access a private repository in GitHub.

  1. Configure the repository incomposer.json usingvcs for the type:

    "repositories": [    {        "type": "vcs",        "url": "https://github.com/username/private_package"    }]
  2. Create a file namedauth.json in your project root directory:

    {    "github-oauth": {        "github.com": "<your-github-auth-token>"    }}

You can obtain the GitHub auth token from GitHub's administrative UI.

Here is another example that illustrates how to access a private repository forBitbucket.

  1. Configure the repository incomposer.json usingvcs for the type:

    "repositories": [    {        "type": "vcs",        "url":  "https://bitbucket.org/username/private_git"    }]
  2. Create a file namedauth.json in your project root directory:

    {    "bitbucket-oauth": {        "bitbucket.org": {            "consumer-key": "<your-oauth-consumer-key>",            "consumer-secret": "<your-oauth-consumer-secret>"        }    }}
Note: Since theauth.json file contains secrets, you should configuredocument_root to point to a subdirectory in your project root so your secretisn't publicly served.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-15 UTC.