Reputation: 3605
I have a Google App Engine application that operates perfectly when run locally using localhost:8080
, but after I deploy to the cloud using gcloud app deploy
, I receive the following error:
Warning: PDO::__construct(): MySQL server has gone away in /base/data/home/apps/s~fileabcd/20190320t221240.123456737151234567/gac_abcd.php on line 7
Warning: PDO::__construct(): Error while reading greeting packet. PID=-1 in /base/data/home/apps/s~fileabcd/20190320t221240.123456737151234567/gac_abcd.php on line 7
Any ideas why this is happening?
Upvotes: 0
Views: 142
Reputation: 3605
I discovered the reason why my Google App Engine (GAE) application functioned properly on localhost, but threw a MySQL server has gone away
error after being deployed to [PROJECT-ID].appspot.com.
The reason is because my application was connecting to a Cloud SQL instance in a different project, and in order to do this you must grant the default appengine service account ([PROJECT-ID]@appspot.gserviceaccount.com) one of the following IAM roles:
After I added the App Engine default service account as a Cloud SQL Client
Role in the project containing the Cloud SQL instance, everything worked perfectly.
From the Cloud SQL documentation.
Upvotes: 1