A virtual machine instance on Google Compute Engine can be controlled like any standard Linux server. Deploy a simple Apache web server to learn the basics of running a server on a virtual machine instance.
Prerequisites
Create a Linux instance that allows HTTP traffic.
- Follow the Quickstart instructions to create a new Linux instance and connect to it.
- While creating your Linux instance, scroll to the Firewalls section and check the Allow HTTP Traffic box. Checking this box enables the External IP address.
Install Apache
-
Use the Debian package manager to install the
apache2package.sudo apt-get update && sudo apt-get install apache2 -y -
Overwrite the Apache web server default web page with the following command:
echo '<!doctype html><html><body><h1>Hello World!</h1></body></html>' | sudo tee /var/www/html/index.html
Test your server
Test that your instance is serving traffic on its external IP.
- Go to the VM Instances page in the Google Cloud Platform Console.
- Copy the external IP for your instance under the External IP column.
- In a browser, navigate to
http://[EXTERNAL_IP].
You should now see the "Hello World!" page.
Clean up
When you're done experimenting, follow the clean up instructions in the Quickstart to avoid incurring charges for the virtual machine instance.
Troubleshooting
Receiving a Connection Refused error
If you are seeing a Connection Refused error, it is possible that:
-
Your VM instance is not publicly accessible because your firewall rules or tags are misconfigured in one of the following ways:
- The VM instance does not have the proper tag that allows Compute Engine to apply the appropriate firewall rules to your instance.
- Your project does not have a firewall rule that allows traffic to the external IP address for your instance.
-
You are trying to access the VM using an
httpsaddress. Check that your URL ishttp://[EXTERNAL_IP]rather thanhttps://[EXTERNAL_IP].
To ensure that your VM instance has the correct tags:
- Go to the VM Instances page in the Google Cloud Platform Console.
- Click the name of the instance that you are trying to connect to.
- Click Edit at the top of the page.
- Scroll down to Firewalls, and make sure the Allow HTTP traffic box is checked. If it is not checked, check it.
- Save your changes. This ensures that the correct tags are added to the VM instance.
To ensure that the correct firewall rule exists:
- Go to the Firewall rules page in the Google Cloud Platform Console.
- Look for a firewall rule that allows all IP ranges through tcp:80. Usually,
this rule is named the
default-allow-httprule. - If a rule does not exist, create one.
- Click Create firewall rule.
- Enter a name for the rule, such as
default-allow-http. - Under Source IP ranges, enter
0.0.0.0/0to allow traffic from all sources. - Under Protocols and ports, check Specified protocols and ports
and enter
tcp:80. - Create your firewall rule.
Test your server again by going to the external IP address of the instance:
http://[EXTERNAL_IP]
What's next
Learn how to host a website on Google Compute Engine.


