Run Your Own Video-Sharing Website with YouPHPTube on Debian 10 Buster

This tutorial is going to show you how to run your own video-sharing website with YouPHPTube on Debian 10 Buster. YouPHPTube is an open-source, self-hosted alternative to video-sharing websites like YouTube, Vimeo, etc. With YouPHPTube, you can upload video to your own server and share it with the Internet.

YouPHPTube Features

  • Unlimited and simultaneous live streams and you can have unlimited users connected to each live stream.
  • Import and encode videos from other sites directly from the Internet
  • Bulk encoding from local video directory
  • Make private videos
  • Totally integrated function with Youtube, letting you sync your videos with Youtube
  • Transcode multiple formats of multimedia files to MP4, WebM and MP3 file
  • Support Amazone S3 (Simple Storage Service)
  • Responsive site layout. YouPHPTube looks incredible on any device. (You can choose YouTube or Netfilx style layout.)
  • User channels and user playlists
  • Subscribe to channels you like
  • You can monitor the performance of your videos with up-to-date metrics and reports in YouPHPTube Statistics.
  • Extend site functionalities with plugins.
  • SEO Optimized
  • iOS and Android apps available

youphptube self-hosted alternative to youtube debian 10 buster

Prerequsites of Installing YouPHPTube on Debian 10 Buster

First, you need a Debian server with at least 2 CPU cores and 4GB RAM as a starting point. Obviously, if your video site gets more users, you need to upgrade your hardware as well. If you are looking for a VPS (virtual private server), then you can click this special link to create an account on Vultr to get $50 free credit (for new users only). Vultr also provides dedicated servers if you want to go that route. Once you have an account at Vultr, install Debian 10 Buster on your server and follow the instructions below.

YouPHPTube requires PHP and MySQL/MariaDB. To follow this tutorial, you should have already set up a LAMP stack or LEMP stack. If you prefer to use Apache web server, then install LAMP stack.

If you prefer to use Nginx web server, then install LEMP stack.

Note: YouPHPTube support with Nginx is only experimental. You may have issues if you use Nginx.

You also need a domain name. I registered my domain name at NameCheap because the price is low and they give whois privacy protection free for life.

YouPHPTube is comprised of two parts.

  • The main part is the front end streamer server, which allow users to watch existing videos.
  • The other part is the encoder, which allow users to upload their videos.

The public encoder uses the domain name encoder.youphptube.com. If you don’t want users to leave your site when uploading videos, you need to set up your private encoder. I will show you how in this article. Without further ado, let’s get started.

Step 1: Download YouPHPTube on Debian 10 Buster Server

Log into your Debian 10 Buster server via SSH. Then go to the web root directory.

cd /var/www/

Clone the YouPHPTube streamer repository from Github.

sudo apt install git
sudo git clone https://github.com/YouPHPTube/YouPHPTube.git

Then go into the directory.

cd YouPHPTube/

Clone the YouPHPTube encoder repository from Github.

sudo git clone https://github.com/YouPHPTube/YouPHPTube-Encoder.git

It will be saved as YouPHPTube-Encoder. We rename it to upload, so users can have a better idea what this URL is for when uploading videos.

sudo mv YouPHPTube-Encoder upload

Next, we need to make www-data (the web server user) as the owner of the web root.

sudo chown www-data:www-data /var/www/YouPHPTube/ -R

Step 2: Install Dependencies

YouPHPTube uses FFmpeg to encode videos. We can easily install FFmpeg from the default Debian repository.

sudo apt install ffmpeg

To read and write meta information in multimedia files, we need to install the libimage-exiftool-perl package.

sudo apt install libimage-exiftool-perl

To fetch videos from other sites, we need to install YouTube-DL. Though it’s included in the Debian repository, but it’s outdated. We will install YouTube-DL from the Python Package Index, which always contains the latest version of YouTube-DL.

sudo apt install python3-pip
sudo -H pip3 install youtube-dl

It’s very important that you use the latest version, or you might not be able to download videos from other sites. We can create a Cron job to automatically check and install the latest version.

sudo crontab -e

Add the following line at the end of the Crontab file to try upgrading YouTube-DL daily.

