You are here
Home > Php > Connect Google App Engine with Google Cloud SQL

Connect Google App Engine with Google Cloud SQL

app-engine-with-cloud-sql-featured

Hello Friends, Today we are going to learn how to connect Google App Engine with Google Cloud SQL. App Engine is a fully managed, serverless platform for developing and hosting web applications at scale while Cloud SQL is a fully-managed database service that makes it easy to set up, maintain, manage, and administer your relational databases on Google Cloud Platform. So, without wasting any time let’s do it by following below steps:-

Step 1: Login to Google Cloud Console and Create a Project

app-engine-with-cloudsql-create-project

Step 2: Select Project and Go to SQL

app-engine-with-cloudsql-select-project

Step 3: Create Cloud SQL Instance by following below screenshots & Copy Instance Connection Name and Paste in Text Editor for a while because we need it later

app-engine-with-cloudsql-create-sql-instance-1

app-engine-with-cloudsql-create-sql-instance-2

app-engine-with-cloudsql-create-sql-instance-3
Enter Instance ID and Password then Select Region, Zone and MySQL Version and Click Create
app-engine-with-cloudsql-create-sql-instance-4
Click on Instance ID to Open Overview of the Instance
 app-engine-with-cloudsql-create-sql-instance-5.jpg
Copy Instance Connection Name & Save it Temporary by pasting in any Text Editor

Step 4: Now click on Databases in Left Menu & Create Database

app-engine-with-cloudsql-create-database
Click Create Database then Popup will open then Type Database Name and Select Character set, Collation and Click Create

Step 5: Go to App Engine and Activate Cloud Shell and Execute below Command to Create Application or you can also click on Create Application and follow steps

app-engine-with-cloudsql-go-to-app-engine

app-engine-with-cloudsql-activate-cloud-shell

Step 6: After receiving success on Cloud Shell click on pencil icon to Launch Editor

app-engine-with-cloudsql-launch-editor

Step 7: Now It’s Time to Code

app.yaml

We configure our App Engine app’s settings in the app.yaml file. The app.yaml file also contains information about your app’s code, PHP runtime, and entrypoint.

Here we have pasted Connection Name obtained in step 3 just after unix_socket=/cloudsql/ and database name created in step 4 just after dbname=

config.php

index.php

contacts.php

contact-add.php

Step 8: Go to Editor which we had launched in step 6 and create directory connect-appengine-to-cloudsql by running below command in cloud shell and upload all the files into it created in step 7.

app-engine-with-cloudsql-create-directory

app-engine-with-cloudsql-upload-files

Step 9: Go inside connect-appengine-to-cloudsql directory using cd command and run below command to deploy your app and press y when asked, wait for a while and you are done.

app-engine-with-cloudsql-deploy

Step 10: Copy target url or the url highlighted in blue shown in step 9 and open it in new tab or window

app-engine-with-cloudsql-deployed

app-engine-with-cloudsql-deployed-2 app-engine-with-cloudsql-deployed-3 app-engine-with-cloudsql-deployed-4

Download Script

 

Thanks friends, I hope it helped
Please don’t forget to share

Rajesh Kumar Sahanee
I am a passionate Java Developer and I like Computer Programming. I love to do some interesting experiments and listening music in my free time.
https://www.zatackcoder.com

Comments

zatackcoder
Top