How to self-host your own website

Prinux
CodeX
Published in
4 min readJul 29, 2023

Buy a Domain Name

You can register your own domain using any domain name registrar. I recommend using Namecheap, which I have been using for registering my domains.

Buy Your Server

There are several server providers available, such as Linode, Vultr, and AWS. I suggest using Vultr, as it allows for a quick and easy account setup and provides servers that cost only $5 per month, which should be sufficient for most use cases.

How to Buy A Server Using Vultur

Click this link to get a 14-day free trial with $100 credits to create and experiment with multiple servers..

Step 1: Click on the blue plus icon

From there, configure your server this way.

  • Under the chose server option, select Cloud Compute (second one)
  • Choose “Regular Performance” for CPU & Storage Technology.
  • Select a server location near you.
  • Choose Debian as your Operating System.
  • For Server Size, select the $5 option.
  • Disable auto-backups.
  • Enter your server hostname and label.
  • Click “Deploy” to start the deployment process.
  • This configuration is designed based on the cheapest hosting option, which costs $5 per month. However, if you are looking for even faster servers with GPU capabilities, you can try using this link to receive $100 credit for 14 days. This credit will allow you to experiment with and experience the higher performance servers offered by Vultr during the trial period.

Keep in mind that GPU-enabled servers typically provide enhanced processing power, making them suitable for computationally intensive tasks, such as machine learning and data processing. If your project requires such capabilities, utilizing the GPU servers might be a more suitable choice.

After deployment, click on your server for viewing your server details.

Connecting Your Server with Your Domain Name

After buying a domain from Namecheap, follow these steps to connect it to your server:

  1. Go to your Namecheap dashboard and click on the “Manage” button for your domain.
  2. Navigate to the “Advanced DNS” tab.
  3. Under the “HOST RECORDS” section, add the IPv4 address of your server using an A record and IPv6 using an AAAA record.
  4. Click the “Add Record” button and allow a few minutes for the DNS records to update.

SSH into your server

Now from your personal computer you can use SSH and connect remotely to your server and manage it,

ssh root@mysite.com

here instead of mysite change it with the domain that you have brought after this, if you have correctly set your DNS records it will prompt you for your password, you will get the password for the server from your server provider.

Installing NGINX

run the command
sudo apt update && sudo apt upgrade
After this run
sudo apt install nginx

Allow ports

after installing nginx, run these two commands that are required for accessing your server

ufw allow http
ufw allow https

Now if you visit your site you would see a default nginx page for changing that

Adding Your Website

Follow these steps to set up your website on the server:

  1. Delete the default directory /var/www/default and create a new directory called /var/www/site.
  2. Save all your website files in the /var/www/site folder.
  3. Navigate to the directory /etc/nginx/sites-available and create a new file (name it as you like, e.g., site).
  4. Add the following contents to the new file:
server {
listen 80 ;
listen [::]:80 ;
server_name example.org ;
root /var/www/site ;
index index.html index.htm index.nginx-debian.html ;
location / {
try_files $uri $uri/ =404 ;
}
}

5. Create a symbolic link to enable the site:

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

6. Reload NGINX:

systemctl reload nginx

Making Your Site HTTPS

Just run:

apt install python3-certbot-nginx

And this will install certbot and its module for nginx.

Now let’s run certbot:

certbot --nginx

Certbot will guide you through the process of selecting the domain you want to enable HTTPS for. Provide your email address when prompted and agree to the terms.

Your website is now ready and should be accessible securely over HTTPS.

If you want to know on how to make your own website, please do comment below.

If you like this blog , please don’t forget to give a clap . if you want to learn more about privacy,security,technology and Linux, consider following me. Plus, whatever I find interesting and valuable.

--

--

Prinux
CodeX
Writer for

I Am Linux Enthusiast , Privacy Advocate , Self Taught Programmer, plus a coffee addict. Follow me to learn more about privacy, linux and technology.