Webdomain, DNS and location on the server

To serve a webpage, you need a server with the proper software installed and a webdomain that points to the server location. Here, I will summarize the registration of a webdomain, refering the domain to the nameservers of DigitalOcean, creating the DNS-records on DigitalOcean and choosing a location for the website on the server. After setting up your webdomain, you need return to the main page to continue the installation of a website.

1. Register a webdomain and refer to the nameservers

Although technically it is possible to view a website on its ip-address, it is not very convenient. Basically, a domainname provides an alias for an IP-address. A domainname is registered with a certified registrar, most of whom will also provide serverspace to host a website. It is important to select a registrar with competitive pricing and who offers functionality to configure nameservers for yourself. I register my webdomains at versio.nl, but there many excellent alternatives. After registering the domainname the domain should be referred to the DigitalOcean nameservers: ns1.digitalocean.com, ns2.digitalocean.com and ns3.digitalocean.com.

2. Create DNS-records

The tutorial to setup a domain nameserver (DNS) is very on DigitalOcean is very clear and straightforward. To setup secure http for the domain with Certbot you need to add two A-type records to the DNS: one for mydomain.ext and another for www.mydomain.ext.

3. Decide about a server location

The webcontent will placed in a subdirectery on the server. The location you choose is up to you. In the examples on DigitalOcean, websites are mostly placed in /var/www. I prefer to create a user for each of my websites, because it keeps things clearly separated and I can easily adapt security measures for individual sites. I create a directory called webdomain and a subdirectory /public_html as the root location for public content. It can be convenient to place a simple index.html or index.php file in the root location for later testing.

$ sudo adduser webdomain
$ sudo usermod -a -G www-data webdomain
$ sudo /home/webdomain/mkdir public_html

Basic index.html:

<!DOCTYPE html>
<html>
  <head>
    <title>webdomain.com</title>
    <style>
	* { font-family: verdana; font-size: 10pt; COLOR: gray; }
	b { font-weight: bold; }
	table { height: 50%; border: 1px solid gray;}
	td { text-align: center; padding: 25;}
    </style>
  </head>
  <body>
    <center><br><br><br><br>
      <table>
	<tr><td>Welcome to the home of <b>webdomain.com</b></td></tr>
	<tr><td>To change this page, upload your website into the public_html directory</td></tr>
      </table>
    <br><br>
    </center>
  </body>
</html>

Basic index.php:

<!DOCTYPE html>
<html>
  <head>
    <title>webdomain.com</title>
    <style>
	* { font-family: verdana; font-size: 10pt; COLOR: gray; }
	b { font-weight: bold; }
	table { height: 50%; border: 1px solid gray;}
	td { text-align: center; padding: 25;}
    </style>
  </head>
  <body>
    <?php $domainname = 'webdomain.com'; ?>
    <center><br><br><br><br>
      <table>
	<tr><td>Welcome to the home of <b><?php echo $domainname; ?></b></td></tr>
	<tr><td>To change this page, upload your website into the public_html directory</td></tr>
      </table>
    <br><br>
    </center>
  </body>
</html>