mercredi 18 juillet 2018

Connect cloud instance locally for laravel project running as service

I am trying to connect a Laravel to Google mysql instance locally.

.env file

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:GptV9AIxUX7TuPkKxbLs54DLjivt2wCmuG37qsnqxJU=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=**********
DB_USERNAME=**********
DB_PASSWORD=**********
DB_SOCKET=/cloudsql/[INSTANCE NAME]
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

I am using cloud_sql_proxy

~/Downloads/cloud_sql_proxy -instances=/cloudsql/[INSTANCE ID]=tcp:3306

and it working properly,

2018/07/18 13:46:29 Listening on 127.0.0.1:3306 for /cloudsql/[INSTANCE ID]
2018/07/18 13:46:29 Ready for new connections

I also enabled enabled Google Cloud SQL and Cloud SQL Admin API for my project and still I am getting error:

SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from `campaigns`)

as cloud instance is refusing the connection.

Below are my observation in struggle to find a solution.

  1. In Stackdriver logging error that I see is

    severity: "ERROR" textPayload: "2018-07-18T05:57:08.204597Z 859643 [Note] Aborted connection 859643 to db: '[DB_NAME]' user: '[DB_USER]' host: 'cloudsqlproxy~173.194.90.33' (Got an error reading communication packets)"

  1. When I check

    $ ~/Downloads/cloud_sql_proxy info 2018/07/18 14:10:50 Using gcloud's active project: [PROJECT ID] 2018/07/18 14:10:55 must set -dir: using a unix socket for [INSTANCE NAME]

I am actually not able to relate if this is related to error

  1. I have tried connecting cloud sql using service account, its connects properly but still not able to resolve this issue.

Thanks in advance.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire