Not able to connect Laravel application on App Engine to Cloud SQL database

元气小坏坏 提交于 2021-02-10 16:44:33

问题


I have a Laravel application running on Google App Engine and I want to connect it to the Google Cloud SQL database I have. I have tried many solutions none of them fixed the problem. Everytime it does a request to the database, it throws
SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from sessions where id = CQZwtQFAm5RCYcP4ZSqf5mtxTnebGUigQQKVluJa limit 1).
I do have the sessions table, and I also get this error while trying to log in but with the users table then.

I've trying changing up all the environment variables, editing the config/database.php file, ...

Heres my app.yaml:

runtime: php
env: flex

runtime_config:
  document_root: public

env_variables:
  APP_ENV: production
  APP_DEBUG: true
  APP_LOG: errorlog
  APP_KEY: mykey
  APP_TIMEZONE: "Europe/Brussels"
  CACHE_DRIVER: database
  SESSION_DRIVER: database

  DB_HOST: localhost
  DB_DATABASE: data
  DB_USERNAME: root # tried custom user aswell
  DB_PASSWORD: mypassword
  DB_SOCKET: "/cloudsql/projectname:region:instancename"

beta_settings:
  cloud_sql_instances: "projectname:region:instancename"

Here is a part of config/database.php (mostly unedited):

'mysql' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],

Obviously I want this connection to be succesful. Let me know if you need any more code parts.

Thanks in advance


回答1:


please change this line:

cloud_sql_instances: "projectname:region:instancename"

into this line:

cloud_sql_instances:projectname:region:instancename

If that doesn't work, please check this link and activate your API if you haven't done so.

Also, if enabling the API didn't solve the issue, please revert the cloud_sql_instances variable to having double quotes on the value.



来源:https://stackoverflow.com/questions/57728725/not-able-to-connect-laravel-application-on-app-engine-to-cloud-sql-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!