How To Self Host Your Own YouTube Instance.

Prinux
CodeX
Published in
5 min readAug 13, 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.

How To Install Your Own Website

For learning more about this topic you can visit this blog which is the first part of this self hosting guides:-

Click here to read

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 my site 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

Installing YT-local

First, you need to visite the yt-local git hub repo and go to their release section download the tar.gz file and extract the file contents to /usr/local directory. Also you need to remove the extracted for folder to yt-local

Create Python ENV

for creating a virtual environment in python, run this command. This helps to manage dependencies and packages easily.

python3 -m venv env

Now this will create a virtual environment and using the environment run this command

source env/bin/activate

Now we are the virtual environment and now we need to install the requirements

pip3 install -r requirements.txt

Now running the python server script will work,

python3 server.py

Now running this command is only for checking, what we need to do with this is to create a systemd service so that we can manage this service easily.

[Unit]
Description=My Youtube
[Service]
ExecStart=/usr/local/yt-local/env/bin/python /usr/local/yt-local/server.py
Exec=/usr/local/yt-local/env/bin/python /usr/local/yt-local/server.py
ExecReload=/usr/local/yt-local/env/bin/python /usr/local/yt-local/server.py

All you need to do to past these contents in a file called yt-local.service and save it. Remember, you will be needing root privileges for saving the file. And you must save this under this PATH /etc/systemd/system.

Now for starting the service.

systemctl start yt-local.service # starting the service
systemclt status yt-local.service # checking the status
  1. Navigate to the directory /etc/nginx/sites-available and create a new file (name it as you like, e.g., vids).
  2. Add the following contents to the new file:
server {
listen 80 ;
listen [::]:80 ;
server_name vids.example.xyz ;
root /var/www/mysite ;
index index.html index.htm index.nginx-debian.html ;
location / {
proxy_pass http:127.0.0.1:9010 ;
}
}

3. Create a symbolic link to enable the site:

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

4. Reload NGINX:

systemctl reload nginx

5. Now you should add a new Record in your domain called vids.example.xyz

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 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.