3 minute read

Hosting on Google Cloud Storage

Required expertise level : Intermediate

Platform : Any

Last tested and confirmed : January 2022


The main advantage of using Google Cloud Storage to host our static mirror is the ability to serve a fully functional “static” web pages directly using Google Cloud Platform URLs which usually looks like this: https://storage.googleapis.com/[bucketname]


Configure static site hosting on Google Cloud Storage

Creating GCS bucket, and setting permissions

  • First, you need to create an account on Google Cloud Platform, you will need to create a Google account for this.

  • Here, you’ll need to open Storage from the side bar to access Google Cloud Storage settings page.

Create a new bucket here

Buck name

  • First step will be choosing your bucket name, bucket names should be unique and you’ll use it to access your static website later.

Region settings

  • Unless you know what you are doing, there is no need to change anything here.

Storage Class

  • In most cases it should be Standard.

Access control

  • We will be handling permissions and access control configurations later on, so we’ll leave it unchanged for now.

Encryption

  • As this bucket will be publicly available, we don’t need to change anything with Encryption settings.


Upload the static website

Install Google Cloud SDK Command Line Interface

Installing Google Cloud SDK is pretty straight forward process. Simply, follow the instructions related to your operating system in this guide and you will be good to go.

Upload using Google Cloud SDK CLI

  • After installing Google Cloud Sdk, you will need to authorize the local client to connect to you Google Cloud account, you can do that by opening your terminal and entering gcloud init

  • After Successfully logging in to your account, you will be asked to select the project you want to use, if you didn’t create a new project you can do that now using the local CLI.

  • Using your terminal, change directory to the static mirror files location, and enter gsutil rsync -R [local-dir] gs://[bucketname]

Uploading files

  • Now if you go to your bucket settings page, you will notice the static mirror files are uploaded.

  • Final step will be setting public permissions to the files so the static mirror will be accessible to public internet, you can do that using the local CLI by entering gsutil iam ch allUsers:objectViewer gs://[bucketname]

Now you can access your static mirror using this URL scheme https://storage.googleapis.com/[bucketname]/index.html