@daily sudo -H pip3 install --upgrade youtube-dl > /dev/null

Step 3: Create Database and User in MariaDB

Log into MariaDB database server with the following command. Since MariaDB is now using unix_socket plugin to authentication user login, there’s no need to enter MariaDB root password. We just need to prefix the mysql command with sudo.

sudo mysql

Then create a database for YouPHPTube. This tutorial names the database YouPHPTube. You can use whatever name you like.

create database YouPHPTube;

Create the database user. Again, you can use your preferred name for this user. Replace your-password with your preferred password.

create user youphptube@localhost identified by 'your-password';

Grant this user all privileges on the youphptube database.

grant all privileges on YouPHPTube.* to youphptube@localhost;

We also need to create a separate database for the encoder.

create database YouPHPTubeEncoder;

Create a user for this database.

create user encoder@localhost identified by 'your-password';

Grant privileges.

grant all privileges on YouPHPTubeEncoder.* to encoder@localhost;

Flush the privileges table and exit.

flush privileges;

exit;

Step 4: Setting Up Web Server

We can use Apache or Nginx web server.

Apache

If you prefer Apache, create a virtual host file for YouPHPTube with a command line text editor like Nano.

sudo nano /etc/apache2/sites-available/youphptube.conf

Put the following text into the file. Replace the red-colored text with your actual data. I use a subdomain in this tutorial. You can use your main domain name if you prefer. Don’t forget to set DNS A record for the domain name in your DNS record manager. Also note that the document root directory is case-sensitive and you should not add a forward slash at the end.

<VirtualHost *:80>
    ServerName tube.yourdomain.com
    DocumentRoot /var/www/YouPHPTube

    <Directory /var/www/YouPHPTube>
       DirectoryIndex index.php
       Options +FollowSymLinks
       AllowOverride All
       Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/youphptube.error.log
    CustomLog ${APACHE_LOG_DIR}/youphptube.access.log combined

</VirtualHost>

Save and close the file. Then enable this virtual host.

sudo a2ensite youphptube.conf

We need to enable the rewrite module.

sudo a2enmod rewrite

Restart Apache for the changes to take effect.

sudo systemctl restart apache2

Now visit tube.yourdomain.com and you will be redirected to the setup wizard page (tube.yourdomain.com/install/index.php). If you see the default Apache page instead of the setup wizard, then you need to disable the default virtual host.

sudo a2dissite 000-default.conf

And restart Apache.

Before entering any information in the setup wizard, we need to enable HTTPS.

Nginx

If you prefer Nginx, create a youphptube.conf file in /etc/nginx/conf.d/ directory.

sudo nano /etc/nginx/conf.d/youphptube.conf

Put the following text into the file. Replace the red-colored text with your actual data. I use a subdomain in this tutorial. You can use your main domain name if you prefer. Don’t forget to set DNS A record for the domain name in your DNS record manager. Also note that the document root directory is case-sensitive.

