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.
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
- Install pine installer from github on your windows computer and then insert the sd card into your computer
- Open the installer and select your device(in this case rock64)
- Choose the os you want to install on the sd card(in my case Community debian stretch minimal(rock64 microSD ))
- Select flash memory card if not already selected and hit flash
- Once flash is complete, removed sd card from computer and insert in into the rock64
- Connect it to hdmi display and a keyboard and mouse and ethernet cable and then power it up.
- Username and password is rock64
If the computer gives some extra code while typing from the keyboard.
Try following command and then enter password for rock64.
- Then type following commands.This will fix the issue
Echo 4 > printk
Install apache2 webserver using the following command in the console
Sudo apt-get install apache2
- Type Y to continue when prompted
- 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).
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
- Now you can type this number inside your browser and hit enter. This should open the default webpage on your server.
- you are tying to access your website using a private ip address.Note:Private ip addresses can only be used on local networks
- 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:
- We will look for port forwarding rules. it might be under firewall settings
- 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
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
- 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
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"
You certificate will expire after 90 days, to automatically renew it, please use the following command
sudo certbot renew --dry-run