[英]PHP Laravel is not able to connect to cloud sql on google could appengine
I am trying to connect my laravel application to MySQL instance on Cloud SQL.我正在尝试将我的 laravel 应用程序连接到云 SQL 上的 MySQL 实例。 I get the error:
SQLSTATE[HY000] [2002] No such file or directory
我收到错误:
SQLSTATE[HY000] [2002] No such file or directory
I am following this tutorial https://cloud.google.com/community/tutorials/run-laravel-on-appengine-flexible .我正在关注本教程https://cloud.google.com/community/tutorials/run-laravel-on-appengine-flexible 。
I have the following app.yaml我有以下app.yaml
runtime: php
env: flex
runtime_config:
document_root: public
env_variables:
## Put production environment variables here.
APP_NAME: MyApp
APP_ENV: dev
APP_DEBUG: true
APP_KEY: base64:AEoXa4s+7hRiWuFnFcR+Xm/he891r1wpM3tGfkH7lqQ=
APP_STORAGE: /tmp
VIEW_COMPILED_PATH: /tmp
SESSION_DRIVER: database
CACHE_DRIVER: database
MAPS_GOOGLE_KEY: <SOME_KEY>
## Database Configurations
DB_CONNECTION: mysql
DB_PORT: 3306
DB_DATABASE: <NAME>
DB_USERNAME: root
DB_PASSWORD: <PASSWORD>
DB_SOCKET: '/cloudsql/<CONNECTION_NAME>'
LOG_CHANNEL: stackdriver
beta_settings:
cloud_sql_instances: sourcing-279920:<CONNECTION_NAME>=tcp:3306
automatic_scaling:
min_num_instances: 1
max_num_instances: 7
Where Also, I enabled the SQL Admin API.此外,我启用了 SQL 管理员 API。
composer.json作曲家.json
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require": {
"php": "^7.2.5",
"fideloper/proxy": "^4.2",
"fruitcake/laravel-cors": "^1.0",
"gonoware/laravel-maps": "^1.3",
"google/cloud-error-reporting": "^0.16.4",
"google/cloud-logging": "^1.20",
"guzzlehttp/guzzle": "^6.3",
"laravel-frontend-presets/bulma": "^3.0",
"laravel/framework": "^7.0",
"laravel/tinker": "^2.0"
},
"require-dev": {
"facade/ignition": "^2.0",
"fzaninotto/faker": "^1.9.1",
"mockery/mockery": "^1.3.1",
"nunomaduro/collision": "^4.1",
"phpunit/phpunit": "^8.5"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"autoload": {
"psr-4": {
"App\\": "app/"
},
"classmap": [
"database/seeds",
"database/factories"
]
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
],
"post-install-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postInstall",
"php artisan optimize",
"chmod -R 755 bootstrap/cache",
"php artisan config:cache",
"php artisan migrate",
"php artisan db:seed"
]
}
}
PS: I am able to connect through the proxy. PS:我可以通过代理连接。
Thanks for your help.谢谢你的帮助。
First I think that cloud_sql_instances:
in beta_settings
should be in quotation marks.首先我认为
cloud_sql_instances:
in beta_settings
应该用引号引起来。
If this is not solve the problem, you can try to check this Github issue which is linking to another issue that seems to contain resolution.如果这不能解决问题,您可以尝试检查这个Github 问题,它链接到另一个似乎包含解决方案的问题。
I found something like that here on SO as well.我在 SO 上也发现了类似的东西。
I hope it will help to solve it!我希望它会帮助解决它!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.