summaryrefslogtreecommitdiff
path: root/content/peertube.md
blob: 28759045a9c8427842dec5003ccf398c6d2efde3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
---
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 install -y curl sudo unzip vim ffmpeg postgresql postgresql-contrib g++ make redis-server git python-dev cron wget
```

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_14.x | bash -
apt install -y nodejs
npm install --global yarn
```

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

## 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)
cd /var/www/peertube/versions
wget "https://github.com/Chocobozzz/PeerTube/releases/download/${VERSION}/peertube-${VERSION}.zip"
unzip 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/production.yaml.example config/production.yaml
```

Now the `production.yaml` file must be edited in the following ways:

First, add the hostname:

```yaml
webserver:
  https: true
  hostname: 'example.org'
  port: 443
```

Then, the database:

```yaml
database:
  hostname: 'localhost'
  port: 5432
  ssl: false
  suffix: '_prod'
  username: 'peertube'
  password: 'your_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: 'chad@example.org'
```

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 <kbd>Ctrl-d</kbd> to log out and return to the root prompt where
we will configure Nginx and other system settings.

## Certbot

First, we will want a Certbot SSL certificate to encrypt connections to
our PeerTube instance. Just run the following:

```sh
certbot --nginx -d peertube.example.org certonly
```

## 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}/example.org/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
```

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

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

Although check the
[changelog](https://github.com/Chocobozzz/PeerTube/blob/develop/CHANGELOG.md)
to see if there are additional manual requirements for particular
updates.

------------------------------------------------------------------------

*Written by [Denshi.](https://denshi.org) Donate Monero
[here](https://denshi.org/donate.html)
[\[QR\]](https://denshi.org/images/monero.jpg)*