How To Host Static Websites On GCP Cloud Storage
Install CLI
Follow the install page to install gcloud CLI: https://cloud.google.com/sdk/docs/install (the previous version of this guide was using gsutil, but the preferred way is to use gcloud storage instead).
Follow the official guide
Follow the tutorial to setup: https://cloud.google.com/storage/docs/hosting-static-website
Basically create a bucket named after your website like www.yourdomain.com, and verify ownership by creating a new property in the Search Console.
Upload static files to your bucket
To sync the local out folder to the cloud:
$ gcloud storage rsync -r --delete-unmatched-destination-objects out gs://www.yourdomain.com
Setup DNS
Go to the website where you registered the domain. (e.g. CloudFlare)
Set a CNAME and point it to c.storage.googleapis.com
NAME TYPE DATA
www CNAME c.storage.googleapis.com.
Troubleshooting: "Error: Access Denied"
Remember to add a new permission in PERMISSIONS tab:
- Principle = allUsers
- Role = Storage Object Viewer
Recommended ReadingSponsored
How-to
- How to add content group to Google Analytics
- How To Integrate Google AdSense into Modern Web Apps (React & Next.js)
- How To Export and Download HTML5 Canvas as an Image
- How To Embed YouTube Videos Efficiently (Responsive, Fast & Privacy-Safe)
- How to find all files containing a specific text
- How To Host Static Websites On Amazon AWS EC2
- How To Host Static Websites On Amazon AWS S3
- How To Host Static Websites On GCP Cloud Storage
- How to safely store API Keys
- How to Speed Up IntelliJ IDEA / Clion
- How-to Guides

