7 Follow the steps of the [dependencies guide](dependencies.md).
11 Create a `peertube` user with `/var/www/peertube` home:
14 $ sudo useradd -m -d /var/www/peertube -s /bin/bash -p peertube peertube
19 $ sudo passwd peertube
24 Create the production database and a peertube user inside PostgreSQL:
27 $ sudo -u postgres createuser -P peertube
28 $ sudo -u postgres createdb -O peertube peertube_prod
31 ### Prepare PeerTube directory
33 Fetch the latest tagged version of Peertube
35 $ 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"
38 Open the peertube directory, create a few required directories
40 $ cd /var/www/peertube && sudo -u peertube mkdir config storage versions && cd versions
43 Download the latest version of the Peertube client, unzip it and remove the zip
45 $ sudo -u peertube wget -q "https://github.com/Chocobozzz/PeerTube/releases/download/${VERSION}/peertube-${VERSION}.zip"
46 $ sudo -u peertube unzip peertube-${VERSION}.zip && sudo -u peertube rm peertube-${VERSION}.zip
51 $ cd ../ && sudo -u peertube ln -s versions/peertube-${VERSION} ./peertube-latest
52 $ cd ./peertube-latest && sudo -u peertube yarn install --production --pure-lockfile
55 ### PeerTube configuration
57 Copy example configuration:
60 $ cd /var/www/peertube && sudo -u peertube cp peertube-latest/config/production.yaml.example config/production.yaml
63 Then edit the `config/production.yaml` file according to your webserver
68 Copy the nginx configuration template:
71 $ sudo cp /var/www/peertube/peertube-latest/support/nginx/peertube /etc/nginx/sites-available/peertube
74 Then modify the webserver configuration file. Please pay attention to the `alias` keys of the static locations.
75 It should correspond to the paths of your storage directories (set in the configuration file inside the `storage` key).
78 $ sudo vim /etc/nginx/sites-available/peertube
81 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).
83 An example of the nginx configuration could be:
89 server_name peertube.example.com;
91 access_log /var/log/nginx/peertube.example.com.access.log;
92 error_log /var/log/nginx/peertube.example.com.error.log;
94 rewrite ^ https://$server_name$request_uri? permanent;
99 listen [::]:443 ssl http2;
100 server_name peertube.example.com;
102 # For example with Let's Encrypt
103 ssl_certificate /etc/letsencrypt/live/peertube.example.com/fullchain.pem;
104 ssl_certificate_key /etc/letsencrypt/live/peertube.example.com/privkey.pem;
105 ssl_trusted_certificate /etc/letsencrypt/live/peertube.example.com/chain.pem;
107 access_log /var/log/nginx/peertube.example.com.access.log;
108 error_log /var/log/nginx/peertube.example.com.error.log;
110 location ^~ '/.well-known/acme-challenge' {
111 default_type "text/plain";
112 root /var/www/certbot;
115 location ~ ^/client/(.*\.(js|css|woff2|otf|ttf|woff|eot))$ {
116 add_header Cache-Control "public, max-age=31536000, immutable";
118 alias /var/www/peertube/peertube-latest/client/dist/$1;
121 location ~ ^/static/(thumbnails|avatars)/(.*)$ {
122 add_header Cache-Control "public, max-age=31536000, immutable";
124 alias /var/www/peertube/storage/$1/$2;
128 proxy_pass http://localhost:9000;
129 proxy_set_header X-Real-IP $remote_addr;
130 proxy_set_header Host $host;
131 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
133 # For the video upload
134 client_max_body_size 8G;
135 proxy_connect_timeout 600;
136 proxy_send_timeout 600;
137 proxy_read_timeout 600;
141 # Bypass PeerTube webseed route for better performances
142 location /static/webseed {
143 if ($request_method = 'OPTIONS') {
144 add_header 'Access-Control-Allow-Origin' '*';
145 add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
146 add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
147 add_header 'Access-Control-Max-Age' 1728000;
148 add_header 'Content-Type' 'text/plain charset=UTF-8';
149 add_header 'Content-Length' 0;
153 if ($request_method = 'GET') {
154 add_header 'Access-Control-Allow-Origin' '*';
155 add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
156 add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
158 # Don't spam access log file with byte range requests
162 alias /var/www/peertube/storage/videos;
166 location /tracker/socket {
167 # Peers send a message to the tracker every 15 minutes
168 # Don't close the websocket before this time
169 proxy_read_timeout 1200s;
170 proxy_set_header Upgrade $http_upgrade;
171 proxy_set_header Connection "upgrade";
172 proxy_http_version 1.1;
173 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
174 proxy_set_header Host $host;
175 proxy_pass http://localhost:9000;
181 Activate the configuration file:
184 $ sudo ln -s /etc/nginx/sites-available/peertube /etc/nginx/sites-enabled/peertube
185 $ sudo systemctl reload nginx
190 Copy the nginx configuration template:
193 $ sudo cp /var/www/peertube/peertube-latest/support/systemd/peertube.service /etc/systemd/system/
196 Update the service file:
199 $ sudo vim /etc/systemd/system/peertube.service
202 It should look like this:
206 Description=PeerTube daemon
211 Environment=NODE_ENV=production
212 Environment=NODE_CONFIG_DIR=/var/www/peertube/config
215 ExecStart=/usr/bin/npm start
216 WorkingDirectory=/var/www/peertube/peertube-latest
217 StandardOutput=syslog
219 SyslogIdentifier=peertube
223 WantedBy=multi-user.target
227 Tell systemd to reload its config:
230 $ sudo systemctl daemon-reload
233 If you want to start PeerTube on boot:
236 $ sudo systemctl enable peertube
242 $ sudo systemctl start peertube
243 $ sudo journalctl -feu peertube
248 The administrator password is automatically generated and can be found in the
249 logs. You can set another password with:
252 $ cd /var/www/peertube/peertube-latest && NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run reset-password -- -u root
260 $ SQL_BACKUP_PATH="backup/sql-peertube_prod-$(date -Im).bak" && \
261 cd /var/www/peertube && sudo -u peertube mkdir -p backup && \
262 sudo pg_dump -U peertube -W -h localhost -F c peertube_prod -f "$SQL_BACKUP_PATH"
265 Update your configuration file. **If some keys are missing, your upgraded PeerTube won't start!**
268 $ diff <(curl -s https://raw.githubusercontent.com/Chocobozzz/PeerTube/develop/config/production.yaml.example) /var/www/peertube/config/production.yaml
274 $ VERSION=$(curl -s https://api.github.com/repos/chocobozzz/peertube/releases/latest | grep tag_name | cut -d '"' -f 4) && \
275 cd /var/www/peertube/versions && \
276 sudo -u peertube wget -q "https://github.com/Chocobozzz/PeerTube/releases/download/${VERSION}/peertube-${VERSION}.zip" && \
277 sudo -u peertube unzip -o peertube-${VERSION}.zip && sudo -u peertube rm peertube-${VERSION}.zip && \
278 cd ../ && sudo rm ./peertube-latest && sudo -u peertube ln -s versions/peertube-${VERSION} ./peertube-latest && \
279 cd ./peertube-latest && sudo -u peertube yarn install --production --pure-lockfile && \
280 sudo systemctl restart peertube
283 Things went wrong? Change `peertube-latest` destination to the previous version and restore your SQL backup:
286 $ OLD_VERSION="v0.42.42" && SQL_BACKUP_PATH="backup/sql-peertube_prod-2018-01-19T10:18+01:00.bak" && \
287 cd /var/www/peertube && rm ./peertube-latest && \
288 sudo -u peertube ln -s "versions/peertube-$OLD_VERSION" peertube-latest && \
289 pg_restore -U peertube -c -d peertube_prod "$SQL_BACKUP_PATH"
290 sudo systemctl restart peertube