Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dhermann's avatar

Laravel on Cloud Run

I feel like I'm so close. I've finally got my app deploying to Cloud Run from Github without ever really learning Docker. It's exposed and I can connect to it. It deploys with every commit. Remarkable!

The issue is the connection to my Google SQL instance with a database named laravel and a new user (not root).

Desperate for help. Like, "Ready to go to Fiverr" desperate. I just need this unfathomably large architecture to run my silly tiny Laravel checklist webapp. Am I too dumb to use an "unmanaged" server?

Things I've Tried

  • I can connect via Cloudshell using the new user
  • I added Run Admin, SQL Client, Editor, and Service Account User roles to my IAM Compute default service account, which seems important
  • I left the SQL Instance -> Authorized Networks empty so the SQL Proxy can connect
  • I've tried change DB_HOST to localhost and the public IP address of the SQL instance
  • ChatGPT, Google quickstart articles, searching Laracasts forums
  • Watching the Codejet and Techguy videos

I use the Environment Variables section of the Cloud Run revision to set these values. Am I missing a required value?

APP_NAME=Appname
APP_ENV=prod
APP_KEY=base64:longstringhere
APP_DEBUG=true
APP_TIMEZONE=UTC
APP_URL=http://customdomain.com
APP_LOCALE=en

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=sail
DB_PASSWORD=password

There is an option at the bottom to use the SQL instance, which should automatically set up Cloud SQL Auth Proxy

Cloud SQL connections
  Cloud SQL instance 1
  appname-123456:us-central1:appname
Illuminate \ Database \ QueryException    PHP 8.3.6.  Laravel 11.0.8
SQLSTATE[HY000] [2002] Connection refused

select * from `sessions` where `id` = sessionidhere limit 1
0 likes
3 replies
flyingL123's avatar
Level 5

I think you need to remove the DB_HOST and DB_PORT variables, and instead use the DB_SOCKET environment variable. I have a cloud run app successfully connecting to CloudSQL instance using the following environment variables:

DB_DATABASE=db_name
DB_USERNAME=db_username
DB_PASSWORD=db_password
DB_SOCKET=/cloudsql/my-project:us-east1:my-db

Also, be sure you added your database as a "Cloud SQL Connection" to the Cloud Run container. This can be done through the Cloud Run UI.

1 like
dhermann's avatar

@flyingL123 Thank you, friend. I have never seen the DB_SOCKET variable so I gave up and switched to Forge. I hope someone else trying this infrastructure will find this post and leverage your answer.

Please or to participate in this conversation.