]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - support/doc/production.md
Add the activation of a needed SCL for CentOS
[github/Chocobozzz/PeerTube.git] / support / doc / production.md
CommitLineData
63bfad7e
C
1# Production guide
2
4df6a1b8
C
3 * [Installation](#installation)
4 * [Upgrade](#upgrade)
5
63bfad7e
C
6## Installation
7
66c3b774 8**Please don't install PeerTube for production on a small device behind a low bandwidth connection (example: a Raspberry PI behind your ADSL link) because it could slow down the fediverse.**
1185c246 9
63bfad7e
C
10### Dependencies
11
12Follow the steps of the [dependencies guide](dependencies.md).
13
14### PeerTube user
15
59c48d49 16Create a `peertube` user with `/var/www/peertube` home:
63bfad7e 17
afe81767 18```
59c48d49 19$ sudo useradd -m -d /var/www/peertube -s /bin/bash -p peertube peertube
e5203ffa
TC
20```
21
22Set its password:
23```
d2000ca6 24$ sudo passwd peertube
63bfad7e
C
25```
26
27### Database
28
e5203ffa 29Create the production database and a peertube user inside PostgreSQL:
63bfad7e 30
afe81767 31```
d2000ca6
C
32$ sudo -u postgres createuser -P peertube
33$ sudo -u postgres createdb -O peertube peertube_prod
63bfad7e
C
34```
35
d2000ca6 36### Prepare PeerTube directory
63bfad7e 37
e5203ffa
TC
38Fetch the latest tagged version of Peertube
39```
40$ 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"
41```
59c48d49 42
e5203ffa
TC
43Open the peertube directory, create a few required directories
44```
15dbc134 45$ cd /var/www/peertube && sudo -u peertube mkdir config storage versions && cd versions
e5203ffa 46```
59c48d49 47
e5203ffa 48Download the latest version of the Peertube client, unzip it and remove the zip
afe81767 49```
15dbc134
TC
50$ sudo -u peertube wget -q "https://github.com/Chocobozzz/PeerTube/releases/download/${VERSION}/peertube-${VERSION}.zip"
51$ sudo -u peertube unzip peertube-${VERSION}.zip && sudo -u peertube rm peertube-${VERSION}.zip
e5203ffa 52```
59c48d49 53
193b12bf
O
54Install Peertube. If you're using CentOS7, do not forget to activate the devtoolset-6 software collection:
55```
56$ scl enable devtool-6 bash
57```
58And after that, follow the step as usual. Do not forget to exit the environment after installing Peertube.
e5203ffa 59```
15dbc134 60$ cd ../ && sudo -u peertube ln -s versions/peertube-${VERSION} ./peertube-latest
09c93c20 61$ cd ./peertube-latest && sudo -H -u peertube yarn install --production --pure-lockfile
63bfad7e
C
62```
63
64### PeerTube configuration
65
66Copy example configuration:
67
afe81767 68```
59c48d49 69$ cd /var/www/peertube && sudo -u peertube cp peertube-latest/config/production.yaml.example config/production.yaml
63bfad7e
C
70```
71
72Then edit the `config/production.yaml` file according to your webserver
d2000ca6 73configuration.
63bfad7e 74
30f55025
C
75**PeerTube does not support webserver host change**. Keep in mind your domain name is definitive after your first PeerTube start.
76
63bfad7e
C
77### Webserver
78
e883399f
RK
79We only provide official configuration files for Nginx.
80
63bfad7e
C
81Copy the nginx configuration template:
82
afe81767 83```
59c48d49 84$ sudo cp /var/www/peertube/peertube-latest/support/nginx/peertube /etc/nginx/sites-available/peertube
63bfad7e
C
85```
86
5668bf2e
C
87Then modify the webserver configuration file. Please pay attention to the `alias` keys of the static locations.
88It should correspond to the paths of your storage directories (set in the configuration file inside the `storage` key).
63bfad7e 89
afe81767 90```
63bfad7e
C
91$ sudo vim /etc/nginx/sites-available/peertube
92```
93
0b495712
C
94Activate the configuration file:
95
96```
97$ sudo ln -s /etc/nginx/sites-available/peertube /etc/nginx/sites-enabled/peertube
98```
99
100To generate the certificate for your domain as required to make https work you can use [Let's Encrypt](https://letsencrypt.org/):
101
102```
103$ sudo systemctl stop nginx
e6607b25 104$ sudo vim /etc/nginx/sites-available/peertube # Comment ssl_certificate and ssl_certificate_key lines
0b495712 105$ sudo certbot --authenticator standalone --installer nginx --post-hook "systemctl start nginx"
e6607b25
C
106$ sudo vim /etc/nginx/sites-available/peertube # Uncomment ssl_certificate and ssl_certificate_key lines
107$ sudo systemctl reload nginx
e883399f
RK
108```
109
110Remember your certificate will expire in 90 days, and thus needs renewal.
63bfad7e 111
0b495712 112Now you have the certificates you can reload nginx:
63bfad7e 113
afe81767 114```
63bfad7e
C
115$ sudo systemctl reload nginx
116```
117
07aa93a8 118### systemd
63bfad7e 119
07aa93a8 120If your OS uses systemd, copy the configuration template:
63bfad7e 121
afe81767 122```
59c48d49 123$ sudo cp /var/www/peertube/peertube-latest/support/systemd/peertube.service /etc/systemd/system/
63bfad7e
C
124```
125
126Update the service file:
127
afe81767 128```
d2000ca6 129$ sudo vim /etc/systemd/system/peertube.service
63bfad7e
C
130```
131
63bfad7e
C
132
133Tell systemd to reload its config:
134
afe81767 135```
d2000ca6 136$ sudo systemctl daemon-reload
63bfad7e
C
137```
138
6b2ef589
C
139If you want to start PeerTube on boot:
140
141```
9625507f 142$ sudo systemctl enable peertube
6b2ef589
C
143```
144
07aa93a8 145Run:
63bfad7e 146
afe81767 147```
d2000ca6
C
148$ sudo systemctl start peertube
149$ sudo journalctl -feu peertube
63bfad7e
C
150```
151
6d55bd21
GN
152### FreeBSD
153
07aa93a8 154If you're using FreeBSD, copy the startup script and update rc.conf:
6d55bd21
GN
155
156```
157$ sudo cp /var/www/peertube/peertube-latest/support/freebsd/peertube /usr/local/etc/rc.d/
158$ sudo chmod +x /usr/local/etc/rc.d/peertube
159$ sudo echo peertube_enable="YES" >> /etc/rc.conf
160```
161
07aa93a8 162Run:
6d55bd21
GN
163
164```
165$ sudo service peertube start
166```
167
63bfad7e
C
168### Administrator
169
170The administrator password is automatically generated and can be found in the
171logs. You can set another password with:
172
afe81767 173```
59c48d49 174$ cd /var/www/peertube/peertube-latest && NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run reset-password -- -u root
63bfad7e
C
175```
176
2e3a0215
C
177Now you can subscribe to the mailing list for PeerTube administrators: https://framalistes.org/sympa/subscribe/peertube-admin
178
63bfad7e
C
179## Upgrade
180
a8b5ce95 181#### Auto (minor versions only)
1007a018
SL
182
183```
a8b5ce95 184$ cd /var/www/peertube/peertube-latest/scripts && sudo -u peertube ./upgrade.sh
a8b5ce95 185$ sudo systemctl restart peertube && sudo journalctl -fu peertube
1007a018
SL
186```
187
a8b5ce95
C
188#### Manually
189
ce487e1e 190Make a SQL backup
c7a9f34f
C
191
192```
193$ SQL_BACKUP_PATH="backup/sql-peertube_prod-$(date -Im).bak" && \
59c48d49 194 cd /var/www/peertube && sudo -u peertube mkdir -p backup && \
c7a9f34f
C
195 sudo pg_dump -U peertube -W -h localhost -F c peertube_prod -f "$SQL_BACKUP_PATH"
196```
197
ce487e1e 198Fetch the latest tagged version of Peertube:
23e27dd5
C
199
200```
ce487e1e 201$ 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"
23e27dd5
C
202```
203
ce487e1e 204Download the new version and unzip it:
c7a9f34f 205
afe81767 206```
ce487e1e 207$ cd /var/www/peertube/versions && \
fd206f0b 208 sudo -u peertube wget -q "https://github.com/Chocobozzz/PeerTube/releases/download/${VERSION}/peertube-${VERSION}.zip" && \
ce487e1e
C
209 sudo -u peertube unzip -o peertube-${VERSION}.zip && \
210 sudo -u peertube rm peertube-${VERSION}.zip
211```
212
4805cff1 213Install node dependencies:
ce487e1e
C
214
215```
4805cff1
C
216$ cd /var/www/peertube/versions/peertube-${VERSION} && \
217 sudo -u peertube yarn install --production --pure-lockfile
ce487e1e
C
218```
219
4805cff1 220Copy new configuration defaults values and update your configuration file:
ce487e1e 221
63bfad7e 222```
4805cff1 223$ sudo -u peertube cp /var/www/peertube/versions/peertube-${VERSION}/config/default.yaml /var/www/peertube/config/default.yaml
a8b5ce95 224$ diff /var/www/peertube/versions/peertube-${VERSION}/config/production.yaml.example /var/www/peertube/config/production.yaml
ce487e1e
C
225```
226
4805cff1 227Change the link to point to the latest version:
ce487e1e
C
228
229```
4805cff1 230$ cd /var/www/peertube && \
2519d9fe 231 sudo unlink ./peertube-latest && \
4805cff1 232 sudo -u peertube ln -s versions/peertube-${VERSION} ./peertube-latest
ce487e1e
C
233```
234
4805cff1 235
ce487e1e
C
236Restart PeerTube:
237```
238$ sudo systemctl restart peertube
239```
240
241### Things went wrong?
c7a9f34f 242
ce487e1e 243Change `peertube-latest` destination to the previous version and restore your SQL backup:
c7a9f34f
C
244
245```
246$ OLD_VERSION="v0.42.42" && SQL_BACKUP_PATH="backup/sql-peertube_prod-2018-01-19T10:18+01:00.bak" && \
2519d9fe 247 cd /var/www/peertube && unlink ./peertube-latest && \
c7a9f34f 248 sudo -u peertube ln -s "versions/peertube-$OLD_VERSION" peertube-latest && \
f529f983 249 pg_restore -U peertube -W -h localhost -c -d peertube_prod "$SQL_BACKUP_PATH"
c7a9f34f
C
250 sudo systemctl restart peertube
251```