server {
    listen      80;
    server_name tube.yourdomain.com;

    root /var/www/YouPHPTube;
    index index.php index.html index.htm;
    charset utf-8;
    client_max_body_size 2G;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    access_log  /var/log/nginx/youphptube.access.log;
    error_log   /var/log/nginx/youphptube.error.log;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php/php7.3-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location = /upload/index.php {
       rewrite ^(.*)$ /upload/view/index.php last;
    }

    location = /upload/isAdmin {
      rewrite ^(.*)$ /upload/view/isAdmin.php last;
   }

   location = /upload/removeStreamer {
     rewrite ^(.*)$ /upload/view/removeStreamer.php last;
   }

  location = /upload/priority {
     rewrite ^(.*)$ /upload/view/priority.php last;
  }

  location = /upload/status {
     rewrite ^(.*)$ /upload/view/status.php last;
  }

  location = /upload/serverStatus {
    rewrite ^(.*)$ /upload/view/status.php?serverStatus=1 last;
  }

  location = /upload/upload {
    rewrite ^(.*)$ /upload/view/upload.php last;
  }

  location = /upload/listFiles.json {
   rewrite ^(.*)$ /upload/view/listFiles.json.php last;
  }

  location = /upload/deleteQueue {
    rewrite ^(.*)$ /upload/view/deleteQueue.php last;
  }

  location = /upload/saveConfig {
    rewrite ^(.*)$ /upload/view/saveConfig.php last;
  }

  location = /upload/youtubeDl.json {
    rewrite ^(.*)$ /upload/view/youtubeDl.json.php last;
  }

  location = /upload/send.json {
    rewrite ^(.*)$ /upload/view/send.json.php last;
  }

  location = /upload/streamers.json {
    rewrite ^(.*)$ /upload/view/streamers.json.php last;
  }

  location = /upload/queue.json {
    rewrite ^(.*)$ /upload/view/queue.json.php last;
  }

  location = /upload/queue {
    rewrite ^(.*)$ /upload/view/queue.php last;
  }

  location = /upload/login {
    rewrite ^(.*)$ /upload/objects/login.json.php last;
  }

  location = /upload/logoff {
    rewrite ^(.*)$ /upload/objects/logoff.json.php last;
  }

  location /upload/ {
    rewrite "^/getImage/([A-Za-z0-9=/]+)/([A-Za-z0-9]{3})$" /upload/objects/getImage.php?base64Url=$1&format=$2 last;
    rewrite "^/getImageMP4/([A-Za-z0-9=/]+)/([A-Za-z0-9]{3})/([0-9.]+)$" /upload/objects/getImageMP4.php?base64Url=$1&format=$2&time=$3 last;
  }

  location /upload/getSpiritsFromVideo {
    rewrite ^/getSpiritsFromVideo/([A-Za-z0-9=/]+)/([0-9]+)/([0-9]+)$ /upload/objects/getSpiritsFromVideo.php?base64Url=$1&tileWidth=$2&totalClips=$3 last;
  }

  location /upload/getLinkInfo {
    rewrite ^/getLinkInfo/([A-Za-z0-9=/]+)$ /upload/objects/getLinkInfo.json.php?base64Url=$1 last;
  }

}

Save and close the file. Then test Nginx configuration.

sudo nginx -t

If the test is successful, reload Nginx for the changes to take effect.

sudo systemctl reload nginx

Now visit tube.yourdomain.com and you will be redirected to the setup wizard page (tube.yourdomain.com/install/index.php). Before entering any information in the setup wizard, we need to enable HTTPS.

Step 5: Enabling HTTPS

To encrypt the HTTP traffic, we can enable HTTPS by installing a free TLS certificate issued from Let’s Encrypt. Run the following command to install Let’s Encrypt client (certbot) on Debian 10 Buster server.

sudo apt install certbot

If you use Apache, you also need to install the Certbot Apache plugin.

sudo apt install python3-certbot-apache

And run this command to obtain and install TLS certificate.

sudo certbot --apache --agree-tos --redirect --hsts --staple-ocsp --email [email protected] -d tube.yourdomain.com

If you use Nginx, install the Certbot Nginx plugin.

sudo apt install python3-certbot-nginx

Next, run the following command to obtain and install TLS certificate.

sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email [email protected] -d tube.yourdomain.com

Where

  • --nginx: Use the nginx plugin.
  • --apache: Use the Apache plugin.
  • --agree-tos: Agree to terms of service.
  • --redirect: Force HTTPS by 301 redirect.
  • --hsts: Add the Strict-Transport-Security header to every HTTP response. Forcing browser to always use TLS for the domain. Defends against SSL/TLS Stripping.
  • --staple-ocsp: Enables OCSP Stapling. A valid OCSP response is stapled to the certificate that the server offers during TLS.

The certificate should now be obtained and automatically installed.

install youphptube on Debian 10 buster

Step 6: Finish Installation with the Setup Wizard

Now go to tube.yourdomain.com and the setup wizard will appear. On the left side, you can see if your server meet the requirements.

youphptube requirements

If you use Nginx, you can ignore the following message.

Your server is nginx/1.14.2, you must install Apache.

As you can see, the PHP post_max_size should be at least 100M and upload_max_filesize should be at least 100M. We need to edit the php.ini file to change the two values.  If you use Apache web server, then

