You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel部署GAE后无法连接Cloud SQL:实例未找到问题求助

Fixing Laravel 5.6 + Cloud SQL Connection Issues on App Engine Flexible

Let’s work through your connection problems step by step to get your Laravel app talking to Cloud SQL:

1. Resolve the gcloud sql instances describe Error

The error you’re seeing means either you’re in the wrong Google Cloud project, or there’s a typo in your instance name. Here’s how to fix it:

  • First, list all your projects to confirm the correct project ID:
    gcloud projects list
    
  • Set your active project to the one where you created the laraveljwtstarter instance:
    gcloud config set project YOUR_CORRECT_PROJECT_ID
    
  • Re-run the describe command to verify access:
    gcloud sql instances describe laraveljwtstarter
    
    This will return your instance’s details, including the connection name (format: PROJECT_ID:REGION:INSTANCE_NAME). Save this value—you’ll need it for both local and App Engine connections.

2. Connect Locally with Cloud SQL Proxy

Once you have the connection name, set up the proxy correctly to link your MacBook to Cloud SQL:

  • Start the proxy using your instance’s connection name:
    ./cloud_sql_proxy -instances=YOUR_CONNECTION_NAME=tcp:3306
    
  • Update your Laravel .env file for local development:
    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=3306
    DB_DATABASE=YOUR_DATABASE_NAME # Ensure this exists in your Cloud SQL instance
    DB_USERNAME=YOUR_DB_USER # The user you created for the instance
    DB_PASSWORD=YOUR_DB_PASSWORD # The user's password
    
  • Test the connection by running migrations:
    php artisan migrate
    

3. Configure App Engine Flexible to Connect to Cloud SQL

For your deployed app to connect to Cloud SQL, update your app.yaml with these settings:

  • Add environment variables for the database connection:
    env_variables:
        APP_KEY: YOUR_LARAVEL_APP_KEY
        DB_CONNECTION: mysql
        DB_HOST: '/cloudsql/YOUR_CONNECTION_NAME'
        DB_DATABASE: YOUR_DATABASE_NAME
        DB_USERNAME: YOUR_DB_USER
        DB_PASSWORD: YOUR_DB_PASSWORD
    
  • Add the beta setting to link the Cloud SQL instance to your App Engine service:
    beta_settings:
        cloud_sql_instances: YOUR_CONNECTION_NAME
    
  • Redeploy your app to apply changes:
    gcloud app deploy
    

4. Double-Check Critical Details

Make sure these boxes are ticked:

  • The database name you’re using exists in your Cloud SQL instance (create it via the GCP Console or using the proxy with a MySQL client).
  • Your database user has SELECT, INSERT, UPDATE, DELETE permissions on the target database (configure this in the GCP Console under Cloud SQL > Users).

Follow these steps, and your Laravel app should connect to Cloud SQL both locally and on App Engine Flexible without issues.

内容的提问来源于stack exchange,提问作者Connor Leech

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 07:03:44