How To Start Your Very Own Website

Welcome to setting up your first website! in this tutorial, I will be using the DNS server epik.com and using a VPS on vultr.com.

To be successful in setting up this website, you need to have an ssh connection (or PuTTY connection on windows) and a valid credit card for buying the DNS and VPS

Total Costs

VPS: $3.50/month
DNS: $8.00/year
The DNS may cost a bit more or bit less, depending on your domain name. I chose a standard .com domain name, which costed me $8.00/year. For example, if you get a .io domain, it usually costs around $50.00/year.

Setting up a VPS

What is a VPS?

VPS stands for Virtual Private Server. This is the machine which will be running as the server for your website, and serving the html pages to the clients that request it from across the world. This machine has a public IP address set up by default, so it will be accessible from anywhere in the world.

Buying the VPS

I will be showing how to use a VPS from vultr.com. As stated above, this will cost $3.50/month, so make sure you have enough money to support that.
Once you are on the vultr website, set up an account and link your credit card to the account. Linking the credit card will not cost money.
If you click “I just want to link my credit card - 0.00 deposit”, there will be no cost to linking your credit card.

Deploying the VPS

Once you link the credit card, click the tab “products”, and click the plus button to buy a new VPS.

  • Keep “Cloud Computing” checked (it should be checked by default).
  • Check the location that you prefer.
    • If you want to have fast uploads/downloads to and from your server, you can choose the option nearest to you, but the $3.50/month option may not be available at that location. I chose New York/New Jersey, which does support this option.
  • Choose the operating system that you want. I will be giving the rest of the tutorial assuming that you are using Debian 11, but you can experiment with any other OS that you want.
    • For whichever OS that you choose, Windows is probably the worst option, not even worth trying
  • Choose the plan that you prefer.
    • I chose the plan with a 10GB SSD, 1 CPU, 512MB Memory, and 500GB bandwidth per month
    • If you plan on storing large amounts of video/images, you may want to choose a more expensive plan with more storage, but I don’t need that
    • **Do not choose an “IPv6 Only” option, because this will make your site less accessible for some locations/browsers
  • Choose “enable IPv6” so that you have both IPv4 and IPv6 support, and the site is more accessible in more scenarios
  • Choose “Private Networking” because it doesn’t cost any extra
  • You want to upload your ssh public key, so that you don’t have to enter the password to log in every time, and your server will be much more secure.
    • If you don’t know how to get your ssh public key, check out my ssh tutorial
  • Enter your hostname as anything you want to identify this machine as, such as your desired domain name.

Now you can click “deploy now”, and your VPS will be deployed. It will take a minute or two, but once it starts up it will have a label that says “running”.


NOTE
To verify that your server is running, you can type

ping $IP

where $IP is the IP address of your vultr VPS. You can find this value by clicking Products -> Server Name, and the IP address will be listed there. If you get some feedback, you know the server is running


Setting up SSH

The primary mode of communicating with your server, and making changes on the server side, is through SSH (the Secure Shell). From here going forward, I will be defining $IP in any shell syntax as the IP address of your server that you set up on vultr.com

Loggin in

The first thing we want to do is to actually log in to the server. Go to Product -> Server Name, and find your IP address and password. with this, type

ssh root@$IP

and enter the password you find in vultr.com. Your terminal should now look like a default terminal, and if you type

whoami
curl ifconfig.io

you should get root and your ip address printed out.

Making sure only you can sign in (OPTIONAL)