sudo nano /etc/php/7.3/apache2/php.ini

If you use Nginx with PHP-FPM, then you need to edit the FPM version of php.ini file.

sudo nano /etc/php/7.3/fpm/php.ini

Find the following two lines.

post_max_size = 8M
upload_max_filesize = 2M

Change the values according to the video file size you are going to upload. For example, if you allow uploading 1G video file, then

post_max_size = 1024M
upload_max_filesize = 1024M

Save and close the file. Restart Apache for the changes to take effect.

sudo systemctl restart apache2

If you use Nginx with PHP-FPM, then restart PHP-FPM.

sudo systemctl restart php7.3-fpm

Now refresh the YouPHPTube install wizard page. Your server should pass all requirements. Now on the right side, you can enter a title your video site. Enter the YouPHPTube database name, user and password your created earlier. (Note: You should use the main database, not the encoder database. Also be aware of case-sensitive.) And set a system admin password.

youphptube create database and tables

 

Click the Install now button and YouPHPTube should be installed successfully.

youphptube install directory

Now we need to remove the /var/www/YouPHPTube/install/ directory.

sudo rm /var/www/YouPHPTube/install/ -r

Click the Go to the main page button and you will see the YouPHPTube main page.

youphptube main page

You can click the drop-down menu on the left and login as the admin user and with the password you set just a few moments ago.

youphptube admin signin

Step 7: Set Up the Encoder

Go to https://tube.yourdomain.com/upload/. You will be redirected to the Encoder setup wizard. If you are not automatically redirected, then you can manually enter the setup wizard URL.

https://tube.yourdomain.com/upload/install/index.php/

The left hand side will show you if your server meet the requirements of YouPHPTube Encoder.

youphptube encoder requirements

If you use Nginx, you can ignore the following message.

Your server is nginx/1.14.2, you must install Apache.

As you can see the PHP max_execution_time should be at least 7200 and PHP memory_limit should be at least 512M. We need to edit the php.ini file to change the two values.  If you use Apache web server, then

sudo nano /etc/php/7.3/apache2/php.ini

If you use Nginx with PHP-FPM, then you need to edit the FPM version of php.ini file.

sudo nano /etc/php/7.3/fpm/php.ini

Find the following two lines.

max_execution_time = 30
memory_limit = 128M

Change the values .

max_execution_time = 7200
memory_limit = 512M

Note that if later video encoding stops half way through, you need to increase the max_execution_time, or upgrade your CPU.

Save and close the file. Restart Apache for the changes to take effect.

sudo systemctl restart apache2

If you use Nginx with PHP-FPM, then restart PHP-FPM.

sudo systemctl restart php7.3-fpm

Now refresh the YouPHPTube Encoder install wizard page. Your server should pass all requirements. Now on the right side, you need to enter the YouPHPTubeEncoder database name, user and password your created earlier.  Be aware of case-sensitive and enter the streamer site’s admin password.

youphptube encoder setup wizard database

 

Click the Install Now button and YouPHPTube Encoder will be installed.

install youphptube encoder debian 10 buster

Remove the install directory.

sudo rm /var/www/YouPHPTube/upload/install/ -r

And go to the main page.

youphptube encoder admin signin

Step 8 : Change the Encoder URL

By default, YouPHPTube uses the public encoder for uploading videos. To use your own encoder, sign in as admin in YouPHPTube (not YouPHPTube encoder) and go to the admin panel from the left side admin panel.

youphptube admin panel

Go to settings -> site settings -> advanced configuration. Change the Encoder URL to https://tube.yourdomain.com/upload/. Save the settings, clear the cache directory and generate a new sitemap.

youphptube private encoder url

Now log out and log back in. If you click the encode video and audio button on the upper-right corner, you will be taken to your own encoder to upload videos. It should be noted that the encoding speed depends on your server’s CPU power.

Step 9: Configure SMTP

To send out emails (such as account registration, password reset, etc), you need to configure a SMTP server. If you would like to use your own mail server to send emails to clients, please check out the following article to set up your own mail server.

If you would like to use a SMTP relay service, I recommend Mailjet. You can follow the tutorial below to set up SMTP relay on your YouPHPTube server.

