【问题标题】:Connecting Laravel to GAE Cloud SQL Database with PostgreSQL使用 PostgreSQL 将 Laravel 连接到 GAE Cloud SQL 数据库
【发布时间】:2019-02-03 08:53:30
【问题描述】:

我正在向 Google App Engine Flex 环境部署一个新应用程序。该应用由 Laravel 提供支持。

我能够连接到本地计算机上的数据库,但是,一旦我部署了我的应用程序,我就无法连接到数据库。

我需要在 app.yaml 文件中包含哪些信息才能连接到数据库?我是否需要其他文件中的任何其他信息?

"message": "SQLSTATE[08006] [7] could not connect to server: Connection refused\n\tIs the server running on host \"localhost\" (::1) and accepting\n\tTCP/IP connections on port 5432?\ncould not connect to server: Connection refused\n\tIs the server running on host \"localhost\" (127.0.0.1) and accepting\n\tTCP/IP connections on port 5432? (SQL: select * from \"users\" where \"email\" = mitchell@efficialtec.com and \"users\".\"deleted_at\" is null limit 1)",

这是我的 .ENV 文件的内容,它允许我在本地连接

APP_ENV=development
APP_KEY=base64:B0G3Yr82fWO7xw8LrvcOC19DGUAEd32loJlPHCfP2sg=
APP_DEBUG=true

LOG_CHANNEL=stack


DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_POST=5432
DB_DATABASE=DATABASE
DB_USERNAME=USERNAME
DB_PASSWORD=PASSWORD
DB_SOCKET: "/cloudsql/CONNECTION_NAME"

这是我的 app.yaml 文件的内容:

env: flex     # let app engine know we use flexible environment
service: SERVICENAME

automatic_scaling:
  min_num_instances: 1
  max_num_instances: 2
  cpu_utilization:
    target_utilization: 0.8

runtime_config:
  document_root: public

skip_files:
  - .env #we want to skip this to make sure we don’t mess stuff up on the server

env_variables:
  # Put production environment variables here.
  APP_ENV: development
  APP_DEBUG : true # or false 
  APP_KEY: base64:B0G3Yr82fWO7xw8LrvcOC19DGUAEd32loJlPHCfP2sg=
  APP_LOG: daily
  APP_TIMEZONE: UTC #your timezone of choice


  # Replace USER, PASSWORD, DATABASE, and CONNECTION_NAME with the
  # values obtained when configuring your Cloud SQL instance.
  POSTGRES_USER: USERNAME
  POSTGRES_PASSWORD: PASSWORD
  POSTGRES_DSN: pgsql:dbname=bnsw;host=/cloudsql/CONNECTION_NAME"

  DB_HOST: localhost
  DB_DATABASE: DATABASE
  DB_USERNAME: USERNAME
  DB_PASSWORD: PASSWORD
  DB_SOCKET: "/cloudsql/CONNECTION_NAME" 

beta_settings:
  cloud_sql_instances: "CONNECTION_NAME"

非常感谢您对此提供任何帮助,我已经在 Google 上查找了将近一个星期,但还没有答案!

【问题讨论】:

    标签: laravel postgresql google-app-engine google-cloud-platform


    【解决方案1】:

    默认情况下,Laravel 在pgsql 连接下没有 DB_SOCKET。 因此,为了从应用引擎连接到云 SQL 连接,您的环境显示如下:

    DB_CONNECTION=pgsql
    DB_HOST=/cloudsql/CONNECTION_NAME
    DB_DATABASE=DATABASE
    DB_USERNAME=USERNAME
    DB_PASSWORD=PASSWORD
    

    另外,请不要在数据库环境变量中包含 DB_PORT。

    【讨论】:

      猜你喜欢
      • 2023-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-12
      • 2018-05-25
      • 2019-04-18
      • 2018-08-04
      • 2021-04-15
      相关资源
      最近更新 更多