oitmain-public / yii2-app-gae-flex

Yii2 App boilerplate for Google App Engine Flex Environment
Other
5 stars 2 forks source link

Questions: Setting Google configuration, credentials and Cloud SQL #1

Closed cbdelavenne closed 6 years ago

cbdelavenne commented 6 years ago

Hello!

First of all, thanks for making this boilerplate of Yii 2 for GAE Flex. It's been super useful already! With that said, I had some questions regarding additional configuration settings.

  1. For Yii 2 to connect correctly to CloudSQL correctly, where would you set the cloudsql connection name (i.e. your_project_name:your_region:your_instance)?
  2. Where would the Google Project ID be set?
  3. Do you know if Google OAuth would work with Yii 2 (providing we give it a generated Client ID and Secret)?

Most of my questions stem from following along the Google Cloud PHP Bookshelf App tutorial.

patrick-yi-82 commented 6 years ago
  1. Go to the advanced branch, and check out config/db.php, config/web-gae.php and env_variables section in app.yaml.dist
  2. See second paragraph in https://cloud.google.com/appengine/docs/flexible/php/configuring-your-app-with-app-yaml#app-id. (app.yaml isn't used)

However, in the flexible environment, the project ID (app ID) is specified either:

By using gcloud init when you install the Google Cloud SDK. To view the default project ID of the gcloud tool, run gcloud config list. By using the gcloud config set project [YOUR_PROJECT_ID] command to set the default project ID of the gcloud tool. By using the --project flag when you deploy your app, for example: gcloud app deploy --project [YOUR_PROJECT_ID]

  1. I never tried it, but I'm sure someone made a module of it already.
cbdelavenne commented 6 years ago

@patrick-yi-82 Thanks for getting back to me some quickly!

I was reviewing all the file differences between the master and advanced branched and identified:

Most of it is self-explanatory and makes for local dev/testing use vs GAE deployment.

While configuring my .env.dist file and renaming it to .env, I realized I have a few additional questions:

  1. I navigated to the link you suggested below, but I'm still a bit lost as to what you are suggesting here:
    # google cloud default credentials for local deployment
    # https://cloud.google.com/docs/authentication/getting-started#setting_the_environment_variable
    #GOOGLE_APPLICATION_CREDENTIALS=../your-credentials.json

    Could you clarify?

  2. You also have a # debug section that lists a DEBUG_IP (which I won't list here).
    • How do you use this said DEBUG_IP?
    • It probably shouldn't be set to the value it's set to right now given that it is an actual IP address ;)
  3. In config/web-gae.php and config/web-local.php, you have the same comment come up twice:
    // This configuration will be merged with web.php
    // See index.php for detail on merging

    What do you mean by this? Should I merge the contents of these files manually into config/web.php?

patrick-yi-82 commented 6 years ago
  1. GOOGLE_APPLICATION_CREDENTIALS By setting this env value, PHP Google Cloud library will automatically use that file as the default credential. (https://github.com/GoogleCloudPlatform/google-cloud-php#authentication)

  2. DEBUG_IP will let you access Yii2 debug and gii module from that IP

  3. In index.php, config from web-gae.php and web-local.php will automatically merge with config in web.php

$config = \yii\helpers\ArrayHelper::merge( require(DIR . '/../config/web.php'), require(DIR . '/../config/web-gae.php'), require(DIR . '/../config/web-local.php') );