Hello everyone and welcome to this tutorial on how to host a website on your personal computer! In this article, I will explain all the steps to host your website on your own computer, and little tips to help you solve common issues.
For this tutorial, you will need any computer. Any. It should just have at least some storage free and a good amount of RAM (1 GB is usually enough if you just want a website). If you have an old laptop with a good battery, it is the perfect device to host your site because it has a battery, so it can stay alive even when there is a power outage.
If you have any Linux distribution, you can skip this part. We will assume a Debian-based distribution.
If you have Windows or any other OS, please install Debian using this manual, chapters 4-6. THIS WILL ERASE ALL DATA ON THE DISK. Please install the version without the GUI.
Start your computer with Debian.
Next, install the required software with:
sudo apt update
sudo apt install apache2
Then, accept any prompts. This installs Apache, the server that will host your website and give it to the rest of the Internet. Then, make your firewall accept incoming traffic:
sudo ufw allow in "WWW Full"
If this fails, don't panic: it means there is no firewall to configure.
You can now see if it works by running:
curl http://localhost
If you get some HTML (should end with something like </html>), it means it's working. You can continue.
Your site is in /var/www/html. You simply need to create index.html with something like:
<html><body><p>Hello world!</p></body></html>
Go to your router config, connected devices, and find your Debian computer. Write its IP on a paper. Then, on another device connected to the same network, open the IP you just wrote in a web browser. You should see your website ("Hello world!" if you used my example file above).
Right now, you can only see your site if you are on the same network as your Debian laptop. We can fix that by configuring port forwarding. I can't help you, because every router is different. A simple search online will help you. You just need to know that you need to forward port 80 (in and out) to the IP you wrote earlier. Then, go to What is my IP? and write this new IP too. Others will be able to see your site with this new IP.
Right now, your site's URL is just a bunch of numbers. Human brains are designed for text, not numbers. You probably need a domain name. If you have money, then buy a domain, add an A record pointing to your IP and then wait. The UI is different for all domain providers.
If you don't have money, I recommend FreeDNS. You can easily get a free subdomain. Let me know in the comments if you want a tutorial on how to use FreeDNS.
I hope this tutorial was helpful. See ya! :D