我在Lumen开发了一个API,并将其部署在GAE上。为此,我遵循了this教程。在部署API之前,它运行良好,但是当我尝试访问cloud-sql实例上的数据库时出现了问题。我无法以上述教程中描述的方式访问数据库。然后,我尝试了不同的解决方案,但它们都不起作用。最后,仅出于测试目的,我在cloud-sql实例及其当前工作的授权列表中添加了实例IP地址(部署GAE的位置)。但这是一个临时解决方案,因为实例部署在VM上,并且它们的IP地址可以随时更改,这将中断GAE和cloud-sql之间的连接。任何解决方案或建议将不胜感激。 尽管我尝试通过多种方式更改App.yaml,但仍在下面给出了
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_ENV: production
APP_DEBUG: true
#QUEUE_DRIVER: sync
APP_LOG: errorlog
APP_KEY: 32 char key
STORAGE_DIR: /tmp
CACHE_DRIVER: database
SESSION_DRIVER: database
#APP_TIMEZONE: UTC
## Set these environment variables according to your CloudSQL configuration.
DB_HOST: 127.0.0.1
DB_DATABASE: dbname
DB_USERNAME: root
DB_PASSWORD: pass
DB_SOCKET: "/cloudsql/Instance Connection Name"
MYSQL_DSN: "mysql:unix_socket=/Instance Connection Name;dbname=dbname"
MYSQL_USER: root
MYSQL_PASSWORD: pass
beta_settings:
# for Cloud SQL, set this value to the Cloud SQL connection name,
# e.g. "project:region:cloudsql-instance"
cloud_sql_instances: "Instance Connection Name"