I am trying to connect a Google Compute Engine instance with a MySQL database to Google App Engine using Laravel. I actually have connected my Google App Engine to a Cloud SQL instance, I don't have problem with this, but I need an additional database connection with the database located on Google Compute Engine.
Google Compute Engine instance is on a different project. This is my scheme:
Project A -> Compute Engine -> Instance -> MySQL database
Project B -> App Engine -> Laravel
Project B -> Cloud SQL -> DB-instance -> MySQL database
This is my app.yaml file:
runtime: php
env: flex
runtime_config:
document_root: public
# Ensure we skip ".env", which is only for local development
skip_files:
- .env
env_variables:
# Put production environment variables here.
APP_LOG: "errorlog"
APP_KEY: "[KEY]"
STORAGE_DIR: "/tmp"
CACHE_DRIVER: "database"
SESSION_DRIVER: "database"
APP_DEBUG: "true"
#CLOUD SQL database connection
DB_CONNECTION: "[DATABASE_1_NAME]"
DB_HOST: "[CLOUD_SQL_INSTANCE_NAME]"
DB_DATABASE: "[DATABASE_1_NAME]"
DB_USERNAME: "root"
DB_PASSWORD: "[PASSWORD]"
DB_SOCKET: "/cloudsql/[PROJECTB]:[REGION]:[CLOUD_SQL_INSTANCE_NAME]"
# COMPUTE ENGINE database connection
DB_HOST_2: "[COMPUTE_ENGINE_INSTANCE_NAME]"
DB_DATABASE_2: "[DATABASE_2_NAME]"
DB_USERNAME_2: "root"
DB_PASSWORD_2: "[PASSWORD]"
beta_settings:
cloud_sql_instances: "[PROJECTB]:[REGION]:[CLOUD_SQL_INSTANCE_NAME]"