Creating a Guestbook

This tutorial shows you how to implement a PHP application for App Engine—a simple guestbook that lets users post messages to a public message board.

The UI for the application looks like this:

Objectives

  • Clone the tutorial project
  • Walk through the code samples to see how to integrate your application with Google accounts, handle web forms, and serve static files
  • Run, test, and deploy the project

Costs

There are no costs associated with running this tutorial. This application does not exceed the free quota.

Before you begin

  1. Download the App Engine SDK for PHP.

    Alternatively, you can download the sample as a zip file and extract it.

  2. Optionally, to simplify development and deployment, add the directory to the PHP SDK to your PATH environment variable by adding the following line to your $HOME/.profile, $HOME/.bashrc, or equivalent:

    export PATH=[PATH_TO_GOOGLE_APPENGINE]:$PATH
    

  3. Sign in to your Google account.

    If you don't already have one, sign up for a new account.

  4. Select or create a Cloud Platform Console project.

    Go to the Projects page

  5. Note the Project ID, which might be different from the project name and is used in commands.

Cloning the project from GitHub

  1. Clone the Guestbook application repository to your local machine:

    git clone https://github.com/GoogleCloudPlatform/appengine-php-guestbook.git
    
  2. Switch to the branch with the final version of the application:

    cd appengine-php-guestbook/
    git fetch
    git checkout phase3-staticfiles
    

The cloned project contains several branches. In this tutorial we will only cover the project in the branch named phase3-staticfiles.

Building and running locally

To build and run the sample locally:

  1. From the project appengine-php-guestbook in the branch phase3-staticfiles, invoke the command:

    dev_appserver.py ./
    
  2. The development web server is now running, and you can visit this URL in your browser:

    http://localhost:8080

  3. The app serves a page inviting you to sign in. Try clicking the Sign in link, then sign in with any email address. The development server has only a very basic emulation of the Google Account sign-in process for testing purposes, so this accepts whatever email you supply, valid or not, and generates a fake user object based on that supplied value. This same code, however, when deployed to production, requires a valid Google Account and email for the sign-in to work, and yields a valid user object.

  4. Terminate the development server by pressing Control+C.

Understanding the code

To walk through the application code and see how it works, continue to the next page.

Send feedback about...

App Engine standard environment for PHP