This quickstart shows you how to create a small App Engine application that displays a short message.
Before you begin
Before running and deploying this quickstart, you must set up a GCP project for App Engine and then install the Cloud SDK:
Create a new GCP project and App Engine application using the GCP Console:
When prompted, select the region where you want your App Engine application located. After your App Engine application is created, the Dashboard opens.
Download and install the Cloud SDK. Follow the instructions in the Cloud SDK page to initialize and set your GCP project ID in the
Run the following command to install the
gcloudcomponent that includes the App Engine extension for PHP:
gcloud components install app-engine-php
App Engine locations
App Engine is regional, which means the infrastructure that runs your apps is located in a specific region and is managed by Google to be redundantly available across all the zones within that region.
Meeting your latency, availability, or durability requirements are primary factors for selecting the region where your apps are run. You can generally select the region nearest to your app's users but you should consider the location of the other GCP products and services that are used by your app. Using services across multiple locations can affect your app's latency as well as pricing.
App Engine is available in the following regions:
southamerica-east1(São Paulo) *
* For customers using the São Paulo region, all regional product SLAs remain in force. However, multi-region and cross-region functionality that span across North America and South America might temporarily have reduced availability or performance.
You cannot change an app's region after you set it.
If you already created an App Engine application, you can view the
region by running the
gcloud app describe command or opening the
App Engine Dashboard in the GCP Console.
The region of your App Engine application is listed under
Download the Hello World app
We've created a simple Hello World app for PHP so you can quickly get a feel for deploying an app to Google Cloud Platform. Follow these steps to download Hello World to your local machine.
Clone the Hello World sample app repository to your local machine in a directory called
git clone -b phase0-helloworld https://github.com/GoogleCloudPlatform/appengine-php-guestbook.git helloworld
Then go to the directory that contains the sample code:
Alternatively, you can download the sample
as a .zip file and extract it into a directory called
Test the application
Test the application using the local development server (
which is included with the SDK.
From within the
helloworlddirectory where the app's app.yaml configuration file is located, start the local development server with the following command:
python dev_appserver.py app.yaml
The local development server is now running and listening for requests on port 8080. Something go wrong?
Visit http://localhost:8080/ in your web browser to view the app.
Running the local development server (
To run the local development server, you can either run
specifying the full directory path or you can add
dev_appserver.py to your
PATH environment variable:
If you installed the original App Engine SDK, the tool is located at:
If you installed the Google Cloud SDK, the tool is located at:
Tip: To add the Google Cloud SDK tools to your
PATHenvironment variable and enable command-completion in your shell, you can run:
For more information about running the local development server including how to change the port number, see the Local Development Server reference.
Make a change
You can leave the development server running while you develop your application. The development server watches for changes in your project files, and reloads them if necessary.
- Try it now: Leave the development server running, then edit
Hello, World!to something else.
- Reload http://localhost:8080/.
Deploy your app
To deploy your app to App Engine, run the following command from within the root
directory of your application where the
app.yaml file is located:
gcloud app deploy
Learn about the optional flags.
gcloud command flags
--versionflag to specify an ID that uniquely identifies that version of your app, otherwise one is generated for you. Example:
--projectflag to specify an alternate GCP project ID to what you initialized as the default in the
gcloud app deploy --version pre-prod-5 --project my-sample-app
View your application
To launch your browser and view the app at
http://[YOUR_PROJECT_ID].appspot.com, run the following command:
gcloud app browse
You have completed this quickstart.
See the following sections for information about cleaning up after this quickstart as well as links to the possible next steps that you can take with your deployed applications.
To learn more about this Hello World app, see the Hello World code review section.
Clean upTo avoid incurring charges, you can delete your GCP project to stop billing for all the resources used within that project.
- In the GCP Console, go to the Projects page.
- In the project list, select the project you want to delete and click Delete project.
- In the dialog, type the project ID, and then click Shut down to delete the project.
Use a custom domain
You can serve your App Engine app using your own custom domain instead of
appspot.com. For more information, see Using Custom Domains and
Hello World code review
Hello World is the simplest possible App Engine app: it contains only one service, has only one version, and all of the code is located within the app's root directory. This section describes each of the app files in detail.
helloworld.php script responds to any HTTP request with the message
<?php echo 'Hello, World!';
app.yaml configuration file describes which handler scripts should be used
for which URLs.
runtime: php55 api_version: 1 threadsafe: true handlers: - url: /.* script: helloworld.php
From top to bottom, this configuration file says the following about this application:
- This code runs in the
php55runtime environment, API version
- This application is
threadsafeso the same instance can handle several simultaneous requests. Threadsafe is an advanced feature and can result in erratic behavior if your application is not specifically designed to be threadsafe.
- Every request to a URL whose path matches the regular expression
/.*(all URLs) should be handled by the
The following is a common error message that you might encounter:
ERROR: (gcloud.config.set) argument VALUE: Must be specified.
- If you encounter this error when running the
gcloud app deploycommand, you need to run the
gcloud initcommand to ensure that the tool has been initialized and your GCP project ID is set.
The development server must be started with the --php_executable_path flag set to the path of the php-cgi binary.
If you encounter this error when running
dev_appserver.py, you need to rerun
dev_appserver.pywith the flag
php_executable_pathand specify the path to your php-cgi binary. On Linux and Mac systems, you can find the path by running the following command:
Example of the
dev_appserver.pycommand with the
--php_executable_pathflag set to the
python dev_appserver.py helloworld/ --php_executable_path /usr/bin/php-cgi
Learn the whole platform
Now that you know what it's like to develop and deploy App Engine apps, you can stretch out and see the rest of Google Cloud Platform. For a guided walkthrough that teaches you how to create an application that uses the entire platform, not just App Engine, check out our Creating a Guestbook tutorial in which you expand this simple application to become a fully-fledged Guestbook application that lets authenticated Google accounts post messages to a public page.
Learn more about App Engine standard environment
Here are some topics to help you to continue learning about App Engine.