I’ll show you how to install Apache Webserver on a virtual machine on the Google Cloud Platform (GCP) in this article. I will begin with a brief review of Google Cloud Platform, and then I’ll teach you how to use Google Cloud Platform to install Webserver and execute the Hello World program from virtual machine instances. Let’s get going.
Read this blog post or watch the video below to learn how to install Webserver and execute Hello World on Virtual Machine in Google Cloud Platform.
Overview of Google Cloud Platform
The Google Cloud Platform is a collection of physical and virtual assets, including computers, hard drives, and CPUs, that are housed in Google Cloud data centres. Each data centre is located in a worldwide region, which is comprised of zones. Within the same territory, each zone is segregated from the others.
This distribution gives us several benefits, such as data redundancy in the event of a zone failure, lower latency by placing resources closer to the client, and more control over resources and how they may be used to improve service and lower costs.
Because this is a cloud platform, you won’t have to bother about purchasing and building hardware or data centres. You may use all of Google’s hardware and software as services. These services in Google Cloud Platform give you access to the underlying hardware. When you begin working, you will find that your product is simply a mix of Google services and your code.
What is Virtual Machine and Google Compute Engine (GCE) ?
When you deploy your app, you need servers. In the cloud environment, you need virtual servers to deploy and run your app. Google Compute Engine (GCE) will provision and maintain the virtual machines.
Virtual machines on Google Computing Engine deliver on-demand, high-scale performance and value, allowing you to quickly deploy massive compute clusters on Google’s infrastructure using Windows Server or Red Hat Enterprise Linux or any Operating system of your choice.
Install Apache Server in Virtual Machine
Below are the steps you need to follow to install Apache Server:
First you need to login to virtual machine’s by clicking on “Open in browser window” option under SSH.
Once you are within the virtual machine’s SSH-in-browser, you need to become root in order to install any software. The command is:
Next, you need to update all the packages. The command for that is:
Now, you can install Apache server. The command is:
apt install apache2
It will ask for your permission. Once you provide the permission, it will install the apache server on the virtual machine.
Now if you open the virtual machine, by clicking on the External IP, it will open a new page in a new tab. You will find the Apache Welcome page, indicating that Apache is installed correctly.
You can change the content on the Apache Webserver’s index.html page. For that go to the location /var/www/html and modify the content of the index.html like –
echo “Hello from Technical Potpourri” > index.html
After that when you will refresh the page, the new content i.e. the message “Hello from Technical Potpourri” will be displayed on the screen.
Internal IP vs. External IP
When you create one virtual machine, Google Cloud Platform will assign one primary internal IP address, one external IP address, and any number of secondary internal IP addresses. As the name suggests, external IP addresses are reachable from outside of the VPC network while internal IP addresses are not.
By default, each Compute Engine instance is assigned a single public and private IP address.
The regional subnets that are formed for each region are used to assign internal IP addresses. Any VM instance in any zone in the area where the IP Address Range (subnet) exist can be given an internal IP address. These IP addresses can often only be accessible by IP Addresses that are part of the same VPC Network. As a result, they are a part of the network.
A Google Managed Pool of IP Addresses is used to assign external IP addresses, which are publicly accessible and assignable from any IP address. Depending on the needs of the organization, external IP addresses might be local or worldwide. Despite the fact that they are outside the VPC network, the network knows how to divert traffic meant for the external addresses to the internal IP so that it can reach the intended VM instances.
Every VM instance must have an internal IP address but the external IP address is optional, only for VMs that require a dedicated network connection.
In my next blog post, I will explain what is Static IP and how you can configure that in Google Cloud Platform.