2

I'm able to deploy php application in google cloud by configuring app.yaml for Standard and Flexible environments separately.

'app.yaml' For Standard Environment:

 runtime: php55
 api_version: 1
 threadsafe: true

 handlers:
  - url: /.*
  script: helloworld.php

  - url: /fileUpload.php
  script: fileUpload.php

'app.yaml' For Flexible Environment:

 runtime: php55
 env: flex  # flexible env
 api_version: 1
 threadsafe: true

 handlers:
  - url: /.*
  script: helloworld.php

  - url: /fileUpload.php
  script: fileUpload.php

Now i want to use both environments in single application.

1. Standard environment for the URL of helloworld.php
2. Flexible environment for the URL of fileUpload.php

so please suggest me the structure of this application.
Thanks in Advance

I tried with below structure but it's not working..

|-dispatch.yaml
|-standard
|-app.yaml
|-helloworld.php
|-flexible
|-app.yaml
|-fileUpload.php

dispatch.yaml code:

dispatch:
- url: "*/fileupload/*"
  service: flex-module
- url: "/.*"
  service: default

How to utilize both standard & flexible environments within a single application?

Example:
Domain: example.com

  1. if we access url 'example.com/' or 'example.com/helloworld.php' : then it will use the standard environment.

  2. if we access url 'example.com/fileupload.php' : then it will use the flexible environment.

is it possible, to process above two conditions?

Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
  • Thanks for the reply @Mangu it's single application only, not two subapps. Example: Domain: example.com 1. if we access url 'example.com/' or 'example.com/helloworld.php' : then it will use the standard environment. 2. if we access url 'example.com/fileupload.php' : then it will use the flexible environment. is it possible, to process above two conditions? – Nagendra Babu Nov 15 '18 at 11:30

2 Answers2

1

The environments on google cloud are per app. if you want to deploy on different environments they must be separated apps or a least the same copy on different microservices. Not a single deployment for two different enviroments.

this is for the stantard environment but is the same concept https://cloud.google.com/appengine/docs/standard/php/microservices-on-app-engine each module or microserivice is an app by itself. beacuse it manage its own resources besides the ones being shared such the database ect.

0

Yes it's possible: you'd have a single GAE application (i.e. a single GCP project) with 2 services, one standard and one flex. You pretty much started in this direction, but you missed a few things.

The runtime is incorrect and you're missing the service naming of the (non-default) flex-module app.yaml. From General settings:

runtime: php

This setting is required. It is the name of the App Engine language runtime used by this application. To specify PHP, use php. Other runtimes are available; refer to each language's documentation for more info.

service: service_name

Required if creating a service. Optional for the default service. Each service and each version must have a name. A name can contain numbers, letters, and hyphens. It cannot be longer than 63 characters and cannot start or end with a hyphen. Choose a unique name for each service and each version. Don't reuse names between services and versions.

You can also drop the standard env configs in this file - they're ignored presently but just in case the check become more strict down the road). Maybe peek at the somehow related How to tell if a Google App Engine documentation page applies to the standard or the flexible environment

 runtime: php
 env: flex  # flexible env
 service: flex-module

You should check The runtime_config section as well, it appears to be mandatory, but I'm not a PHP user, I don't know what to suggest here:

You must configure document_root in the runtime_config section, such as in the example above.

You need to be careful with your dispatch.yaml content. The pattern for the flex service doesn't match the URL you chose for that service, it needs to. You can also drop the default service pattern at the end - anything not matching the specified route patterns goes to the default service anyways.

dispatch:
  - url: "*/fileUpload.php"
    service: flex-module

Note: I always used a directory pattern in dispatch.yaml - i.e. - url: "*/some_dir/*" - never just a specific file, I'm not 100% certain the above will work, it may need some tweaking if it doesn't.

In the default service's app.yaml you can drop the handler for the upload - that would be handled by flex-module. Just cosmetic.

Also take care at deployment - you have 3 deployables: the 2 services (deployed by deploying the respective app.yaml files) and the dispatch.yaml file which must be specifically deployed. Any combination of the 3 .yaml files can be included in a single deployment command (but that's just convenience, under the hood each of them is actually deployed separately):

gcloud app deploy standard/app.yaml flexible/app.yaml dispatch.yaml
Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97