获取SQLSTATE [HY000] [2002]在AppEngine上没有这样的文件或目录

I have deployed application on gcloud App Engine, I deployed successfully but getting SQLSTATE[HY000] [2002] No such file or directory while it working fine on local system. I am following https://cloud.google.com/community/tutorials/run-laravel-on-appengine-flexible this tutorial.

I also followed https://www.youtube.com/watch?v=QhQ1PrYH3q0&t=230s but getting same issue.

Webstie url : https://phpsipl1.appspot.com/

My app.yml file is:

runtime: php
env: flex

runtime_config:
  document_root: public

# Ensure we skip ".env", which is only for local development
skip_files:
  - .env

env_variables:

  # Put production environment variables here.

  APP_LOG: errorlog
  APP_KEY: base64:DZaQGd2hg/irj0YeTQtZxb3bY6Em25gMlLmoY8oDK7E=
  STORAGE_DIR: /tmp
  CACHE_DRIVER: database
  SESSION_DRIVER: database
  DB_HOST: localhost
  DB_DATABASE: blog
  DB_USERNAME: root
  DB_PASSWORD: target@2017
  DB_SOCKET: "/cloudsql/phpsipl1:us-central1:phpsipl"
beta_settings:
  cloud_sql_instances: "phpsipl1:us-central1:phpsipl" 

Please help me.

Moin,

can you try to use 127.0.0.1 instead of localhost in your config. In MySQL terms there is a difference between 127.0.0.1 and localhost regarding connection to sockets. See https://serverfault.com/questions/295285/mysql-cannot-connect-via-localhost-only-127-0-0-1 for more information.

I also had the same issue but adding DB_CONNECTION: mysql to the env_variables in my app.yaml did the trick for me.