Web servers are used to host websites and make them available to users through HTTP protocol requests. It is common for these web servers to be created within virtual machines in the cloud. In this post, we will provide a step-by-step guide on how to create a virtual machine and web server inside Google Cloud.

Context

Google Compute Engine delivers virtual machines running on Google's innovative data centers and global fiber networks.

Compute Engine resources are created in regions or zones. A region is a geographical location where you can run your resources. Each region has one or more zones. For example, the us-central1 region denotes the region in the central United States that has the zones us-central1-a, us-central1-b, us-central1-c, and us-central1-d. Resources that live in a zone are referred to as zonal resources.

DA 1
Create a New Instance

You can create a new virtual machine through the Cloud Console or the gcloud command line.

In the GCP Console, on the top left of the screen, select Navigation menu > Compute Engine > VM Instances:

DA 2

To create a new instance, click Create:

DA 3

To create a virtual machine, there are several parameters that must be filled. The main ones are: Name, Region, Zone, Machine Type, Boot Disk, and Firewall.

To create a virtual machine through the command line in gcloud, all the same parameters must be passed, as shown in the example below:

gcloud compute instances create [name] --machine-type [machine-type] --zone [zone]

Installing the NGINX Web Server

First, open an SSH client with the virtual machine. You can perform this operation directly from the list of virtual machines in the Cloud Console, as shown in the image below:

DA 4

After accessing the machine's SSH client, run the following commands:

sudo su -

// get root access


apt-get update

// update the OS


apt-get install nginx -y

// install NGINX


ps auwx | grep nginx

// check if NGINX is running

If everything is correct, you may access your web server simply by entering the external IP of the machine, as shown in the image below:

DA 5

When accessing the link, you will see the default page of your server:

DA 6

Conclusion

Creating virtual machines to run your own web server is an easy task and a quick process. Among the key benefits of Compute Engine is its ability to configure the virtual machine with custom resources since the platform is not limited to predefined virtual machine configurations.


Author

Douglas Augusto

Douglas Augusto is a Lead Solutions Architect at Avenue Code and is passionate about Cloud Computing. He is a Google Developer Expert (GDE) for Google Cloud Platform and a Mentor in Cloud Computing at Google for Startups.


Terraform 101: An Introduction to Infrastructure as Code

READ MORE

Which Google Cloud certification is the best fit for me?

READ MORE

How the Mulesoft JWT Validation Policy Works

READ MORE

How to Use Redis Cache to Prevent DDoS Attacks

READ MORE