Introduction

This quide is to help you setup a webserver at home to host your own website or websites. This guide can be used by students or for someone looking to setup webserver at home and want to know what are steps involved. If you are ready, go to next step to learn more about what you will need.

Requirements

You will need to have the following

  • Ethernet Internet Connection
  • Windows computer
  • Server(i am using Rock64)
  • power adapter for your server
  • Ethernet Cable
  • Memory Card

Installing OS on server

  1. Install pine installer from github on your windows computer and then insert the sd card into your computer
  2. Open the installer and select your device(in this case rock64)
  3. Choose the os you want to install on the sd card(in my case Community debian stretch minimal(rock64 microSD ))
  4. Select flash memory card if not already selected and hit flash
  5. Once flash is complete, removed sd card from computer and insert in into the rock64
  6. Connect it to hdmi display and a keyboard and mouse and ethernet cable and then power it up.
  7. Username and password is rock64
  8. If the computer gives some extra code while typing from the keyboard. Try following command and then enter password for rock64.
    sudo -I
  9. Then type following commands.This will fix the issue
    Cd /proc/sys/kernel
    Echo 4 > printk

Setting up web server

  1. Install apache2 webserver using the following command in the console
    Sudo apt-get install apache2
  2. Type Y to continue when prompted
  3. If you have completed the previous step successfully then you will be able to access your webserver from anycomputer on your local network(your home network).
  4. To access your webserver, you will need its ip address which can be found by running following command in the server console ip addr show
  5. Now you can type this number inside your browser and hit enter. This should open the default webpage on your server.

Configuring home router

If you try to access your website from any other computer on the internet, it will not work, you will not get any webpage. This fails for following two reasons.
  1. you are tying to access your website using a private ip address.Note:Private ip addresses can only be used on local networks
  2. your home internet router is blocking all incoming web requests from internet

Lets configure your router to not block our incoming requests and instead send them to our newly configured webserver. For this we will need ip address of our home router, which can be found by using same command we used in previous step. But this time we will note the number after the default gateway.

Next, we will open browser and put that number in the browser and hit enter.

Steps below will differ from router to router but what we will do is as follows:
  1. We will look for port forwarding rules. it might be under firewall settings
  2. Next we will configure our router to forward ports 80 and 443 to our server by entering the private ip address of our server we found previously.

Now our router is sending incoming requests to our server, but we cannot use private ip to access our server. What we will do instead is find public ip address of our router and send request to our router which is now already configured to forward request to our web sever.

Simple way to find your public ip addres is to search in google "my ipv4 addresss" using any computer connected to your home network. You will see similar type of number in the search results. This number is public ip address of your router.

Now you put this number in browser of any internet connected computer and access your website.

Are you thinking why i have to put a number intead of a name like (google.com) in the browser to access my website. Next section will teach you how to do that

Setting up DNS or dynamic DNS

To access our server from the internet using a name like abc.com, we will need to have our name and ip address registered in public dns records. This can be done on many websites like godaddy.com and many others for a fee. But if you are looking for free option, you can go to noip.com and signup for their service. They will let you choose a name and then link it to your ip address.

After registation, you will be able to access your website using the name you choose at noip.com

Setting up https access to website

  1. add this line deb http://ftp.debian.org/debian stretch-backports main to your sources.list (or add a new file with the ".list" extension to /etc/apt/sources.list.d/) You can also find a list of other mirrors at https://www.debian.org/mirror/list
  2. Then run following commands sudo apt-get -t stretch-backports install "package"
    sudo apt-get install python-certbot-apache -t stretch-backports
    sudo certbot --authenticator webroot --installer apache
    sudo certbot certonly --authenticator standalone --pre-hook "apachectl -k stop" --post-hook "apachectl -k start"
  3. You certificate will expire after 90 days, to automatically renew it, please use the following command
    sudo certbot renew --dry-run