--- title: "PeerTube" date: 2021-07-31 icon: "peertube.svg" tags: ["service", "activity-pub"] short_desc: "Your own self-hosted video-site also compatible with Activity Pub." --- PeerTube is a self-hosted and (optionally) federated video sharing platform that saves bandwith on videos the more people watch. PeerTube instances can follow each other to share videos and grow the federated network, but you can always keep your instance to yourself if you choose to. ## Note on Bandwidth Video sharing is the most bandwidth intensive thing on the internet! If you plan on just having a small personal site with a few viewers and friends, that won\'t be a big concern, but most VPS providers like Vultr have caps on how much bandwidth can be used within a month without being throttled. This level is far beyond what most sites need, but it might be an issue with a video site! So if you plan on having a big video-sharing PeerTube site, it\'s a good idea to host it with a provider that offers infinite bandwidth. I strongly recommend getting a separate VPS with [Frantech/BuyVM](https://my.frantech.ca/aff.php?aff=3886). They have unmetered bandwidth, extremely cheap block storage for hosting many, many videos and they even have a good record of being censorship resistant. ## Prerequisites **Most** of PeerTube\'s dependencies can be installed with this command: ```sh apt update apt install -y curl sudo unzip vim ffmpeg postgresql postgresql-contrib g++ make redis-server git cron wget certbot nginx ffmpeg postgresql postgresql-contrib openssl g++ make redis-server git cron wget apt install python3-dev python3-pip python-is-python3 python --version # Should be >= 3.8 ffmpeg -version # Should be >= 4.1 g++ -v # Should be >= 5.x redis-server --version # Should be >= 6.x ``` It\'s also important to start all associated daemons: ```sh systemctl start postgresql redis ``` PeerTube also requires **NodeJS 14** and **yarn** which cannot be installed from the Debian repositories. This means they have to be installed from separate, external repos: ```sh curl -fsSL https://deb.nodesource.com/setup_22.x -o nodesource_setup.sh bash nodesource_setup.sh apt install -y nodejs node -v # Should be 20.x or 22.x ``` Now we create a PeerTube user to run and handle PeerTube with the proper permissions: ```sh useradd -m -d /var/www/peertube -s /bin/bash -p peertube peertube passwd peertube ls -ld /var/www/peertube # Should be drwxr-xr-x ``` ## Database PeerTube requires a PostgreSQL database to function. To create it, first make a new Postgres user named PeerTube: ```bash su -l postgres createuser -P peertube createdb -O peertube -E UTF8 -T template0 peertube_prod psql -c "CREATE EXTENSION pg_trgm;" peertube_prod psql -c "CREATE EXTENSION unaccent;" peertube_prod exit ``` Be sure to **make note of your Postgres user password,** as it will be needed later when setting up PeerTube. ## Installation Using `su -l`, we will become the PeerTube user to create the required directories and download and install PeerTube itself with the proper permissions. First, we create the required directories. ```sh su -l peertube mkdir config storage versions chmod 750 config/ ``` ### Downloading PeerTube Still as the PeerTube user, we can now check for the most recent PeerTube versions number, download and install it in the newly created `versiond` directory. ```bash VERSION=$(curl -s https://api.github.com/repos/chocobozzz/peertube/releases/latest | grep tag_name | cut -d '"' -f 4) && echo "Latest Peertube version is $VERSION" cd /var/www/peertube/versions wget -q "https://github.com/Chocobozzz/PeerTube/releases/download/${VERSION}/peertube-${VERSION}.zip" unzip -q peertube-${VERSION}.zip && rm peertube-${VERSION}.zip ``` ### Installation via Yarn The downloaded release can then be symbolically linked to `/var/www/peertube/peertube-latest` and **yarn** is used to install PeerTube: ```sh cd /var/www/peertube ln -s versions/peertube-${VERSION} ./peertube-latest cd ./peertube-latest yarn install --production --pure-lockfile ``` ## Configuration PeerTube's default config file can be copied over to `/var/www/peertube/config/production.yaml` so it can actually be used: Note that we are still running these as the PeerTube user (having run `su -l peertube`). ```sh cd /var/www/peertube cp peertube-latest/config/default.yaml config/default.yaml cp peertube-latest/config/production.yaml.example config/production.yaml ``` Now the `production.yaml` file must be edited in the following ways: First, generate a secret key by `openssl rand -hex 32`: ```yaml secrets: # Generate one using `openssl rand -hex 32` peertube: "5e55258877f5d259cb1b5e5562dcb0eded3a2c3373d9fafac65ed765fbb1936c" ``` Add the hostname: ```yaml webserver: https: true hostname: "peertube.thesiah.xyz" port: 443 ``` Then, the database: ```yaml database: hostname: "localhost" port: 5432 ssl: false suffix: "_prod" username: "peertube" password: "your_database_password" pool: max: 5 ``` An email to generate the admin user: ```yaml admin: # Used to generate the root user at first startup # And to receive emails from the contact form email: "peertube@thesiah.xyz" ``` And **optionally,** email server information: ```yaml smtp: # smtp or sendmail transport: smtp # Path to sendmail command. Required if you use sendmail transport sendmail: null hostname: mail.example.org port: 465 # If you use StartTLS: 587 username: your_email_username password: your_email_password tls: true # If you use StartTLS: false disable_starttls: false ca_file: null # Used for self signed certificates from_address: "admin@example.org" ``` At this point, we have done all we need to do as the PeerTube user. Run `exit` or press Ctrl-d to log out and return to the root prompt where we will configure Nginx and other system settings. ```sh exit ``` ## Nginx PeerTube includes an Nginx configuration that can be copied over to `/etc/nginx/sites-available:` ```sh cp /var/www/peertube/peertube-latest/support/nginx/peertube /etc/nginx/sites-available/peertube ``` Because the PeerTube config is so long, it\'s recommended to use `sed` to modify the contents of the file, replacing `${WEBSERVER_HOST}` with your hostname, and `$(PEERTUBE_HOST)` with your localhost and port, which by default should be `127.0.0.1:9000`: ```sh sed -i 's/${WEBSERVER_HOST}/videos.thesiah.xyz/g' /etc/nginx/sites-available/peertube sed -i 's/${PEERTUBE_HOST}/127.0.0.1:9000/g' /etc/nginx/sites-available/peertube ``` Once you\'re happy with the Nginx config file, link it to `sites-enabled` to activate it: ```sh ln -s /etc/nginx/sites-available/peertube /etc/nginx/sites-enabled/peertube ``` ## Certbot First, we will want a Certbot SSL certificate to encrypt connections to our PeerTube instance. Just run the following: ```sh systemctl stop nginx certbot certonly --standalone -d videos.thesiah.xyz systemctl restart nginx ``` ## Running PeerTube A config file for a systemd daemon is included in PeerTube and can be setup and started like so: ```sh cp /var/www/peertube/peertube-latest/support/systemd/peertube.service /etc/systemd/system/ systemctl daemon-reload systemctl enable --now peertube systemctl start peertube journalctl -feu peertube ``` PeerTube will take a minute or so to start, but after it does, you can check its status with `systemctl status peertube` and at this point, your PeerTube site should be live! ## Using PeerTube To get the automatically generated admin password, run: ```sh cat /var/www/peertube/storage/logs/peertube.log | grep password ``` To set a password for your admin user, run: ```sh cd /var/www/peertube/peertube-latest NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run reset-password -- -u root ``` Login to your PeerTube instance using the admin email specified in your `production.yaml` file and the admin password you just set. {{< img alt="PeerTube login" src="/pix/peertube-login.jpg" >}} Once logged in, it\'s recommended to create a separate user without admin privileges for uploading videos to PeerTube. This can be done easily from the users tab in the administration section. Enjoy your PeerTube instance! --- ## Updating PeerTube PeerTube is constantly adding new features, so it\'s a good idea to [check for new updates](https://github.com/Chocobozzz/PeerTube/blob/develop/CHANGELOG.md) and add them if you wish. Just in the past year, they have added livestreaming and more. ### PeerTube instance Updating is fairly easy now since an `upgrade.sh` script has been added. Just run: ```sh cd /var/www/peertube/peertube-latest/scripts && sudo -H -u peertube ./upgrade.sh sudo systemctl restart peertube # Or use your OS command to restart PeerTube if you don't use systemd ``` ### Update PeerTube configuration Check for configuration changes, and report them in your `config/production.yaml` file: ```sh cd /var/www/peertube/versions diff -u "$(ls -t | head -2 | tail -1)/config/production.yaml.example" "$(ls -t | head -1)/config/production.yaml.example" ``` ### Update nginx configuration Check changes in nginx configuration: ```sh cd /var/www/peertube/versions diff -u "$(ls -t | head -2 | tail -1)/support/nginx/peertube" "$(ls -t | head -1)/support/nginx/peertube" ``` ### Update systemd service Check changes in systemd configuration: ```sh cd /var/www/peertube/versions diff -u "$(ls -t | head -2 | tail -1)/support/systemd/peertube.service" "$(ls -t | head -1)/support/systemd/peertube.service" ``` ### Restart PeerTube If you changed your nginx configuration: ```sh sudo systemctl reload nginx ``` If you changed your systemd configuration: ```sh sudo systemctl daemon-reload ``` Restart PeerTube and check the logs: ```sh sudo systemctl restart peertube sudo journalctl -fu peertube ``` Although check the [changelog](https://github.com/Chocobozzz/PeerTube/blob/develop/CHANGELOG.md) to see if there are additional manual requirements for particular updates. ## Things went wrong? Change peertube-latest destination to the previous version and restore your SQL backup: ```sh OLD_VERSION="v0.42.42" && SQL_BACKUP_PATH="backup/sql-peertube_prod-2018-01-19T10:18+01:00.bak" && \ cd /var/www/peertube && sudo -u peertube unlink ./peertube-latest && \ sudo -u peertube ln -s "versions/peertube-$OLD_VERSION" peertube-latest && \ sudo -u postgres pg_restore -c -C -d postgres "$SQL_BACKUP_PATH" && \ sudo systemctl restart peertube ``` ## Remote PeerTube CLI `peertube-cli` is a tool that communicates with a PeerTube instance using its REST API. It can be launched from a remote server/computer to easily upload videos, manage plugins, redundancies etc. ### Installation Ensure you have node installed on your system: ```sh node --version # Should be >= 16.x ``` Then install the CLI: ```sh sudo npm install -g @peertube/peertube-cli ``` ### CLI wrapper The wrapper provides a convenient interface to the following sub-commands. The wrapper can keep track of instances you have an account on. We limit to one account per instance for now. ```sh peertube-cli auth add -u 'PEERTUBE_URL' -U 'PEERTUBE_USER' --password 'PEERTUBE_PASSWORD' peertube-cli auth list ┌──────────────────────────────┬──────────────────────────────┐ │ instance │ login │ ├──────────────────────────────┼──────────────────────────────┤ │ 'PEERTUBE_URL' │ 'PEERTUBE_USER' │ └──────────────────────────────┴──────────────────────────────┘ ``` ### peertube-cli upload You can use this script to upload videos directly from the CLI. Videos will be publicly available after transcoding (you can see them before that in your account on the web interface). ```sh cd ${CLONE} peertube-cli upload --help peertube-cli upload "videoFile" peertube-cli plugins list ``` peertube-cli plugins Install/update/uninstall or list local or NPM PeerTube plugins: ```sh cd ${CLONE} peertube-cli plugins --help peertube-cli plugins list --help peertube-cli plugins install --help peertube-cli plugins update --help peertube-cli plugins uninstall --help peertube-cli plugins install --path /my/plugin/path peertube-cli plugins install --npm-name peertube-theme-example ``` ### peertube-cli redundancy Manage (list/add/remove) video redundancies: To list your videos that are duplicated by remote instances: ```sh peertube-cli redundancy list-remote-redundancies ``` To list remote videos that your instance duplicated: ```sh peertube-cli redundancy list-my-redundancies ``` To duplicate a specific video in your redundancy system: ```sh peertube-cli redundancy add --video 823 ``` To remove a video redundancy: ```sh peertube-cli redundancy remove --video 823 ``` --- _Written by [TheSiahxyz.](https://thesiah.xyz) Donate Monero [here](https://thesiah.xyz/donate.html) [\[QR\]](https://thesiah.xyz/images/monero.jpg)_