Project Overview
Objective: Host a static website on Google Cloud Storage (GCS)
Project Name: cloud-demo-site
Bucket Name: cloud-demo-static-site
Region: us-central1 (Iowa)
Website URL: https://storage.googleapis.com/cloud-demo-static-site/index.html
Expected Result: A live website with a homepage (index.html) and an image (logo.png)
Step 1: Create a New Google Cloud Project
Step 2: Enable Cloud Storage API
By default, APIs are disabled in Google Cloud. You must manually enable the Cloud Storage API to use storage services.
In Google Cloud Console:Navigate to API & Services > Library.
Search for Cloud Storage API.
Click Enable.
Step 3. Create a Google Cloud Storage Bucket
To host a static website, you first need to create a Cloud Storage bucket. The bucket name must match your website’s domain (e.g., mywebsite.com). The bucket should be publicly accessible to serve the website.
Google Cloud CLI (Automated Terminal Approach): gcloud storage buckets create gs://cloud-demo-static-site --location=us-central1 --uniform-bucket-level-access
Step 4: Upload Website Files
Once the bucket is created, you need to upload your static website files (index.html, style.css, etc.). These files will be publicly accessible once permissions are set.
Google Cloud CLI (Automated Terminal Approach)
: gsutil cp Downloads/index.html gs://cloud-demo-static-site/
Step 5: Grant Public Access to Files
To serve your website to the public, you must grant "allUsers" the "Reader" role. This allows anyone to view the files but not modify them.
Google Cloud CLI (Automated Terminal Approach)
: gsutil iam ch allUsers:objectViewer gs://cloud-demo-static-site
Step 6: Configure the Website Settings
Google Cloud CLI (Automated Terminal Approach)
Run this command in the terminal:
gcloud storage buckets update gs://cloud-demo-static-site --web-main-page-suffix=index.html --web-error-page=404.html
Step 7: Verify the Website
Open your web browser.
Visit the following URL:
https://storage.googleapis.com/cloud-demo-static-site/index.html
Step 8: Enforce Public Access for the Files
Step 9: Final Verification
Open your web browser.
Visit:
https://storage.googleapis.com/cloud-demo-static-site/index.html
Conclusion
We’ve successfully hosted a static website on Google Cloud Storage using the bucket cloud-demo-static-site in the us-central1 region. Your site is publicly accessible !
By completing these steps, you’ve learned how to:
Create and configure a new project in Google Cloud.
Set up a GCS bucket with the correct permissions and website settings.
Upload static content (HTML, images) to make it publicly available.
Popular Projects
What is Cloud Computing ?
Cloud computing delivers computing resources (servers, storage, databases, networking, and software) over the internet, allowing businesses to scale and pay only for what they use, eliminating the need for physical infrastructure.