Assigning a Domain Name to Your Google Cloud Platform Apache Server
Tags: googlecloud
Published: 2020-08-31 16:50:59

In last week's blog, I discussed how to set up an Apache web server using Google Cloud Platform. However, this website was only accessible by it's IP address. For obvious reasons, this is not ideal as it is not easily remembered or easily transferable. Today, I'm going to discuss setting up your Apache Server with it's own domain name.

## How does a domain work?

Domain names allow your browser to request a connection to a server by using a simple-to-use alias. For example [http://www.google.com/](http://google.com/) actually connects to a web server with a specific IP address. As a typical user, we do not see this IP address and only interface with Google using the domain name [http://google.com/](http://google.com/). This makes using the Google website a much better experience. This mapping of aliases to IP addresses is possible through a system called the Domain Name System (DNS).

In simple terms, the DNS is a network of servers that keep records of all the domain names and their corresponding IP addresses. All of these domain servers are created and managed by domain hosting companies (Google, GoDaddy, Domain.com, etc.) When a browser makes a request to a domain name, the DNS matches the domain name request to an IP address and then serves the information to the user.

## How do we get a domain

No matter what, domains are not free. You can choose any domain hosting service you like to host your domain, however, since we created our server using Google Cloud Platform, I will be using Google Domains. However, don't be too worried if you do not want to use this service as the process is largely the same. Just go onto the domain hosting service website and sign up.

## Creating a Google Domain

To start, go to [domains.google.com](https://domains.google/) and type in the domain you would like to purchase into the search bar.

![Domain Name Search](https://dev-to-uploads.s3.amazonaws.com/i/anau4cbmtg0vax763qnp.PNG)

If the name is available, you can add the domain name to your cart. You must then sign in to your Google account and go through the checkout process to purchase the domain. After you're done, you are now a proud owner of your own domain name! Congratulations!

## Configuring Your Domain DNS

Now that we have our own domain name, we must now point the domain name to our Apache web server. To do this, we will be configuring our DNS for this domain. To start, navigate to the DNS tab on the Google Domains dashboard.

![DNS Dashboard](https://dev-to-uploads.s3.amazonaws.com/i/vbg62i5jee88c6b3l0rx.PNG)

You can now select your name servers. Here, Google allows you to use other DNS providers for your domain name, however, we're going to stick to using Google's name servers. You can read more on domain name servers [here](https://support.google.com/domains/answer/3290309?hl=en).

We can ignore DNSSEC, Registered hosts, and Synthetic records for now as these offer additional configuration options.

### Custom Resource Records

Scroll down to the bottom of the page to Custom resource records. This is where we will link our IP address to our domain. This is fairly straightforward, however, we need to understand the concept of resource record types. Resource record types tell your domain DNS how to route traffic when users connect to your domain. The types we will use in this tutorial are A and CNAME. To see a full list of resource types, you can read the documentation [here](https://support.google.com/domains/answer/3251147?hl=en).

The A resource record type maps the domain name to the a specific IP address. As you can guess, we will use this one to tie the IP address from our Apache web server.

The CNAME (cononical name) resource record type maps an alias domain name to a true domain name. For this, we are simply going to point the www subdomain to the true domain name. This redirects www.[yourdomainname].com to [yourdomainname].com.

Since I did not want to buy a new domain name for this tutorial, I am using my own website [brandonmichaelbrown.com](https://brandonmichaelbrown.com). To configure the custom resource records, you can use the template below. Just make sure to update the IP address to your own IP address running the Apache web server.

![Custom Resource Records Configuration](https://dev-to-uploads.s3.amazonaws.com/i/aftlzi1rrqfcxbqavaag.PNG)

#### Quick note on the "A" record

The @ symbol is used as a "root" alias. This tells the DNS that when anyone connects to your root domain (brandonmichaelbrown.com in this example), it should redirect traffic to the IP address specified.

## Additional Google Domain Features

As mentioned before, there are a couple of additional features in the DNS table for Google Domains. These include DNSSEC, Registered hosts, and Synthetic records.

DNSSEC offers some additional security which you can read about [here](https://support.google.com/domains/answer/6387342?hl=en). 

Registered hosts allows you to configure subdomains for your website. For example, Google has an images subdomain located at [http://images.google.com/](http://images.google.com/). You can read more about registered hosts [here](https://support.google.com/domains/answer/6147097?hl=en).

Synthetic records are unique to Google Domains and give you the ability to add domain forwarding to your domain address. You can read more about Synthetic records [here](https://support.google.com/domains/answer/6069273?hl=en).

## Conclusion

After you finish these steps, you should have your domain name configured. It may take a little while as the network of DNS providers needs to update. I believe Google says up to 48 hours, but I've only had to wait a maximum of 4 hours on previous occasions. After checking in every hour or so, you should eventually see your Apache web server hosting to your new domain name!

I hope this tutorial has been helpful and easy to walk through. Please reach out to me if you have any questions setting up your domain name!