Once you sign in, you will most likely want to make sure that you (and only you) can log in to the server and make important changes. An added benefit is that you don’t have to put in the password every time!

  1. Make sure that you have an ssh public/private key pair set up. If you don’t, check out [this website] (https://www.linuxshelltips.com/passwordless-ssh-login/).
  2. Copy your public key to your server. Use
ssh-copy-id root@$IP

You will have to put in the password this time, but if you log out of the server (with ) and try to log back in, you won’t have to put in your password. 3. Using your favorite text editor (vim is installed by default on most servers), edit the file /etc/ssh/sshd_config. Assuming you are using vim,

vim /etc/ssh/sshd_config

and type in the following lines:

PasswordAuthentication no
ChallengeResponseAuthentication no
UsePAM no

This will ensure that only those with their public key on the site (so far, this is only your machine) will be able to log in. This is the safest option to securing your web server, but can be dangerous if you lose access to your keys. Because of this, it is best practice to back up your ssh key pairs.

Setting up the DNS

What is a DNS?

DNS stands for Domain Name Server. For explanation, I will take google.com as an example. When you type in www.google.com into your browser, the browser has to know which machine to get the html code from

Buy the DNS

Go to epik.com and search for the DNS that you want. There is a good chance that it is already taken, so you will have to search for another one. As mentioned above, you will have to pay in order to register your domain, so you have to sign up for an account and connect your credit card.
You now own a Doman Name Server!

Linking the DNS records

You will want to set up 4 DNS records. From the epik.com homepage, go to DNS records. Here you will see multiple tabs of record types. Click on A/AAAA Records. You can delete any records that may already exist. You will enter 4 records

  • A record going from your domain to your vultr.com ipv4 address
  • A record going from **www.**your domain to your vultr.com ipv4 address
  • AAAA record going from your domain to your vultr.com ipv6 address
  • AAAA record going from **www.**your domain to your vultr.com ipv6 address

You can find your ipv6 address by going to Products -> Your server name -> Settings -> ipv6

Now, if you ping your DNS from the command line, with

ping $DNS

you should see results coming back from vultr.com, and your ip address specifically.

Setting up the web server on the VPS

Now comes the fun part! Of course, first log in to your server using SSH.
All steps from now on will assume that you are logged on to your server machine

Installing all required packages

The first thing you want to do is to run

apt update
apt upgrade -y

in order to make sure that your server if fully up to date and all packages are the most recent. Then, there are 3 packages you will install:

apt install nginx certbot python3-certbot-nginx

This will install the three packages: nginx, certbot, and python3-certbot-nginx.

  • nginx is the web server that I will be using for this tutorial. This is a more modern alternative to the ubiquitous apache web server, with the tradeoff being that some features may not be present or just may be different. If you want to use the apache web server, most steps will most likely be the same, but I cannot ensure it in this tutorial.
  • certbot is the program that will generate an SSL certificate for your website. This will allow your website to have encrypted connection with your web server (aka https:// instead of http:// in the website name). Although this is not strictly required, it is highly recommended because it gives your users a higher sense of security, allows a higher range of browsers to support your website, and will give higher priority to your website through various search engines.
  • python3-certbot-nginx is the plugin for certbot that allows it to communicate with nginx, and generate the necessary configuration pages for it. This package is also not necessary if you do not want to set up certbot.

Starting up nginx

After installing nginx, you want to first enable the service, so that it is constantly running. Type

systemctl enable nginx
systemctl start nginx

Then you want to make sure that the ports on the machine are open. This should be enabled by default, but in case it is not, run

iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT

to open up the ports 80 and 443 for anyone to access. This will allow any machine, not just the localhost, to access the website.

Configuring nginx

In order to configure your website, you must have a valid configuration file in /etc/nginx/sites-enabled. Firstly, you want to copy the default configuration, so that you are working non-destructively

cp /etc/nginx/sites-available/default /etc/nginx/sites-available/your_website

Now you can enable the site through creating a symlink from a configuration file from /etc/nginx/sites-available to /etc/nginx/sites-enabled, with the command

ln -s /etc/nginx/sites-available/your_website /etc/nginx/sites-enabled/

You can make sure everything is working so far by trying to access your domain name from a web browser on a local machine: it should show a default nginx webpage.

Adding custom content

Inside of /etc/nginx/sites-enabled/your_website, you can set the following values:

root /var/www/your_website
server_name your_website.com www.your_website.com

Now, of course the directory /var/www/your_website will not exist, so you need to create it.

mkdir -p /var/www/your_website

Now, you just want to put a default homepage in that directory. By convention, index.html is the first page that will be shown on your website. For example, if you type www.your_website.com into your browser, you will see the index.html page rendered. Create a file index.html in the /var/www/your_website directory, with

touch /var/www/your_website/index.html

Now you can edit this file, and put any bit of html inside of it. For the most basic preview, you can put in the following content:

<h1>Welcome to my website!</h1>

<p>This is some welcome text</p>

Now you have your website set up! You can put whatever content that you want inside of the /var/www/your_website directory, and it will show up on the webpage. To have more advanced nginx setup, check out the documentation. Contact me if you have any questions!