Connect to a GCP VM via SSH and Install Apache Web Server

Connect to a GCP VM via SSH and Install Apache Web Server

In this tutorial, you’ll learn how to:

  1. Connect to a Google Cloud VM using the GCP Console (Web UI)
  2. Install and start the Apache HTTP Server
  3. Test it by opening the browser

This is a beginner-friendly guide, and you only need basic terminal skills.

Requirements

Make sure you have:

  • A Google Cloud project with billing enabled
  • A Compute Engine VM already created
  • gcloud CLI installed and authenticated:

There 2 way to connect to GCP ssh.

1. Using command line

Install Google Cloud SDK:

curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-453.0.0-darwin-x86_64.tar.gz
tar -xf google-cloud-cli-*.tar.gz
./google-cloud-sdk/install.sh

Then, close and reopen the command line.

if everything is ok, try to execute:

gcloud init

A popup to authenticate will open.
To set a default project:

gcloud config set project [IL_TUO_PROJECT_ID]

To get the already created VM:

gcloud compute instances list

To connect in ssh:

gcloud compute ssh [VM_NAME] --zone=[ZONE]

2. Directly through GCP console

1️ Connect to the VM

  1. Go to the Google Cloud Console
  2. In the left menu, go to Compute Engine > VM instances
  3. Find your VM and click the SSH button in the row.

2️ Update packages

sudo apt update

(Optional):

sudo apt upgrade

3️ Install Apache

sudo apt install apache2 -y

4️ Start Apache

sudo systemctl start apache2
sudo systemctl enable apache2

Check status:

sudo systemctl status apache2

5️ Open in browser

gcloud compute instances list

Then open:
http://[EXTERNAL_IP]

(Optional) Allow HTTP traffic

gcloud compute instances add-tags [VM_NAME] --tags=http-server --zone=[ZONE]
gcloud compute firewall-rules create allow-http --allow=tcp:80 --target-tags=http-server

📚 Quiz

  1. Which command connects to a GCP VM?

    • A. ssh gcp connect
    • B. gcloud compute ssh
    • C. gcp ssh vm
    • D. gcloud vm access
  2. Default Apache port?

    • A. 443
    • B. 21
    • C. 80
    • D. 22
  3. Apache install command?

    • A. yum install apache2
    • B. install apache
    • C. apt install apache2
    • D. gcloud install apache2
  4. Test Apache at?

    • A. localhost
    • B. 127.0.0.1
    • C. [EXTERNAL_IP]
    • D. google.com
  5. Purpose of systemctl enable apache2?

    • A. Run once
    • B. Uninstall
    • C. Start at every boot
    • D. Disable Apache

✅ Correct Answers

  1. B
  2. C
  3. C
  4. C
  5. C
© Nc6 by Giuseppe Fanuzzi - IT08952900721 - PIQA6QP