How to set up your Serverless Google Cloud Platform environment for OctoberCMS (Laravel)

Setting up the Google Cloud Platform Infrastructure

Setting up the Google Cloud Platform Infrastructure

Provided by Cloud Office Sr. Cloud Architect in Google Cloud Platform

At Cloud Office we were assigned a medium-sized infrastructure project based on OctoberCMS (Laravel) and when it was time for deployment we were working together with the Development team at Web Motion.

Setting up the infrastructure took no more than a couple of hours. The customer wanted a severless solution. First we went through the App Engine Standard environment, but that proved to be less effective due to the specifics of OctoberCMS (Laravel).

Initial idea was to have the app scale down to 0, but that was a challenge, as having 0 instances to manage when there is no traffic is not possible. We then decided to switch to App Engine Flexible, so that there can always be one instance running for additional customizations through SSH. 

With a couple of changes to the app.yaml file as well as the configurations listed later in this document and the linked article, the new environment for the deployment was up and running in the App Engine Flexible environment.

You can find a list of all of the steps that were made for the infrastructure creation in Google Cloud Platform below:

  1. Project creation
  2. Billing setup
  3. User additions and permissions
  4. Networking
    1. Firewall rules
  5. SQL Instance creation
    1. SQL User creation
    2. Database creation
    3. Connection management
    4. Migration from test environment
  6. Storage bucket creation
    1. User access and permissions
    2. Structure
    3. Migration from test environment
  7. Service accounts for component interactions
  8. Repository cloning to Cloud Shell
  9. Initial deployment for automatic App Engine Infrastructure
  10. Debugging and refactoring
  11. Double-checking for service account access and permissions
  12. Testing connections to components
  13. Deployment and debugging
  14. Cloud DNS domain management
    1. End-user access
    2. Admin access
  15. Deployment

Setting up the project

During our tests with Google App Engine Standard Environment, we found that it is not possible to set up OctoberCMS, because it has specific feature requirements, such as access to the console. We managed to start the project on Google App Engine Standard Environment, but some of the code snippets on the documentation’s example for Laravel on the Standard Environment were insufficient and we could not produce a completed deployment. We ended up setting up an App Engine Flexible Environment, which allows more configuration through a Dockerfile.

Preparing the app.yaml file

Create a file named app.yaml in the project root to set up the App Engine as a flexible environment. The variables in section “env_variables” are for configuring Laravel and OctoberCMS and will be explained in the linked article

Our file is shown as an example below:

runtime: custom
env: flex
 
runtime_config:
   document_root: .
 
resources:
 cpu: 2
 memory_gb: 2.3
 disk_size_gb: 10
 volumes:
 – name: ramdisk1
   volume_type: tmpfs
   size_gb: 0.5
 
manual_scaling:
 instances: 1
 
vpc_access_connector:
 name: projects/insert-project-name/locations/europe-west3/connectors/insert-connector-name
 
network:
 instance_tag: insert-instance-tag
 name: default
 
env_variables:
 APP_STORAGE_PATH: gs://inset-bucket-name/storage/app
 APP_STORAGE_URL: https://storage.googleapis.com/inset-bucket-name/storage/app
 APP_DEBUG: false
 APP_ENV: production
 SESSION_DRIVER: cookie
 DATABASE_HOST: insert-database-ip
 DATABASE: insert-database-name
 DATABASE_USERNAME: insert-database-user
 DATABASE_PASSWORD: insert-database-password
 DATABASE_PORT: 3306
 URL: insert-app-engine-url
 KEY: insert-laravel-key
 CIPHER: AES-256-CBC

After the infrastructure and app.yaml were deployed, we then continued with setting up October CMS (Laravel) and the actual development.

Limitations:

Editing capabilities of OctoberCMS

Since data can be stored on the Docker instance only in the “/tmp” folder and PHP does not have the right to modify the code of the application in the /app folder (also if the code is modified, the changes are lost during the next deployment) we noticed that the result of this limitation was that editing pages in OctoberCMS is not possible within App Engine. Our solution is to locally edit the pages or using a staging server, then committing them to the code repo and deploying them on Google Cloud Platform.

Mounting the storage bucket

We used a Google Cloud Storage bucket. The storage bucket can be mounted with FUSE, unfortunately we could not find a way to mount the storage bucket in the Docker container, because the container did not have sufficient permissions. We had to use the less elegant solution of accessing the files through the “gs://” protocol, which required changes in the application, which you can find in the linked article.

What benefits do we get when switching to Google Workspace

In this article, you can learn all the benefits you could receive if you decide that you want to joi...

Read more
The Future of Gmail

Google brought email, chat, voice & video calling together. Also, there are added Rooms, so you can ...

Read more
The Cloud Office team was recognized with 2 new lines of expertise from Google Cloud

When you see a partner with an Expertise, it indicates whether they have demonstrated customer succe...

Read more