The PHP Development Server

The Google Cloud SDK and App Engine SDK for PHP each include a local development server that you can run locally to simulate your application running in production App Engine. The simulated environment enforces some sandbox restrictions, such as restricted system functions and PHP module imports, but not others, like request time-outs or quotas.

The local development server also simulates the services provided by App Engine PHP SDK libraries, including Datastore, Memcache, and Task Queues, by performing their tasks locally. Note that when your application is running in the development server, you can still make remote API calls to the production infrastructure using Google APIs HTTP endpoints.

Running the local development server

Once you have a directory for your application and an app.yaml configuration file, you can start the local development server using the command.

Windows or Mac OS X

Change to the directory containing your application, then invoke the following:

     google_appengine/ [PATH_TO_YOUR_APP]

The local server listens on port 8080 by default, so you can visit the application at http://localhost:8080/. To change the port, use the --port option:

     google_appengine/ --port=9999 [PATH_TO_YOUR_APP]

Linux or custom php-cgi

If you're on Linux or if you want to use a custom version of php-cgi, you need to do the following:

  1. Build your own version of App Engine PHP Extension on your local machine.

  2. Run your PHP app by invoking the local development server as follows:

         google_appengine/ --php_executable_path=path-to-php-cgi \
           --php_gae_extension_path=path-to-gae-extension path-to-your-app

    where --php_executable_path is set to the location of the PHP interpreter you are using, and where --php_gae_extension_path is set to the the location of file you built in the previous step. not working?

Specifying application IDs

If you want to use application IDs with the local development server, don't use the App ID from the APPLICATION_ID environment variable. The development server differs from production App Engine service in that the local server prepends the string dev~ to the APPLICATION_ID environment variable.

Instead, if you need to access your App ID in the local server, for example to spoof an email address, use the AppIdentityService::getApplicationId function. To get the hostname of the running app, use the AppIdentityService::getDefaultVersionHostname function.

Storing data

Google App Engine for PHP supports reading and writing to Google Cloud Storage via PHP's streams API. You can read and write to Cloud Storage by specifying a Cloud Storage URI (gs://) when using any PHP function that supports PHP Streams implementation such as fopen, fwrite or file_get_contents.

The local development server emulates this functionality by reading and writing to temporary local files that are preserved between requests.

Browsing the local Datastore

If your app has written data to your local Datastore using the local development server, you can browse it in the local development console.

To browse local Datastore:

  1. Start the development server.

  2. Access the Datastore Viewer in the local development console. (The URL is http://localhost:8000/datastore.)

  3. View your local Datastore contents.

Using the Users service

App Engine provides a Users Service to simplify authentication and authorization for your application. The local development server simulates the behavior of Google Accounts with its own sign-in and sign-out pages. While running under the local development server, the createLoginURL and createLogoutURL functions return URLs for /_ah/login and /_ah/logout on the local server.

Using Mail

The local development server can send email for calls to the App Engine mail service using either an SMTP server or a local installation of Sendmail.

Using SMTP

To enable mail support with an SMTP server, invoke as follows:: --smtp_port=25 \
    --smtp_user=ajohnson --smtp_password=k1tt3ns [PATH_TO_YOUR_APP]

where you set the --smtp_host, --smtp_port, --smtp_user and --smtp_password options with your own values.

Using Sendmail

To enable mail support with Sendmail, invoke as follows: --enable_sendmail [PATH_TO_YOUR_APP]

The local server will use the sendmail command to send email messages with your installation's default configuration.

Using URL Fetch

When your application uses the URL fetch API to make an HTTP request, the local development server makes the request directly from your computer. The URL Fetch behavior on the local server may differ from production App Engine if you use a proxy server for accessing websites.

Debugging locally with XDebug

If you have a debugger that is compatible with the XDebug debugger, and you have the xdebug module installed, you can use XDebug with the local development server.

To enable XDebug on the Development Server on Linux or Mac OS X:

  1. Export the XDEBUG_CONFIG environment variable with an idekey for your IDE to connect to

    export XDEBUG_CONFIG="idekey=netbeans-xdebug remote_host=localhost"
  2. Invoke the Development Server with --php_remote_debugging=yes

Send feedback about...

App Engine standard environment for PHP