Launch Your First Web Server on GCP
Provision a Linux VM on Google Cloud and serve a live webpage with Apache.
Introduction
30 Second Summary
Every website you visit lives on a computer somewhere. Learning to set up that computer in the cloud is the first step toward building anything online.
In this project, you will create a Linux virtual machine on Google Cloud and turn it into a live web server. By the end, you will have a custom webpage accessible from anywhere on the internet.
What You'll Build
A Linux virtual machine running on Google Cloud infrastructure that hosts a custom webpage you can access from any browser via its public IP address.
By the end of this project, you'll have:
- A Google Cloud project with a running e2-micro VM instance you created and configured yourself.
- A live custom webpage served by Apache on your VM, accessible from anywhere on the internet.
- Hands-on experience managing a VM lifecycle (stopping, starting, and monitoring) through the Cloud Console.
- Secret Mission: Create a snapshot of your configured VM and launch a second identical instance from it.
Are there any prerequisites?
You only need a Google account (Gmail) and a web browser. No local software installation is required.
Google Cloud offers a free tier plus $300 in free credit for new accounts valid for 90 days, so this project costs nothing to complete.
Set Up Your Google Cloud Account and Project
To host your web server in the cloud, you need somewhere for it to live. Google Cloud provides on-demand infrastructure that lets you spin up a server in minutes without buying physical hardware.
In this step, you will create a free Google Cloud account, set up a project to organize your resources, and enable the service that lets you create virtual machines.
In this step, get ready to:
- Create your free Google Cloud account with $300 in trial credit.
- Set up a new project to organize your VM resources.
- Enable the Compute Engine API so you can create virtual machines.
Create your free GCP account
Google Cloud offers a generous free tier plus $300 in credit for new accounts. You will not be charged for anything in this project.
- Open your browser and navigate to the Google Cloud free tier page.
- Click Get started for free.
- Sign in with your Google account (the same one you use for Gmail).
- Accept the terms of service and select your country.
- Enter your billing information when prompted.
Will I be charged?
No. Google requires a payment method for identity verification, but you will not be charged. The free tier covers this entire project.
Your account comes with $300 in free credit valid for 90 days, plus always-free tier access to certain products including one small VM.
Once your account is created, the Google Cloud Console loads in your browser. This is the web-based dashboard where you manage all your cloud resources.
Create a new project and enable Compute Engine
Everything in Google Cloud lives inside a project. A project groups your VMs, billing, and permissions together in one place.
- In the Google Cloud Console, click the project selector dropdown at the top of the page.
- Click New Project.
- Enter my-first-vm in the Project name field.
- Click Create.
- Wait a few seconds for the project to be created, then click the project selector dropdown again.
- Select my-first-vm from the list to make it your active project.
What is a GCP project?
A project is Google Cloud's way of organizing resources. Every VM, database, or storage bucket you create belongs to a project. It also controls billing and access permissions.
Now you need to enable Compute Engine, the Google Cloud service that lets you create and manage virtual machines.
- Click the navigation menu icon (three horizontal lines) in the top-left corner of the Console.
- Scroll down and click Compute Engine, then click VM instances.
- When prompted, click Enable to enable the Compute Engine API.
- Wait for the API to finish enabling. This takes about a minute.
Why do I need to enable an API?
Google Cloud keeps services turned off by default to prevent accidental usage. Enabling the Compute Engine API tells Google Cloud that your project wants to use virtual machines.
Once the API finishes enabling, the VM instances page loads. You should see a Create Instance button and an empty list with no instances.
Not seeing the VM instances page?
If the page still says "Enabling", wait another 30 seconds and refresh your browser. The Compute Engine API can take up to two minutes to activate on a brand-new project.
If you see a billing warning, make sure your my-first-vm project is selected in the project selector dropdown at the top of the page.
help me troubleshoot the Compute Engine API not enabling on my new GCP project
Your Google Cloud environment is ready. Next up, you will create your first Linux virtual machine and watch it come to life.
Create Your Linux VM
Your Google Cloud account is ready and Compute Engine is enabled. Now it's time to create your first virtual machine.
A virtual machine is a computer that runs in Google's data center instead of on your desk. You'll configure one with Linux, choose a size that fits the free tier, and allow web traffic so it can serve a webpage later.
In this step, get ready to:
- Configure and launch a Linux VM instance on Google Cloud.
- Verify the VM is running and note its public IP address.
Configure and launch the VM
You'll walk through the Create Instance form to set your VM's name, location, size, and operating system. Each setting determines how your machine behaves and how much it costs.
- On the VM instances page, click Create Instance.
- In the Name field, enter web-server.
- Set Region to us-central1 (Iowa).
- Leave Zone at the default (us-central1-a).
- Under Machine configuration, select the E2 series.
- Select e2-micro as the machine type.
Why e2-micro in us-central1?
Google Cloud's free tier includes one e2-micro VM instance per month in us-west1, us-central1, or us-east1. Picking one of these regions means your VM runs for free without touching your $300 credit.
- In the OS and Storage section, click Change to configure the boot disk.
- On the Public images tab, choose Ubuntu from the Operating system list.
- Choose Ubuntu 24.04 LTS from the Version list.
- Click Select.
- Scroll down to the Firewall section.
- Check Allow HTTP traffic.
- Click Create.
What does Allow HTTP traffic do?
Checking this box creates a firewall rule that allows incoming web traffic on port 80. Without it, nobody on the internet could reach the webpage you'll host on this VM.
Google Cloud handles the firewall at the network level, so you won't need to configure anything inside the VM itself.
Google Cloud now provisions your VM. This can take 30 to 60 seconds.
Verify the VM is running
- Wait for the green status icon to appear next to your instance on the VM instances page.
- Find the External IP column in the instance list and note the IP address displayed there.
Save your External IP
Copy this IP address somewhere handy. You'll use it in the next step to view your live webpage in a browser.
Don't see a green status icon?
If the icon is gray or spinning, your VM is still being provisioned. Wait another 30 seconds and refresh the page.
If you see a red error icon, check that you selected e2-micro as the machine type and us-central1 as the region. Delete the failed instance and try creating it again.
Help me troubleshoot my VM creation error
Your VM is live and has a public IP address. Next up, you'll connect to it over SSH and install a web server to start hosting a real webpage.
Connect and Deploy Your Web Server
Your VM is running in the cloud, but right now it is an empty machine with nothing installed on it.
In this step, you will connect to your VM using a browser-based terminal, install Apache (a web server), and publish a custom HTML page that anyone on the internet can visit.
In this step, get ready to:
- Connect to your VM using browser-based SSH.
- Install Apache and verify it is running.
- Create a custom webpage and view it live on the internet.
SSH into your VM via the browser
SSH is a protocol that lets you securely connect to a remote machine and control it through a terminal. Google Cloud provides a browser-based SSH client so you do not need to install anything on your computer.
- Return to the VM instances page in the Google Cloud Console.
- Find your web-server instance in the list.
- Click SSH in the row of your instance.
- A new browser window opens with a terminal connected to your VM.
What just happened?
You are now logged into your Linux VM as your Google account user. Everything you type in this terminal runs directly on the VM in the cloud, not on your local computer.
SSH window not opening?
Make sure pop-ups are allowed for the Google Cloud Console domain in your browser settings. Some browsers block the SSH window by default.
If the connection fails, confirm your VM status shows a green checkmark (running) on the VM instances page.
help me connect to my VM via SSH
Install Apache and create your custom page
Apache is a web server that listens for incoming requests on port 80 and serves web pages in response. Once installed, it will turn your VM into a live website host.
- Update your package list and install Apache by running this command in the SSH terminal:
sudo apt update && sudo apt install apache2 -y
What does this command do?
sudo apt update refreshes the list of available software packages so your VM knows what is available to install.
sudo apt install apache2 -y installs the Apache web server. The -y flag automatically confirms the installation so you do not have to type "yes" manually.
- Verify Apache started automatically by running:
sudo systemctl status apache2
- Look for active (running) in green text in the output. This confirms Apache is live and ready to serve web pages.
- Press q to exit the status view and return to your terminal prompt.
Not seeing 'active (running)'?
If Apache shows as inactive or failed, try starting it manually by running sudo systemctl start apache2 and then checking the status again.
If you see a "package not found" error, make sure you ran sudo apt update first to refresh the package list.
help me get Apache running on my VM
Now you will replace the default Apache page with your own custom HTML. The default document served by Apache lives at /var/www/html/index.html.
- Open the default page in the nano text editor by running:
sudo nano /var/www/html/index.html
- Delete all the existing content. Press Ctrl+K repeatedly until the file is completely empty. Each press deletes one line.
- Paste the following HTML into the empty file:
<!DOCTYPE html>
<html>
<head>
<title>My First Cloud Server</title>
</head>
<body>
<h1>Hello from Google Cloud!</h1>
<p>This page is served from my own virtual machine running on Google Cloud.</p>
<p>I built this server from scratch using Compute Engine.</p>
</body>
</html>
What does this HTML do?
This is a simple webpage with a heading and two paragraphs. When someone visits your VM's IP address, Apache reads this file and sends it to their browser.
Feel free to customize the text inside the <h1> and <p> tags to say whatever you like.
- Save the file by pressing Ctrl+O, then press Enter to confirm the filename.
- Exit nano by pressing Ctrl+X.
Pasting into the SSH terminal
In the browser-based SSH window, use Ctrl+Shift+V to paste text you have copied. Regular Ctrl+V does not work inside the terminal.
Test your live website
Your custom page is now saved on the VM. Apache is already serving it to anyone who visits your VM's public IP address.
- Open a new browser tab (separate from the SSH window and the Cloud Console).
- In the address bar, type http:// followed by the External IP address you noted from the VM instances page earlier, then press Enter.
- You should see your custom webpage with the heading "Hello from Google Cloud!" displayed in the browser.
Where do I find my External IP again?
Switch back to the Cloud Console tab and look at the VM instances list. The External IP column shows the public IP address assigned to your VM. Copy it and paste it into your browser's address bar after http://.
Page not loading?
Make sure you are using http:// and not https:// in the address bar. Your VM does not have an SSL certificate, so HTTPS will not work.
Confirm that you checked Allow HTTP traffic when you created the VM in Step 2. Without this firewall rule, port 80 is blocked.
If you still see the default Apache page instead of your custom content, make sure you saved the file correctly in nano (Ctrl+O, then Enter).
help me access my webpage on my VM's external IP
You now have a live website running on a VM you built from scratch. Next up, you will learn how to manage your VM's lifecycle by stopping, starting, and monitoring it through the Cloud Console.
Manage Your VM Lifecycle
Your custom webpage is live on the internet, served from a virtual machine you built from scratch. That's a major milestone.
Launching a VM is just the beginning. In this step, you'll explore the monitoring dashboard and practice stopping and restarting your server to understand how cloud costs work.
In this step, get ready to:
- Explore the VM instance details and monitoring dashboard.
- Stop and restart your VM to practice lifecycle management.
- Understand the cost implications of running, stopping, and deleting a VM.
Explore the VM dashboard
The Google Cloud Console gives you a detailed view of each VM's configuration and performance. This is where you monitor resource usage and troubleshoot issues.
- Return to the VM instances page in the Cloud Console.
- Click your instance name (web-server) to open the VM instance details page.
- Review the details displayed: machine type, zone, network interfaces, and boot disk.
- Click the Monitoring tab to see CPU utilization and network traffic graphs.
What am I looking at?
The instance details page shows everything about your VM in one place. You can see what hardware it uses (e2-micro), where it lives (us-central1-a), and how it connects to the internet.
The Monitoring tab tracks your VM's resource usage over time. If your server ever slows down, this is the first place to check.
Stop and restart your VM
Stopping a VM is like shutting down a computer. The data on the disk stays intact, but the machine stops using CPU and memory resources.
- At the top of the instance details page, click Stop.
- Confirm the stop action when prompted.
- Wait for the status icon to change to a gray icon, indicating the VM is stopped.
Why might your IP address change?
Your VM uses an ephemeral IP address. This means the External IP is not permanently reserved for your VM. When you stop and restart, Google Cloud may assign a different IP address.
You can reserve a static IP if you need a permanent address, but for this project the ephemeral IP works perfectly.
- Click Start/Resume to bring the VM back online.
- Wait for the status icon to turn green again.
- Note the External IP address displayed on the instance details page. It may be different from the one you used earlier.
- Open a new browser tab and navigate to http:// followed by your new External IP address.
Your custom webpage loads in the browser, proving your server configuration survived the restart.
Page not loading after restart?
- Make sure you are using the new External IP, not the old one. Check the VM instances page for the current address.
- Confirm the VM shows a green status icon. If it is still starting up, wait another minute.
- Verify you are using http:// and not https:// in the URL. Your server is configured for HTTP only.
Why isn't my website loading after restarting my VM on Google Cloud?
Understand costs
Knowing when you are being charged is essential for managing cloud resources responsibly. Here is how Compute Engine billing works for your VM.
- While the VM is stopped, you are not charged for compute (CPU and memory).
- You are still charged for persistent disk storage even when the VM is stopped. The free tier covers 30 GB of standard persistent disk.
- The e2-micro instance type is always-free in us-west1, us-central1, or us-east1. Your VM in us-central1 qualifies for this.
What does always-free actually mean?
Each month, eligible use of all e2-micro instances is free until total hours equal the number of hours in the current month. That is enough to run one VM continuously for the entire month at no cost.
This is separate from your $300 free trial credit. Even after that credit expires in 90 days, your single e2-micro VM in an eligible region stays free forever.
Secret mission
Clone Your VM with a Snapshot
You have a fully configured web server running on Google Cloud. But what if you need a second identical server? In this secret mission, you will create a disk snapshot and use it to launch a clone of your VM without any manual setup.
Clean Up Your Resources
Clean Up Your Resources
Decide whether to keep your resources running, pause them to come back later, or delete them entirely.
Your first e2-micro VM in us-central1 is covered by the always-free tier. The second VM and snapshot use your $300 free trial credit.
Cost warning
The GCP free tier covers one e2-micro VM running continuously per month in us-west1, us-central1, or us-east1. Your second VM (web-server-2) consumes free trial credit while running. If you are not actively using it, stop or delete it to preserve your $300 credit.
Resources you used:
- VM instance: web-server (e2-micro, us-central1).
- VM instance: web-server-2 (e2-micro, us-central1).
- Snapshot: web-server-snapshot.
- Persistent disks attached to each VM instance.
Keep everything running
No action needed. Choose this if you are still actively building or want to keep experimenting with your VMs.
- Your web-server VM is covered by the always-free tier (one e2-micro per month in us-central1).
- Your web-server-2 VM uses free trial credit while running. You have $300 in credit valid for 90 days from account creation.
- Disk storage for both VMs is covered by the free tier (30 GB total).
Pause - I'll come back to this later
Stop both VMs to free up compute costs while keeping your files and configuration intact.
- In the Google Cloud Console, navigate to Compute Engine > VM instances.
- Select the checkbox next to web-server.
- Select the checkbox next to web-server-2.
- Click Stop at the top of the page.
- Wait for both VMs to show a gray status icon (stopped).
What am I still paying for?
While VMs are stopped, you are not charged for compute (CPU and memory). You are still charged for persistent disk storage, but the free tier covers 30 GB total. Your snapshot also uses minimal storage covered by free trial credit.
Delete - I don't want to use this again
Remove all project resources completely. This cannot be undone.
Delete both VM instances:
- Navigate to Compute Engine > VM instances.
- Select the checkbox next to web-server.
- Select the checkbox next to web-server-2.
- Click Delete at the top of the page.
- Confirm by clicking Delete in the dialog.
Delete the snapshot:
- Navigate to Compute Engine > Snapshots.
- Select the checkbox next to web-server-snapshot.
- Click Delete at the top of the page.
- Confirm the deletion.
Delete any remaining disks:
- Navigate to Compute Engine > Disks.
- If any disks remain from this project, select them and click Delete.
- Confirm the deletion.
What about my GCP account?
You do not need to delete your Google Cloud account. With all resources removed, there is nothing left to generate charges. Your free tier access and remaining trial credit stay available for future projects.
Nice Work!
Nice Work!
Nice work! You just built and deployed a live web server on Google Cloud from scratch.
You've learned how to:
- Provisioned a Linux virtual machine (e2-micro, Ubuntu 24.04 LTS) on Google Cloud and connected to it via browser-based SSH.
- Installed Apache and deployed a custom webpage accessible on the public internet from your VM's external IP address.
- Managed the VM lifecycle (stop, start, monitor) and understood the cost implications of running cloud resources.
- Secret Mission: Created a disk snapshot and launched a cloned VM from it, proving you can replicate cloud infrastructure.
Ready to quiz yourself?