Updated 10 September 2019


PeerTube is a distributed video hosting and broadcasting platform. [PeerTube] ( is an independent, lightweight, scalable alternative to YouTube, Dailymotion and Vimeo. It uses visitor browsers to create a P2P-based distributed network. PeerTube supports the ActivityPub protocol, which allows you to merge isolated servers with video content into a federated network. People visiting it can subscribe to channels and be notified about new videos. This open source application is distributed under the AGPLv3 license.

Preparing a LXC container

We recommend that you install PeerTub in a separate container and configure it according to the manual.

Installing and configuring PostgreSQL

Install and configure PostgreSQL according to the manual. Replace dbtest with your peertube_prod database, and the test user with peertube. Complete the setup process:

psql -U postgres

psql (11.2)
Type "help" for help.
postgres=# \c peertube_prod
postgres=# CREATE EXTENSION pg_trgm;
postgres=# CREATE EXTENSION unaccent;
postgres=# \q

Installing PeerTube

Install the packages required by PeerTube:

emerge -a app-arch/unzip dev-db/redis media-video/ffmpeg dev-python/nodeenv

Create a peertube user account and protect it with a password:

mkdir -p /var/calculate/www

useradd -m -d /var/calculate/www/peertube -s /bin/bash -p peertube peertube

passwd peertube

Install Node.js in the user directory:

su - peertube

nodeenv --node=8.16.3 .node-10

source .node-10/bin/activate

npm install -g yarn

echo 'source ~/.node-10/bin/activate' >> ~/.bash_profile

Create the necessary paths, download and extract the latest version of PeerTube:

mkdir config storage versions

VERSION=$(curl -s | grep tag_name | cut -d '"' -f 4) && echo "Latest Peertube version is $VERSION"

wget "${VERSION}/peertube-${VERSION}.zip" -P versions

unzip versions/peertube-${VERSION}.zip -d versions

rm versions/peertube-${VERSION}.zip

Install PeerTube:

ln -s versions/peertube-${VERSION} ./peertube-latest

cd ./peertube-latest

yarn install --production --pure-lockfile

cp /var/calculate/www/peertube/versions/peertube-latest/config/default.yaml /var/calculate/www/peertube/config/default.yaml

cp config/production.yaml.example ../config/production.yaml

PeerTube configuration

Setup PeerTube, replacing with your site:

# Correspond to your reverse proxy server_name/listen configuration
  https: true
  hostname: ''
  port: 443
# Your database name will be "peertube"+database.suffix
  hostname: 'localhost'
  port: 5432
  suffix: '_prod'
  username: 'peertube'
  password: 'secret'
    max: 5
# SMTP server to send emails
  port: 465 # If you use StartTLS: 587
  username: null
  password: null
  tls: true # If you use StartTLS: false
  disable_starttls: false
  ca_file: null # Used for self signed certificates
  from_address: ''
# From the project root directory
  tmp: '/var/calculate/www/peertube/storage/tmp/' # Used to download data (imports etc), store uploaded files before processing...
  avatars: '/var/calculate/www/peertube/storage/avatars/'
  videos: '/var/calculate/www/peertube/storage/videos/'
  redundancy: '/var/calculate/www/peertube/storage/videos/'
  logs: '/var/calculate/www/peertube/storage/logs/'
  previews: '/var/calculate/www/peertube/storage/previews/'
  thumbnails: '/var/calculate/www/peertube/storage/thumbnails/'
  torrents: '/var/calculate/www/peertube/storage/torrents/'
  captions: '/var/calculate/www/peertube/storage/captions/'
  cache: '/var/calculate/www/peertube/storage/cache/'
  # Used to generate the root user at first startup
  # And to receive emails from the contact form
  email: ''

Getting Let's Encrypt certificate

Get a certificate for Nginx on according to the manual.

Installing and configuring Nginx

Install and configure your Nginx server as a reverse proxy according to the manual.

Copy the default Nginx configuration file for PeerTube:

cp /var/calculate/www/peertube/peertube-latest/support/nginx/peertube /etc/nginx/sites-enabled/peertube.conf

Specify the paths and the server name,

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    ssl_certificate /etc/letsencrypt/live/;
    ssl_certificate_key /etc/letsencrypt/live/;
    # Bypass PeerTube for performance reasons. Could be removed
    location ~ ^/client/(.*\.(js|css|woff2|otf|ttf|woff|eot))$ {
        add_header Cache-Control "public, max-age=31536000, immutable";
        alias /var/calculate/www/peertube/peertube-latest/client/dist/$1;
    # Cache 2 hours
    add_header Cache-Control "public, max-age=7200";
    root /var/calculate/www/peertube/storage;
    rewrite ^/static/(thumbnails|avatars)/(.*)$ /$1/$2 break;
    try_files $uri
        # Don't spam access log file with byte range requests
        access_log off;
    root /var/calculate/www/peertube/storage;
    rewrite ^/static/webseed/(.*)$ /videos/$1 break;
    rewrite ^/static/redundancy/(.*)$ /redundancy/$1 break;

Starting PeerTube

Create an OpenRC script for PeerTube:

# Copyright 2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

name="Peertube daemon"
start_stop_daemon_args="-e NODE_ENV=production -e NODE_CONFIG_DIR=/var/calculate/www/peertube/config -e PATH=/var/calculate/www/peertube/.node-10/lib/node_modules/.bin:/var/calculate/www/peertube/.node-10/bin:\"$PATH\"

depend() {
        need nginx postgresql redis

start_pre() {
    checkpath -f -o peertube -m 0600 /var/log/peertube.log

Define the privileges:

chmod 0755 /etc/init.d/peertube

Launch the PeerTube daemon:

/etc/init.d/peertube start

Add PeerTube to autostart:

rc-update add peertube

Open in your Web browser:

Defining the administration password

The administrator password is created automatically. You can find it in the log. To reset the password, run:

cd /var/www/peertube/peertube-latest && NODE_CONFIG_DIR=/var/calculate/www/peertube/config NODE_ENV=production npm run reset-password -- -u root

Updating PeerTube

Download and unpack the new version of PeerTube:

su - peertube

VERSION=$(curl -s | grep tag_name | cut -d '"' -f 4) && echo "Latest Peertube version is $VERSION"

wget "${VERSION}/peertube-${VERSION}.zip" -P versions

unzip versions/peertube-${VERSION}.zip -d versions

rm versions/peertube-${VERSION}.zip

Install PeerTube:

cd versions/peertube-${VERSION}

yarn install --production --pure-lockfile

Copy the new default configuration file:

cp config/default.yaml /var/calculate/www/peertube/config/default.yaml

Update your production.yml configuration:

mv /var/calculate/www/peertube/config/production.yaml /var/calculate/www/peertube/config/production-old.yaml

cp config/production.yaml.example /var/calculate/www/peertube/config/production.yaml

Check the differences and move your settings to production.yaml:

diff /var/calculate/www/peertube/config/production{-old,}.yaml

Update the symlink:


unlink peertube-latest

ln -s versions/peertube-${VERSION} ./peertube-latest


Now restart PeerTube:

/etc/init.d/peertube restart