Skip to content

Yii2 App boilerplate for Google App Engine Flex Environment

License

Notifications You must be signed in to change notification settings

oitmain-public/yii2-app-gae-flex

Repository files navigation

yii2-app-gae-flex

Create Yii2 basic application for deploy on Google App Engine (Flex Environment)

Flex Environment allows read and write on the directory sys_get_temp_dir(), which allows Yii2 to use the runtime folder

However, static assets are uploaded into Google Storage for public access

(Advance branch adds local environment support and pretty url)

Instruction for advance branch : https://github.com/oitmain-public/yii2-app-gae-flex/blob/advanced/README.md

Prerequisites

  • Create a Google Storage bucket with permission Storage Object Viewer to allUsers
  • Create a json key file for user @appspot.gserviceaccount.com
  • Enable "Google App Engine Admin API"
  • Enable "Google App Engine Flexible Environment"
  • Enable "Cloud SQL API" on app engine project
  • Enable "Google Service Management API"
  • Enable cors on new storage bucket
$ echo '[{"origin": ["*"],"responseHeader": ["Content-Type"],"method": ["GET", "HEAD"],"maxAgeSeconds": 3600}]' > cors-config.json \
&& gsutil cors set cors-config.json gs://<your-bucket-name>

Installalion

Clone project and install composer requirements

$ git clone https://github.com/oitmain-public/yii2-app-gae-flex
$ # For Advanced app, clone following branch instead
$ # git clone -b advanced https://github.com/oitmain-public/yii2-app-gae-flex
$ cd yii2-app-gae-flex
$ composer install

Copy and update configuration files

$ cp app.yaml.dist app.yaml

Update config/web.php

  • assetsManager and cookieValidationKey

Local Deployment

$ php -S localhost:8080 -t web/

Deploy to Google App Engine

See https://cloud.google.com/appengine/docs/flexible/php/testing-and-deploying-your-app

$ gcloud app deploy —version [YOUR_VERSION_ID] —no-promote —project [YOUR_PROJECT_ID] 

Google Cloud SQL

Troubleshooting

  • A circular dependency is detected for bundle
    • This error occurs when asset bundle is called twice. Once for front view, and once for error view.   * Use app\models\PhpErrorHandler to see the actual error without calling the error view