Specifying Dependencies

Composer runs automatically when you deploy a new version of your application. Simply add the following line to the top of your PHP scripts to require the autoload.php file:

require_once __DIR__ . '/vendor/autoload.php';

Composer adds the packages to your app's vendor/ directory, where the autoload.php file is generated. The Composer autoloader automatically loads classes installed by Composer without a require statement for each file.

By default, the vendor/ directory is ignored in the generated .gcloudignore file to reduce the number of files sent in deployment.

Declaring dependencies

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

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

You can use any Linux-compatible PHP package in App Engine. The runtime looks for a composer.json file in your application's source directory and uses composer to install any dependencies before starting your application.

Scripts defined in your composer.json file will not run when there is a cache hit.

By default, App Engine caches fetched dependencies to reduce build times. To install an uncached version of the dependency, use the command:

gcloud beta app deploy --no-cache

Installing and running locally

Use Composer to install your dependencies locally:

composer install

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

You can test your application using your web server of choice. To quickly run your application, you can use PHP's built-in web server.

Installing a web framework

By default, App Engine serves all requests through the public/index.php or index.php file. A framework is not required, but is encouraged. You can use any web framework with App Engine, including the following:

Using private repositories

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

  • Configure the repository.
  • Give composer the secret to access the private repository.

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

  1. Configure the repository in composer.json using vcs for the type:

    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/username/private_package"
        }
    ]
    
  2. Create a file named auth.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 for Bitbucket.

  1. Configure the repository in composer.json using vcs for the type:

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

    {
        "bitbucket-oauth": {
            "bitbucket.org": {
                "consumer-key": "<your-oauth-consumer-key>",
                "consumer-secret": "<your-oauth-consumer-secret>"
            }
        }
    }
    

Оцените, насколько информация на этой странице была вам полезна:

Оставить отзыв о...

Текущей странице
App Engine standard environment for PHP 7.2 docs