3 * [Installation](#installation)
8 **Please don't install PeerTube for production on a small device behind a low bandwidth connection because it could slow down the fediverse.**
12 Follow the steps of the [dependencies guide](dependencies.md).
16 Create a `peertube` user with `/var/www/peertube` home:
19 $ sudo useradd -m -d /var/www/peertube -s /bin/bash -p peertube peertube
24 $ sudo passwd peertube
29 Create the production database and a peertube user inside PostgreSQL:
32 $ sudo -u postgres createuser -P peertube
33 $ sudo -u postgres createdb -O peertube peertube_prod
36 ### Prepare PeerTube directory
38 Fetch the latest tagged version of Peertube
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"
43 Open the peertube directory, create a few required directories
45 $ cd /var/www/peertube && sudo -u peertube mkdir config storage versions && cd versions
48 Download the latest version of the Peertube client, unzip it and remove the zip
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
56 $ cd ../ && sudo -u peertube ln -s versions/peertube-${VERSION} ./peertube-latest
57 $ cd ./peertube-latest && sudo -H -u peertube yarn install --production --pure-lockfile
60 ### PeerTube configuration
62 Copy example configuration:
65 $ cd /var/www/peertube && sudo -u peertube cp peertube-latest/config/production.yaml.example config/production.yaml
68 Then edit the `config/production.yaml` file according to your webserver
73 Copy the nginx configuration template:
76 $ sudo cp /var/www/peertube/peertube-latest/support/nginx/peertube /etc/nginx/sites-available/peertube
79 Then modify the webserver configuration file. Please pay attention to the `alias` keys of the static locations.
80 It should correspond to the paths of your storage directories (set in the configuration file inside the `storage` key).
83 $ sudo vim /etc/nginx/sites-available/peertube
86 If you want to set https with Let's Encrypt please follow the steps of [this guide](https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04).
88 An example of the nginx configuration could be:
94 server_name peertube.example.com;
96 access_log /var/log/nginx/peertube.example.com.access.log;
97 error_log /var/log/nginx/peertube.example.com.error.log;
99 rewrite ^ https://$server_name$request_uri? permanent;
103 listen 443 ssl http2;
104 listen [::]:443 ssl http2;
105 server_name peertube.example.com;
107 # For example with Let's Encrypt
108 ssl_certificate /etc/letsencrypt/live/peertube.example.com/fullchain.pem;
109 ssl_certificate_key /etc/letsencrypt/live/peertube.example.com/privkey.pem;
110 ssl_trusted_certificate /etc/letsencrypt/live/peertube.example.com/chain.pem;
112 access_log /var/log/nginx/peertube.example.com.access.log;
113 error_log /var/log/nginx/peertube.example.com.error.log;
115 location ^~ '/.well-known/acme-challenge' {
116 default_type "text/plain";
117 root /var/www/certbot;
120 location ~ ^/client/(.*\.(js|css|woff2|otf|ttf|woff|eot))$ {
121 add_header Cache-Control "public, max-age=31536000, immutable";
123 alias /var/www/peertube/peertube-latest/client/dist/$1;
126 location ~ ^/static/(thumbnails|avatars)/(.*)$ {
127 add_header Cache-Control "public, max-age=31536000, immutable";
129 alias /var/www/peertube/storage/$1/$2;
133 proxy_pass http://localhost:9000;
134 proxy_set_header X-Real-IP $remote_addr;
135 proxy_set_header Host $host;
136 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
138 # For the video upload
139 client_max_body_size 8G;
140 proxy_connect_timeout 600;
141 proxy_send_timeout 600;
142 proxy_read_timeout 600;
146 # Bypass PeerTube webseed route for better performances
147 location /static/webseed {
148 if ($request_method = 'OPTIONS') {
149 add_header 'Access-Control-Allow-Origin' '*';
150 add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
151 add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
152 add_header 'Access-Control-Max-Age' 1728000;
153 add_header 'Content-Type' 'text/plain charset=UTF-8';
154 add_header 'Content-Length' 0;
158 if ($request_method = 'GET') {
159 add_header 'Access-Control-Allow-Origin' '*';
160 add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
161 add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
163 # Don't spam access log file with byte range requests
167 alias /var/www/peertube/storage/videos;
171 location /tracker/socket {
172 # Peers send a message to the tracker every 15 minutes
173 # Don't close the websocket before this time
174 proxy_read_timeout 1200s;
175 proxy_set_header Upgrade $http_upgrade;
176 proxy_set_header Connection "upgrade";
177 proxy_http_version 1.1;
178 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
179 proxy_set_header Host $host;
180 proxy_pass http://localhost:9000;
186 Activate the configuration file:
189 $ sudo ln -s /etc/nginx/sites-available/peertube /etc/nginx/sites-enabled/peertube
190 $ sudo systemctl reload nginx
195 Copy the nginx configuration template:
198 $ sudo cp /var/www/peertube/peertube-latest/support/systemd/peertube.service /etc/systemd/system/
201 Update the service file:
204 $ sudo vim /etc/systemd/system/peertube.service
207 It should look like this:
211 Description=PeerTube daemon
216 Environment=NODE_ENV=production
217 Environment=NODE_CONFIG_DIR=/var/www/peertube/config
220 ExecStart=/usr/bin/npm start
221 WorkingDirectory=/var/www/peertube/peertube-latest
222 StandardOutput=syslog
224 SyslogIdentifier=peertube
228 WantedBy=multi-user.target
232 Tell systemd to reload its config:
235 $ sudo systemctl daemon-reload
238 If you want to start PeerTube on boot:
241 $ sudo systemctl enable peertube
247 $ sudo systemctl start peertube
248 $ sudo journalctl -feu peertube
253 The administrator password is automatically generated and can be found in the
254 logs. You can set another password with:
257 $ cd /var/www/peertube/peertube-latest && NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run reset-password -- -u root
265 $ SQL_BACKUP_PATH="backup/sql-peertube_prod-$(date -Im).bak" && \
266 cd /var/www/peertube && sudo -u peertube mkdir -p backup && \
267 sudo pg_dump -U peertube -W -h localhost -F c peertube_prod -f "$SQL_BACKUP_PATH"
270 Fetch the latest tagged version of Peertube:
273 $ 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"
276 Download the new version and unzip it:
279 $ cd /var/www/peertube/versions && \
280 sudo -u peertube wget -q "https://github.com/Chocobozzz/PeerTube/releases/download/${VERSION}/peertube-${VERSION}.zip" && \
281 sudo -u peertube unzip -o peertube-${VERSION}.zip && \
282 sudo -u peertube rm peertube-${VERSION}.zip
285 Install node dependencies:
288 $ cd /var/www/peertube/versions/peertube-${VERSION} && \
289 sudo -u peertube yarn install --production --pure-lockfile
292 Copy new configuration defaults values and update your configuration file:
295 $ sudo -u peertube cp /var/www/peertube/versions/peertube-${VERSION}/config/default.yaml /var/www/peertube/config/default.yaml
296 $ diff /var/www/peertube/versions/peertube-${VERSION}/config//production.yaml.example /var/www/peertube/config/production.yaml
299 Change the link to point to the latest version:
302 $ cd /var/www/peertube && \
303 sudo rm ./peertube-latest && \
304 sudo -u peertube ln -s versions/peertube-${VERSION} ./peertube-latest
310 $ sudo systemctl restart peertube
313 ### Things went wrong?
315 Change `peertube-latest` destination to the previous version and restore your SQL backup:
318 $ OLD_VERSION="v0.42.42" && SQL_BACKUP_PATH="backup/sql-peertube_prod-2018-01-19T10:18+01:00.bak" && \
319 cd /var/www/peertube && rm ./peertube-latest && \
320 sudo -u peertube ln -s "versions/peertube-$OLD_VERSION" peertube-latest && \
321 pg_restore -U peertube -W -h localhost -c -d peertube_prod "$SQL_BACKUP_PATH"
322 sudo systemctl restart peertube