I've read the similar questions and I tried what they said, but I couldn't get my App Engine app to connect to my Cloud SQL instance.
Here's what I've found is supposed to be correct:
index.php
$servername = null;
$username = "root";
$password = "rootPassword";
$database = "NewApp";
$port = null;
$socket = "/cloudsql/newapp-edc:us-central1:newapp0";
$connection = new mysqli($servername,
$username,
$password,
$database,
$port,
$socket);
app.yaml
runtime: php72
entrypoint: serve index.php
env_variables:
# Replace USER, PASSWORD, DATABASE, and CONNECTION_NAME with the
# values obtained when configuring your Cloud SQL instance.
MYSQL_USER: root
MYSQL_PASSWORD: rootPassword
MYSQL_DSN: mysql:dbname=NewApp;unix_socket=/cloudsql/newapp-edc:us-central1:newapp0
# Use the connection name obtained when configuring your Cloud SQL instance.
beta_settings:
cloud_sql_instances: "newapp-edc:us-central1:newapp0"
I've gone through all of the similar questions and answers and all of the relevant Google Docs and I can't find the answer to this.
The current method results in "Connection refused
," which means, I think, that I have the socket correct as before it said, "No such file or directory
." Everything seems to be correct and I have permission for all apps in the same project, and the App Engine app and the Cloud SQL instance are in the same project, so that shouldn't be the issue.