Sudipta Deb

Sudipta Deb

Founder of Technical Potpourri, Co-Founder of Shrey Tech, Enterprise Cloud Architect

In Google Cloud, a Virtual Machine (VM) is a computing resource that emulates a physical computer within the cloud environment. It provides users with the ability to run applications and perform various computing tasks without the need for physical hardware.

In this blog post, I am going to share with you how you can create Linux Virtual Machine and Install Apache Web Server there.

Create A New Project

To start with, the first thing that you need to do is to create a new project. Here are the steps to create a new project.

  1. Open the Google Cloud Console: Go to the Google Cloud Console website (console.cloud.google.com) and sign in with your Google account.

  2. Select or create a Google Cloud organization: If you have multiple organizations, select the organization under which you want to create the project. If you don’t have an organization, you can create one during the project creation process.

  3. Click on the project drop-down menu: On the top navigation bar, you’ll see a drop-down menu with the current project name. Click on it to open the project selection menu.

  4. Click on “New Project”: In the project selection menu, click on the “New Project” button.

  5. Enter project details: In the “New Project” dialog box, provide the following information:

    • Project name: Enter a name for your project (e.g., “My Project”).
    • Project ID: Optionally, you can specify a project ID. If you don’t provide one, Google Cloud automatically generates a unique project ID based on your project name.
    • Organization: If you have multiple organizations, select the desired organization to associate with the project. Otherwise, the default organization will be used.
  6. Click on “Create”: Once you’ve entered the project details, click on the “Create” button to create the project.

  7. Wait for the project to be created: The project creation process may take a few moments. Once the project is created, you’ll be redirected to the project’s overview page.

Enable APIs

Once the project is created, you need to enable the API – Compute Engine API. Here are the steps –

  1. Open the Google Cloud Console: Go to the Google Cloud Console website (console.cloud.google.com) and sign in with your Google account.

  2. Select your project: In the top navigation bar, click on the project drop-down menu and select the project for which you want to enable the Compute Engine API.

  3. Open the API Library: In the left sidebar, click on “APIs & Services” and then select “Library” from the dropdown.

  4. Find the Compute Engine API: In the API Library, type “Compute Engine API” in the search bar or scroll down until you find it.

  5. Enable the Compute Engine API: Click on the “Compute Engine API” in the search results. This will take you to the Compute Engine API page.

  6. Click on “Enable”: On the Compute Engine API page, click on the “Enable” button to enable the API for your project.

  7. Wait for the API to be enabled: The API activation process may take a few moments. Once the Compute Engine API is enabled, you’ll see a notification confirming the activation.

Create The Server Virtual Machine

  1. On the Compute Engine page, click VM instances.
  2. Here click on “Create Instance“.
  3. In the Name field, enter the name of your server. For example: my-linux-web-server.
  4. In the Region list, select your region or zone. To understand Regions, please read my blog here or watch my youtube video here
  5. In the Zone list, select the appropriate zone.
  6. In the Boot Disk section, click on Change and select the following –
    • Operating System: Debian
    • Version: Keep it default
    • Boot disk type: SSD persistent disk.
  7. In the Firewall section, select “Allow HTTP Traffic“.
  8. Click on Create.

This will create the new instance of Virtual Machine.

Install An Apache Server

  1. To open a terminal to your instance, in the Connect column, click SSH.
  2. Update the package lists on your instance:
    • sudo apt-get update

  3. Install Apache2 HTTO Server:
    • sudo aptget install apache2 php7.0

  4. Overwrite the Apache web server default web page with the following command:
    • echo ‘<!doctype html><html><body><h1>Hello World From Technical Potpourri!</h1></body></html>’ | sudo tee /var/www/html/index.html

Test Your Server

  1. In the Google Cloud Console, go to the VM instances.
  2. Copy the VM’s IP address from the External IP column.
  3. Paste the IP address in a new browser tab.

  4. You should see a page with message – Hello World from Technical Potpourri.

Delete

To avoid incurring charges to your Google Cloud account for the resources used in this tutorial, either delete the project that contains the resources, or keep the project and delete the individual resources.

Run the following command to delete the project:

gcloud projects delete <YOUR PROJECT NAME>

Disclaimer

This article is not endorsed by Salesforce, Google, or any other company in any way. I shared my knowledge on this topic in this blog post. Please always refer to Official Documentation for the latest information.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *