paint-brush
How To Run Symfony On Google Cloud Run With The Demo App [Step-by-Step Guide]by@geshanm
592 reads
592 reads

How To Run Symfony On Google Cloud Run With The Demo App [Step-by-Step Guide]

by Geshan ManandharNovember 8th, 2019
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

This blog post demystifies running the Symfony Demo App in a docker container and hosting it serverless on Google Cloud Run. It might look insanely easy but we will go through some details after the steps. The Dockerfile uses multistage build, on stage to install dependencies with composer and another one with Apache to run the application. This post is not going to be a detailed one like the last one about Laravel on Cloud Run, please do read the above-mentioned post thoroughly.

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - How To Run Symfony On Google Cloud Run With The Demo App [Step-by-Step Guide]
Geshan Manandhar HackerNoon profile picture

Symfony is without doubts one of the most popular PHP frameworks. It has amazing flexibility and is written in an applaudable modular fashion. Some Symfony components even power other prominent frameworks like Laravel. Running Symfony is a bit tricky at times, especially the permissions of the cache and logs folder, this blog post demystifies running the Symfony Demo App in a docker container and hosting it serverless on Google Cloud Run.

Prerequisites

  1. You have done at least one project with Symfony (of course you are comfortable with PHP and composer)
  2. You have a good working knowledge of git and Github
  3. Know a fair bit of docker, maybe even multi-stage build
  4. Have a working Google cloud account (they give you $300 credit free for 1 yr, no reasons not to have an account)

This post is not going to be a detailed one like the last one about Laravel on Google Cloud Run. If you are fairly new Git or Docker, please do read the above-mentioned post thoroughly.

Steps

Before going to the steps, the repo is hosted on my Github and it is open-source of course. It might look insanely easy but we will go through some details after the steps. So let’s get started now:

1. Go to the repo

Navigate to the open-source Github repo. That is a very easy step, isn’t it? :)

Repo with Dockerized Symfony Demo App

2. Click on the Google Cloud button

Then click on the Run on Google Cloud blue button, as shown below: 

Click on the button

3. Choose correct settings on Google cloud CLI

After that, given you are logged into your Google account and have Google cloud setup with 1 or more projects, click Proceed. You might need to wait a bit, after that

  1. Choose the project — Choose a project to deploy this application
  2. Choose the region — Choose a region to deploy this application, I usually choose
    us-central-1

Then wait for the container to be built and deployed, you can see my process below:

Deploying Symfony Demo app with Google Cloud shell script

If everything goes fine on your Google Cloud Shell, you will see HTTPs URL you can go to in order to see your Symfony demo app running like below:

Symfony Demo app running on Google Cloud Run

One issue with this setup is that data will not be saved if you click around and add new posts. This happens because the data is saved in the SQLite file, as it is not persisted new containers get the old file and you get the same data pushed in the repo.

So what just happened?

There are some things you need to consider for this automagic deployment of the Symfony App. Let’s look at what just happened above:

  1. The Symfony Demo app has been dockerized, have a look at this Dockerfile and the Apache config too. The Dockerfile uses multistage build, on stage to install dependencies with composer and another one with Apache to run the application.
  2. If you want to run it locally, just run docker-compose up then go to http://localhost:8080. 8080 is the required port needed for Google Cloud Run.
  3. Thanks to the Google Cloud Run button and the Cloud Shell script that does the automagic deployment.

To make the most out of this tutorial, you can fork the repo, add your own button then explore more with it.

Conclusion

Running Symfony entails some tricky configuration :) so the Dockerized version is a breeze to run.

I really believe that Google Cloud Run is a superior product if you know how to dockerize your web app and run it on port 8080 you can get amazing scalability with unparallel ease to make it run.

I would recommend Cloud Run for any pet project or even production application.

Read more at https://geshan.com.np