title: Run Symfony Hello World on App Engine standard environment for PHP 5.5 description: Run Symfony Standard on Google App Engine standard environment for PHP 5.5. Symfony is a popular set of reusable PHP components and a PHP framework for websites and web applications. author: jimtravis tags: App Engine, Symfony, PHP date_published: 2017-02-08
Note: This tutorial uses PHP 5.5, which is EOL. Please use the tutorial for Running Symfony on App Engine for PHP 7.2 instead.
You can use Symfony with PHP on Google App Engine to develop your web apps. Getting to Hello World with Symfony on App Engine takes just a few minutes. We've provided modified source code for Symfony on GitHub. You can download the code and deploy it to App Engine by following the steps in this tutorial.
Symfony is a set of reusable PHP components and a PHP framework for websites and web applications.
Google App Engine's platform-as-a-service (PaaS) features let you easily run on Google's infrastructure, so your app can automatically scale to serve millions of users, while keeping your costs under control.
- Download the App Engine Symfony Starter Project.
- Run Hello World.
- Understand the source code.
Develop using Mac OS X or Microsoft Windows.
Install Composer. This tutorial assumes that you followed the instructions to install Composer globally. Ensure that your system meets the system requirements. Composer will require that your PHP installation supports cURL.
Install and then initialize the Google Cloud SDK.
Create a new Google Cloud Platform project or retrieve the project ID of an existing project from the Google Cloud Platform Console. You can retrieve a list of your existing project IDs by using the
gcloudcommand-line tool. From the command line, run:
gcloud projects list
Deploying Hello World with Symfony on App Engine
To deploy Symfony to App Engine, follow these steps.
Get the source code
Download the modified source code from GitHub. In a terminal window, enter the following command:
composer create-project google/appengine-symfony-starter-project
Change the current directory.
Run the app on your local computer
The following steps will serve your application on
dev_appserver.py, which was installed with the Google Cloud SDK.
Run the following command from the root of the project:
composer run-script server --timeout=0
This step is critical, as App Engine uses a read-only filesystem, so the cache files must be written first.
After the instance starts, open your browser to
When the page loads, you see a simple text message that says Homepage., which is Symfony's "hello world" text.
Deploy the app to the cloud
To deploy the code to App Engine, enter the following command:
composer run-script deploy --timeout=0
Just like above, this script warms the Symfony file cache before deploying to App Engine, as App Engine uses a read-only filesystem.
When the deployment finishes, your app will be serving traffic at
You can run the following command to open your browser to your app's URL:
gcloud app browse
When the page loads, you will see the message: Homepage.
Building the Cache
This application includes two helper scripts,
scripts/server.php, which can be run with
Both of these are used to prime the file cache, which is required for the
application to run due to App Engine Standard's read-only filesystem. The
scripts are convenient wrappers for Symfony's
commands, and are the equivalent to the following:
# This is equivalent to running `composer run-script server` app/console cache:clear --no-debug --env=dev app/console cache:warmup --no-debug --env=dev dev_appserver.py .
# This is equivalent to running `composer run-script deploy` app/console cache:clear --no-debug --env=prod app/console cache:warmup --no-debug --env=prod gcloud app deploy
Using Cloud Storage as your Filesystem
App Engine doesn't provide access to a file system, like the one you might use on a local computer or a server. You can use Cloud Storage in place of a local file system.
- Create and retrieve the name of your Google Cloud Storage bucket.
YOUR_GCS_BUCKET_NAMEwith the bucket name you created above.
- Browse to
This script will write a file "helloworld.txt" to the Cloud Storage bucket
parameters.yml, and then reads it back and displays it in the
By registering Cloud Storage as a stream wrapper, the
gs:// path can be used
to read and write to a Cloud Storage bucket as if it was a filesystem.
Configuring the App Engine application
App Engine applications require a configuration file, named
configure the app. The Symfony project adds this file to the code
from the original branch. In the
handlers section of the file, you can see the
URL routing handlers for the app. For example, you'll find the handler for your
static assets and front controller there. The handlers look like this:
handlers: # tell appengine where our static assets live - url: /bundles static_dir: web/bundles # the symfony front controller - url: /.* script: web/app.php
The url setting defines the URL that is being handled. The value for script points to the file that contains the scripting code to run when the URL is requested.
- Take a look at the App Engine PHP tutorials