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.
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.
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:
To create a new instance, click Create:
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]
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:
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:
When accessing the link, you will see the default page of your server:
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.