Google App Engine is a web framework and cloud computing platform for developing and hosting web applications in Google-managed Data Centers.
- Create a new project or Select an existing project to host.
- Select Language (Here we are using PHP)
- Select the region/location that would like to serve our app.
- Click the Activate Google Cloud Shell button at the top of the console window.
Now will get the Google cloud shell
- Add your project directory. (You can upload or clone from git using the git clone command).
- Then goto inside of your project directory using cd command.
- Create configuration file app.yaml
Google App Engine uses YAML files to specify a deployment's configuration. app.yaml files contain information about your application, like the runtime environment, URL handlers, and more.
- To import your project database from your local server system (localhost), export it from localhost.
- Select Storage under STORAGE from GCP left panel.
- Create a bucket (Storage) in Storage page, and upload the sql file, which is exported from localhost.
- Select SQL under STORAGE from GCP left panel.
- Create Cloud SQL Instance to make database connectivity by clicking Create Instance.
- Then continue with MySQL and choose MySQL Second Generation.
- Provide Instance details including instance id, root password, region etc.
- After instance creation completed, click on the instance id to open instance details and create new database by clicking database tab from there.
- Then click the Import tab, and select the sql file of your project from the bucket you created.
- Before clicking the Import button, click on advanced options while importing, and select the database you already created.
- The connection query of MySQLi is different from the normal query. So, we need to edit the database connection query.
$con=new mysqli (NULL, ”<username>”, ”<password>”, ”<database-name>”, NULL, ”/cloudsql/< instance id> “);
Note : If password is null, then provide as NULL
- Now deploy your app using the command
gcloud app deploy app.yaml --project <project id>
- Now you will get a URL. You can use this URL to open your hosted app.