Forum

App Engine Quicksta...
 
Notifications
Clear all

App Engine Quickstart - PHP

1 Posts
1 Users
0 Likes
2,371 Views
Posts: 108
Topic starter
(@taichi)
Member
Joined: 4 years ago

Learn how to create and deploy a Hello World app.

 

Start a Standard Environment Guided Walkthrough

Start a Flexible Environment Guided Walkthrough

App Engine quickstart

Introduction

This tutorial shows you how to deploy a sample application to App Engine using the gcloud command.

Here are the steps that you will be taking:

  • Create a project

    Projects bundle code, VMs and other resources together for easier development and monitoring.

  • Build and run your 'Hello, World!' app

    You will learn how to run your app using Cloud Shell, directly in your browser. At the end, you'll deploy your app to the web using the gcloud command.

  • After the tutorial…

    Your app will be real and you'll be able to experiment with it after you deploy, or you can remove it and start afresh.

Project setup

GCP organises resources into projects, which collect all of the related resources for a single application in one place.

Begin by creating a new project or selecting an existing project for this tutorial.

Select a project, or

 

Using Cloud Shell

Cloud Shell is a built-in command-line tool for the console. We're going to use Cloud Shell to deploy our app.

Open Cloud Shell

Open Cloud Shell by clicking the  button in the navigation bar in the upper-right corner of the console.

Clone the sample code

Use Cloud Shell to clone and navigate to the 'Hello World' code. The sample code is cloned from your project repository to the Cloud Shell.

Note: If the directory already exists, remove the previous files before cloning.

Then switch to the tutorial directory:

cd \ php-docs-samples/appengine/php72/helloworld

 

jyan@cloudshell:~ (jyan-51sec-org-test1)$ ls
examples  https:  README-cloudshell.txt
jyan@cloudshell:~ (jyan-51sec-org-test1)$ git clone \
>      https://github.com/GoogleCloudPlatform/php-docs-samples 
Cloning into 'php-docs-samples'...
remote: Enumerating objects: 24, done.
remote: Counting objects: 100% (24/24), done.
remote: Compressing objects: 100% (15/15), done.
remote: Total 13788 (delta 13), reused 15 (delta 9), pack-reused 13764
Receiving objects: 100% (13788/13788), 12.30 MiB | 30.42 MiB/s, done.
Resolving deltas: 100% (8979/8979), done.
jyan@cloudshell:~ (jyan-51sec-org-test1)$ ls
examples  https:  php-docs-samples  README-cloudshell.txt
jyan@cloudshell:~ (jyan-51sec-org-test1)$ cd \
>     php-docs-samples/appengine/php72/helloworld
jyan@cloudshell:~/php-docs-samples/appengine/php72/helloworld (jyan-51sec-org-test1)$


Configuring your deployment

You are now in the main directory for the sample code. We'll look at the files that configure your application.

Exploring the application

Enter the following command to view your application code:

cat index.php
 
Exploring your configuration

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.

Enter the following command to view your configuration file:

cat app.yaml
 
The syntax of this file is YAML. For a complete list of configuration options, see the app.yaml reference.

Testing your app

Test your app on Cloud Shell

Cloud Shell lets you test your app before deploying to make sure that it's running as intended, just like debugging on your local machine.

To test your app, enter the following:

php -S localhost:8080
 
 
Preview your app with 'Web preview'

Your app is now running on Cloud Shell. You can access the app by clicking the  

 
 

 button at the top of the Cloud Shell pane and choosing Preview on port 8080.

Terminating the preview web server

Terminate the web server for previewing your application by pressing Ctrl+C in Cloud Shell.

K29odXt.png (1553×908)


Deploying to App Engine

Create an application

To deploy your app, you need to create an app in a region:

gcloud app create
 
jyan@cloudshell:~/php-docs-samples/appengine/php72/helloworld (jyan-51sec-org-test1)$ gcloud app create
You are creating an app for project [jyan-51sec-org-test1].
WARNING: Creating an App Engine application for a project is irreversible and the region
cannot be changed. More information about regions is at
< https://cloud.google.com/appengine/docs/locations>. 

Please choose the region where you want your App Engine application
located:

 [1] asia-east2    (supports standard and flexible)
 [2] asia-northeast1 (supports standard and flexible)
 [3] asia-northeast2 (supports standard and flexible)
 [4] asia-northeast3 (supports standard and flexible)
 [5] asia-south1   (supports standard and flexible)
 [6] asia-southeast2 (supports standard and flexible)
 [7] australia-southeast1 (supports standard and flexible)
 [8] europe-west   (supports standard and flexible)
 [9] europe-west2  (supports standard and flexible)
 [10] europe-west3  (supports standard and flexible)
 [11] europe-west6  (supports standard and flexible)
 [12] northamerica-northeast1 (supports standard and flexible)
 [13] southamerica-east1 (supports standard and flexible)
 [14] us-central    (supports standard and flexible)
 [15] us-east1      (supports standard and flexible)
 [16] us-east4      (supports standard and flexible)
 [17] us-west2      (supports standard and flexible)
 [18] us-west3      (supports standard and flexible)
 [19] us-west4      (supports standard and flexible)
 [20] cancel
Please enter your numeric choice:  15

Creating App Engine application in project [jyan-51sec-org-test1] and region [us-east1]....done.
Success! The app is now created. Please use `gcloud app deploy` to deploy your first app.
 

Note: If you've already created an app, you can skip this step.

Deploying with Cloud Shell

You can use Cloud Shell to deploy your app. To deploy your app, enter the following:

gcloud app deploy
 
 
 
 

Visit your app

Congratulations! Your app has been deployed. The default URL of your app is a subdomain on appspot.com that starts with your project's ID: jyan-51sec-org-test1.appspot.com.

Try visiting your deployed application.

 

Disable your application

  1. Go to the  page.

  2. Click .

This is sufficient to stop billing from this app. More details on the relationship between apps and projects and how to manage each can be found here.

Delete your project

If you would like to completely delete the app, you must delete the project in the Manage resources page. This is not reversible, and any other resources that you have in your project will be destroyed:

  1. Go to

    IAM & admin

    .

     

  2. Click .

  3. Click .

 

 

 

Share: