3 * [Installation](#installation)
10 Follow the steps of the [dependencies guide](dependencies.md).
14 Create a `peertube` user with `/var/www/peertube` home:
17 $ sudo useradd -m -d /var/www/peertube -s /bin/bash -p peertube peertube
22 $ sudo passwd peertube
27 Create the production database and a peertube user inside PostgreSQL:
30 $ sudo -u postgres createuser -P peertube
31 $ sudo -u postgres createdb -O peertube peertube_prod
34 ### Prepare PeerTube directory
36 Fetch the latest tagged version of Peertube
38 $ 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 Open the peertube directory, create a few required directories
43 $ cd /var/www/peertube && sudo -u peertube mkdir config storage versions && cd versions
46 Download the latest version of the Peertube client, unzip it and remove the zip
48 $ sudo -u peertube wget -q "https://github.com/Chocobozzz/PeerTube/releases/download/${VERSION}/peertube-${VERSION}.zip"
49 $ sudo -u peertube unzip peertube-${VERSION}.zip && sudo -u peertube rm peertube-${VERSION}.zip
54 $ cd ../ && sudo -u peertube ln -s versions/peertube-${VERSION} ./peertube-latest
55 $ cd ./peertube-latest && sudo -u peertube yarn install --production --pure-lockfile
58 ### PeerTube configuration
60 Copy example configuration:
63 $ cd /var/www/peertube && sudo -u peertube cp peertube-latest/config/production.yaml.example config/production.yaml
66 Then edit the `config/production.yaml` file according to your webserver
71 Copy the nginx configuration template:
74 $ sudo cp /var/www/peertube/peertube-latest/support/nginx/peertube /etc/nginx/sites-available/peertube
77 Then modify the webserver configuration file. Please pay attention to the `alias` keys of the static locations.
78 It should correspond to the paths of your storage directories (set in the configuration file inside the `storage` key).
81 $ sudo vim /etc/nginx/sites-available/peertube
84 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).
86 An example of the nginx configuration could be:
92 server_name peertube.example.com;
94 access_log /var/log/nginx/peertube.example.com.access.log;
95 error_log /var/log/nginx/peertube.example.com.error.log;
97 rewrite ^ https://$server_name$request_uri? permanent;
101 listen 443 ssl http2;
102 listen [::]:443 ssl http2;
103 server_name peertube.example.com;
105 # For example with Let's Encrypt
106 ssl_certificate /etc/letsencrypt/live/peertube.example.com/fullchain.pem;
107 ssl_certificate_key /etc/letsencrypt/live/peertube.example.com/privkey.pem;
108 ssl_trusted_certificate /etc/letsencrypt/live/peertube.example.com/chain.pem;
110 access_log /var/log/nginx/peertube.example.com.access.log;
111 error_log /var/log/nginx/peertube.example.com.error.log;
113 location ^~ '/.well-known/acme-challenge' {
114 default_type "text/plain";
115 root /var/www/certbot;
118 location ~ ^/client/(.*\.(js|css|woff2|otf|ttf|woff|eot))$ {
119 add_header Cache-Control "public, max-age=31536000, immutable";
121 alias /var/www/peertube/peertube-latest/client/dist/$1;
124 location ~ ^/static/(thumbnails|avatars)/(.*)$ {
125 add_header Cache-Control "public, max-age=31536000, immutable";
127 alias /var/www/peertube/storage/$1/$2;
131 proxy_pass http://localhost:9000;
132 proxy_set_header X-Real-IP $remote_addr;
133 proxy_set_header Host $host;
134 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
136 # For the video upload
137 client_max_body_size 8G;
138 proxy_connect_timeout 600;
139 proxy_send_timeout 600;
140 proxy_read_timeout 600;
144 # Bypass PeerTube webseed route for better performances
145 location /static/webseed {
146 if ($request_method = 'OPTIONS') {
147 add_header 'Access-Control-Allow-Origin' '*';
148 add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
149 add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
150 add_header 'Access-Control-Max-Age' 1728000;
151 add_header 'Content-Type' 'text/plain charset=UTF-8';
152 add_header 'Content-Length' 0;
156 if ($request_method = 'GET') {
157 add_header 'Access-Control-Allow-Origin' '*';
158 add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
159 add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
161 # Don't spam access log file with byte range requests
165 alias /var/www/peertube/storage/videos;
169 location /tracker/socket {
170 # Peers send a message to the tracker every 15 minutes
171 # Don't close the websocket before this time
172 proxy_read_timeout 1200s;
173 proxy_set_header Upgrade $http_upgrade;
174 proxy_set_header Connection "upgrade";
175 proxy_http_version 1.1;
176 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
177 proxy_set_header Host $host;
178 proxy_pass http://localhost:9000;
184 Activate the configuration file:
187 $ sudo ln -s /etc/nginx/sites-available/peertube /etc/nginx/sites-enabled/peertube
188 $ sudo systemctl reload nginx
193 Copy the nginx configuration template:
196 $ sudo cp /var/www/peertube/peertube-latest/support/systemd/peertube.service /etc/systemd/system/
199 Update the service file:
202 $ sudo vim /etc/systemd/system/peertube.service
205 It should look like this:
209 Description=PeerTube daemon
214 Environment=NODE_ENV=production
215 Environment=NODE_CONFIG_DIR=/var/www/peertube/config
218 ExecStart=/usr/bin/npm start
219 WorkingDirectory=/var/www/peertube/peertube-latest
220 StandardOutput=syslog
222 SyslogIdentifier=peertube
226 WantedBy=multi-user.target
230 Tell systemd to reload its config:
233 $ sudo systemctl daemon-reload
236 If you want to start PeerTube on boot:
239 $ sudo systemctl enable peertube
245 $ sudo systemctl start peertube
246 $ sudo journalctl -feu peertube
251 The administrator password is automatically generated and can be found in the
252 logs. You can set another password with:
255 $ cd /var/www/peertube/peertube-latest && NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run reset-password -- -u root
263 $ SQL_BACKUP_PATH="backup/sql-peertube_prod-$(date -Im).bak" && \
264 cd /var/www/peertube && sudo -u peertube mkdir -p backup && \
265 sudo pg_dump -U peertube -W -h localhost -F c peertube_prod -f "$SQL_BACKUP_PATH"
268 Fetch the latest tagged version of Peertube:
271 $ 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"
274 Download the new version and unzip it:
277 $ cd /var/www/peertube/versions && \
278 sudo -u peertube wget -q "https://github.com/Chocobozzz/PeerTube/releases/download/${VERSION}/peertube-${VERSION}.zip" && \
279 sudo -u peertube unzip -o peertube-${VERSION}.zip && \
280 sudo -u peertube rm peertube-${VERSION}.zip
283 Change the link to point to the latest version:
286 $ cd /var/www/peertube && \
287 sudo rm ./peertube-latest && \
288 sudo -u peertube ln -s versions/peertube-${VERSION} ./peertube-latest
291 Install node dependencies:
294 $ cd /var/www/peertube/peertube-latest && \
295 sudo -u peertube yarn install --production --pure-lockfile
298 Copy new configuration defaults values and update your configuration file:
301 $ sudo -u peertube cp /var/www/peertube/peertube-latest/config/default.yaml /var/www/peertube/config/default.yaml
302 $ diff /var/www/peertube/peertube-latest/config//production.yaml.example /var/www/peertube/config/production.yaml
307 $ sudo systemctl restart peertube
310 ### Things went wrong?
312 Change `peertube-latest` destination to the previous version and restore your SQL backup:
315 $ OLD_VERSION="v0.42.42" && SQL_BACKUP_PATH="backup/sql-peertube_prod-2018-01-19T10:18+01:00.bak" && \
316 cd /var/www/peertube && rm ./peertube-latest && \
317 sudo -u peertube ln -s "versions/peertube-$OLD_VERSION" peertube-latest && \
318 pg_restore -U peertube -c -d peertube_prod "$SQL_BACKUP_PATH"
319 sudo systemctl restart peertube