Deploying a PHP App

Deploy your app to upload and run it on App Engine. When you deploy your apps,
you create versions of those apps and their corresponding
services
in App Engine. You can deploy entire apps, including all the source code and
configuration files, or you can deploy and update individual versions or
configuration files.

appcfg

set HTTP_PROXY=http://cache.example.com:3128
set HTTPS_PROXY=http://cache.example.com:3128

Deploying an app

To deploy your app to App Engine, you run the gcloud app
deploy command from within the root directory of your
application where your configuration
files are located, for
example app.yaml.

gcloud

gcloud app deploy [YOUR_DEPLOYMENTS]

Where [YOUR_DEPLOYMENTS] is one or more configuration file's path and
name. You separate each configuration file that you specify with a single
white space. By default, the app.yaml is deployed when no configuration
file is specified.

Optional flags:

Include the --version flag to specify a custom version
ID,
otherwise one is generated for you.

To deploy your app without automatically routing all traffic to that
version, include the --no-promote flag.

Include the --project flag to specify an alternate
GCP project ID to what you initialized as the default in the
gcloud tool.

appcfg

By default, the initial version that you deploy to a service is
automatically configured to receive 100% of traffic. However, all subsequent
versions that you deploy to the same service must be manually configured,
otherwise they receive no traffic.

Choosing unique version IDs

For manually-scaled instances, the ID of your version should begin with a letter
to distinguish them from numeric instance IDs. This ensures that requests
are routed to the correct destination and avoids the ambiguity with URL patterns
like 123.my-service.appspot.com, which can be interpreted
two ways:

If version 123 exists, the request is routed to version 123 of the
my-service service.

If version 123 does not exist, the request is instead routed to
instance ID 123 where the versions of the my-service service are
running.

Note: If you deploy a version that specifies the same version ID as a version
that already exists on App Engine, the files that you deploy will overwrite the
existing version. This can be problematic if the version is serving traffic
because traffic to your application might be disrupted. You can avoid disrupting
traffic if you deploy your new version with a different version ID and then move
traffic to that version.

Deploying multiple service applications

When your application is factored into multiple
services,
you can deploy and update individually targeted services or all the services
simultaneously. Deploying updates to services can include updating individual
configuration
files or updating
the source code in the corresponding versions.

For example, you can deploy and create two versions in App Engine, where each
version runs in their own service. The first version serves as the frontend
service and the other as the backend of your app. You can then deploy
individual configuration files to update only the settings of a service.
You can also choose to deploy a new version to a service in order to update
the source code of the frontend, backend, or both simultaneously.

Requirements for multiple services

You use the same deployment commands for deploying and updating the multiple
services of your application with the following requirements:

You must initially deploy a version of your app to the default service
before you can create and deploy subsequent services.

You must specify the ID of your service in the
app.yaml
configuration file of the corresponding version. To specify the service ID,
you include the service: [YOUR_SERVICE_ID]
element definition in each configuration file.
By default, excluding this element definition from your configuration file
deploys the version to the default service.

You must specify all the corresponding app.yaml configuration files in
your deployment command to simultaneously deploy multiple services.

To deploy multiple services

From the root directory of the application where the configuration files are
located, you run the deployment command and specify the relative paths and file
names for each service's app.yaml file:

gcloud

gcloud app deploy [DEPLOYMENTS]

appcfg

appcfg.py update [DEPLOYMENTS]

Where [DEPLOYMENTS] is one or more configuration file's path and name. You
separate each configuration file that you specify with a single white space.

Example

gcloud

gcloud app deploy main/app.yaml service1/app.yaml service2/app.yaml

appcfg

appcfg.py update main/app.yaml service1/app.yaml service2/app.yaml

You will receive verification via the command line as each service is
successfully deployed.

Troubleshooting

The following are common error messages that you might encounter:

PERMISSION_DENIED: Operation not allowed

The "appengine.applications.create" permission is required.

If the GCP project does not include the required
App Engine
application, the
gcloud app deploy command can fail when it tries to run the
gcloud app create command. Only accounts with Owner role have the
necessary permissions to create App Engine applications.

Command not found

If you did not create symlinks for the appcfg.py or dev_appserver.py
tools when you installed the SDK,
you might need to specify the full directory path to run the tool, for
example: [PATH_TO_APP_ENGINE_SDK]/appcfg.py or
[PATH_TO_CLOUD_SDK]/bin/dev_appserver.py.

If you installed both the Google Cloud SDK as well as the original App
Engine SDK, the entries to your PATH might conflict with one another and
cause import errors. If you received errors when running Cloud SDK commands,
try explicitly using the original App Engine SDK. You can move the
entry for the original App Engine SDK to earlier in your PATH so that those
commands have priority. Alternatively, you can run the command by specifying
the full directory path: [PATH_TO_APP_ENGINE_SDK]/dev_appserver.py.
Tip: On Linux or Mac, you can run which dev_appserver.py to
determine which SDK is first in your PATH.

[400] The first service (module) you upload to a new application must be the 'default' service (module)

Before you can deploy and create the multiple services of your application,
you must first deploy and create the defaultservice. For
details about how to deploy a version to the default service,
see Deploying
multiple service applications.