Enable TCP BBR

For a video streaming server, it’s recommended to enable the TCP BBR congestion control algorithm in the Linux kernel by following the instructions in the article below. (It’s written for Ubuntu, but also works on Debian 10 Buster.)

Mobile Apps

You can download the free android app or iOS app by doing a search for YouPHPTube on Google Play Store or YPT Mobile in Apple Store. White-label mobile app require a paid license.

Troubleshooting

If your YouPHPTube main page failed to load some CSS and JavaScript resources,

youphptube failed to load resources

It’s likely that you have added extra forward slash in the Apache or Nginx virtual host file for the web root directory. Instead of using

DocumentRoot /var/www/YouPHPTube/

You should use

DocumentRoot /var/www/YouPHPTube

Other Tidbits

When encoding videos, you can choose resolutions (low, SD, HD). If you use YouPHPTube as a personal video streaming site, I recommend choosing HD resolution only to reduce encoding time and save disk space. If you have already encoded videos to all 3 resolutions, you can go to the YouPHPTube video directory (/var/www/YouPHPTube/videos) and delete low resolution and SD resolution videos.

cd /var/www/YouPHPTube/videos/
sudo rm *Low.mp4
sudo rm *SD.mp4

Wrapping Up

I hope this tutorial helped you install YouPHPTube on Debian 10 Buster server. As always, if you found this post useful, then subscribe to our free newsletter to get more tips and tricks. Take care 🙂

Rate this tutorial
[Total: 2 Average: 5]

report this ad

8 Responses to “Run Your Own Video-Sharing Website with YouPHPTube on Debian 10 Buster

  • Maksol
    3 days ago

    you are the best
    thank you so much for your article
    this article is the best i’ve seen in the internet ( beside your entire Blog)
    thanks for everything bro

  • Maksol
    3 days ago

    last question please
    which Debian 10 buster should i download?
    from this website?
    https://www.debian.org/releases/buster/debian-installer/
    i don’t know really which version should i use
    my server hardware are:
    CPU: Intel Core i7-3770
    HDD: 2x HDD SATA 3,0 TB Enterprise
    RAM: 4x RAM 8192 MB DDR3

    thank you and waiting for the answer ( again, excuse my bad knowledge )

    • You can download the amd64 netinst CD image. It only contains an installer and doesn’t include any software repository. The installer will download packages from online Debian 10 repositories.

      • Maksol
        3 days ago

        thank you so much for your quick reply sir

      • Maksol
        2 days ago

        is it OK if i installed the script on another OS like Ubuntu ?
        i’m not sure if the problem i’m getting is because of Debian!
        if i can use another OS is there any command should i change?
        and would you please explain how to setup the live streamer so i can use the live stream option on my website please with RMTP?
        thank you for you answer in advance sir

    • I don’t think the problem is related to what distro you use.
      What web server are you using? As I said in this article, if you use Nginx, you might encounter problems. If so, use Apache instead.

      I will discuss setting up live streamer when I have time.

      • i used Apache server sir but when ran to
        Step 6: Finish Installation with the Setup Wizard
        and modified the file

        sudo nano /etc/php/7.3/apache2/php.ini

        nothing happened, the server didn’t meet the requirements of YouPHPTube, but when i modified the file using this command

        sudo nano /etc/php/7.3/fpm/php.ini

        the server meet the requirements of YouPHPTube
        which is strange because i didn’t install Nginx server
        same as Encoder happened with me when i ran to Step 7: Set Up the Encoder
        and after all i was not able to run my own Encoder, when i click on Encode video file it takes me to the public Encoder.
        i don’t know what’s happened unfortunately but i’m sure i didn’t ran any wrong step ^_^
        i’m so sorry to bother you but i think you the only one can help me with this

    • Maybe you are using Apache with PHP-FPM instead of the Apache PHP module, but that’s Ok.

      You need to change the encoder URL in YouPHPTube admin panel. Then log out the admin account and log in again

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community (https://community.linuxbabe.com) for questions unrelated to this article.
  • If my answer helped you, please consider supporting this site. Thanks :)