将laravel GC应用引擎连接到GC SQL postgres时出现问题

tktrz96b  于 2023-03-04  发布在  其他
关注(0)|答案(1)|浏览(125)

我尝试将我的Laravel应用程序(存储在谷歌云应用引擎上)连接到我的Postgresql数据库(存储在谷歌云SQL上)。
这是错误:SQLSTATE[08006] [7] could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432? (Connection: pgsql, SQL: select * from "roles")
我没有发现我的错误,许多解决方案都是针对mysql的(对我来说不起作用)。
你可以在这里找到应用程序。

runtime: php81
env: standard

runtime_config:
 document_root: public

handlers:
- url: /(.*\.(gif|png|jpg|css|js))$
  static_files: public/\1
  upload: public/.*\.(gif|png|jpg|css|js)$

- url: /.*
  secure: always
  redirect_http_response_code: 301
  script: auto

beta_settings:
  cloud_sql_instances: app-id:zone:instance=tcp:5432

env_variables:
  APP_DEBUG: true
  APP_ENV: production
  APP_LOG: errorlog
  APP_KEY: my_app_key
  APP_STORAGE: /tmp
  VIEW_COMPILED_PATH: /tmp
  CACHE_DRIVER: file
  SESSION_DRIVER: cookie
  DB_CONNECTION: pgsql
  DB_HOST: localhost
  DB_PORT: 5432
  DB_DATABASE: postgres
  DB_USERNAME: instance
  DB_PASSWORD: password
  DB_SOCKET: /cloudsql/app-id:zone:instance
  LOG_CHANNEL: stderr
  JWT_SECRET: my-jwt-secret

我尝试用 * 127.0.0.1 public_ip * 和 * private_ip * 替换DB_HOST,但没有结果:(
谢谢你的帮忙

gwbalxhn

gwbalxhn1#

尝试使用以下env变量:

## for MYSQL, use DB_SOCKET:
  ## for PostgreSQL, use DB_HOST:
  DB_HOST: "/cloudsql/YOUR_CONNECTION_NAME"

相关问题