diyhosting/peertube.html

220 lines
9.3 KiB
HTML

<!DOCTYPE html>
<html lang=en>
<head>
<title>PeerTube Instance &ndash; diyhosting.bhh.sh</title>
<!--# include file=".nav.html" -->
</head>
<body>
<header><h1>PeerTube Instance</h1></header>
<nav></nav>
<main>
<img class=titleimg src="pix/peertube.svg" alt="PeerTube logo">
<p>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.</p>
<h2>Note on Bandwidth</h2>
<p>
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!
</p>
<p>
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 <a href="https://my.frantech.ca/aff.php?aff=3886">Frantech/BuyVM</a>.
They have unmetered bandwidth, extremely cheap block storage for hosting many, many videos and they even have a good record of being censorship resistant.
</p>
<h2>Prerequisites</h2>
<p><strong>Most</strong> of PeerTube's dependencies can be installed with this command:</p>
<pre><code>apt install -y curl sudo unzip vim ffmpeg postgresql postgresql-contrib g++ make redis-server git python-dev cron wget</code></pre>
<p>It's also important to start all associated daemons:</p>
<pre><code>systemctl start postgresql redis</code></pre>
<p>PeerTube also requires <strong>NodeJS 14</strong> and <strong>yarn</strong> which cannot be installed from the Debian repositories. This means they have to be installed from separate, external repos:</p>
<pre><code>curl -fsSL https://deb.nodesource.com/setup_14.x | bash -
apt install -y nodejs
npm install --global yarn</code></pre>
<p>Now we create a PeerTube user to run and handle PeerTube with the proper permissions:</p>
<pre><code>useradd -m -d /var/www/peertube -s /bin/bash -p peertube peertube</code></pre>
<h2>Database</h2>
<p>PeerTube requires a PostgreSQL database to function. To create it, first make a new Postgres user named PeerTube:</p>
<pre><code>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</code></pre>
<p>Be sure to <strong>make note of your Postgres user password,</strong> as it will be needed later when setting up PeerTube.</p>
<h2>Installation</h2>
<p>Using <code>su -l</code>, 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.</p>
<pre><code>su -l peertube
mkdir config storage versions
chmod 750 config</code></pre>
<h3>Downloading PeerTube</h3>
<p>Still as the PeerTube user, we can now check for the most recent PeerTube versions number, download and install it in the newly created <code>versiond</code> directory.</p>
<pre class=wide><code>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</code></pre>
<h3>Installation via Yarn</h3>
<p>The downloaded release can then be symbolically linked to <code>/var/www/peertube/peertube-latest</code> and <strong>yarn</strong> is used to install PeerTube:</p>
<pre><code>cd /var/www/peertube
ln -s versions/peertube-${VERSION} ./peertube-latest
cd ./peertube-latest
yarn install --production --pure-lockfile</code></pre>
<h2>Configuration</h2>
<p>PeerTube's default config file can be copied over to <code>/var/www/peertube/config/production.yaml</code> so it can actually be used:</p>
<p>Note that we are still running these as the PeerTube user (having run <code>su -l peertube</code>).</p>
<pre><code>cd /var/www/peertube
cp peertube-latest/config/production.yaml.example config/production.yaml</code></pre>
<p>Now the <code>production.yaml</code> file must be edited in the following ways:</p>
<p>First, add the hostname:</p>
<pre><code>webserver:
https: true
hostname: <strong>'example.org'</strong>
port: 443</code></pre>
<p>Then, the database:</p>
<pre><code>database:
hostname: 'localhost'
port: 5432
ssl: false
suffix: '_prod'
username: <strong>'peertube'</strong>
password: <strong>'your_password'</strong>
pool:
max: 5</code></pre>
<p>An email to generate the admin user:</p>
<pre><code>admin:
# Used to generate the root user at first startup
# And to receive emails from the contact form
email: <strong>'chad@example.org'</strong></code></pre>
<p>And <strong>optionally,</strong> email server information:</p>
<pre><code>smtp:
# smtp or sendmail
transport: smtp
# Path to sendmail command. Required if you use sendmail transport
sendmail: null
hostname: <strong>mail.example.org</strong>
port: 465 # If you use StartTLS: 587
username: <strong>your_email_username</strong>
password: <strong>your_email_password</strong>
tls: true # If you use StartTLS: false
disable_starttls: false
ca_file: null # Used for self signed certificates
from_address: <strong>'admin@example.org'</strong></code></pre>
<p>At this point, we have done all we need to do as the PeerTube user. Run <code>exit</code> or press <code>Ctrl-d</code> to log out and return to the root prompt where we will configure Nginx and other system settings.</p>
<h2>Certbot</h2>
<p>First, we will want a Certbot SSL certificate to encrypt connections to our PeerTube instance.
Just run the following:</p>
<pre><code>certbot --nginx -d <strong>peertube.example.org</strong> certonly</code></pre>
<h2>Nginx</h2>
<p>PeerTube includes an Nginx configuration that can be copied over to <code>/etc/nginx/sites-available:</code>
<pre><code>cp /var/www/peertube/peertube-latest/support/nginx/peertube /etc/nginx/sites-available/peertube</code></pre>
<p>Because the PeerTube config is so long, it's recommended to use <code>sed</code> to modify the contents of the file,
replacing <code>${WEBSERVER_HOST}</code> with your hostname,
and <code>$(PEERTUBE_HOST)</code> with your localhost and port, which by default should be <code>127.0.0.1:9000</code>:
<pre><code>sed -i 's/${WEBSERVER_HOST}/<strong>example.org</strong>/g' /etc/nginx/sites-available/peertube
sed -i 's/${PEERTUBE_HOST}/127.0.0.1:9000/g' /etc/nginx/sites-available/peertube</code></pre>
<p>Once you're happy with the Nginx config file, link it to <code>sites-enabled</code> to activate it:</p>
<pre><code>ln -s /etc/nginx/sites-available/peertube /etc/nginx/sites-enabled/peertube</code></pre>
<h2>Running PeerTube</h2>
<p>A config file for a systemd daemon is included in PeerTube and can be setup and started like so:</p>
<pre><code>cp /var/www/peertube/peertube-latest/support/systemd/peertube.service /etc/systemd/system/
systemctl daemon-reload
systemctl start peertube</pre></code>
<p>
PeerTube will take a momemnt to start, but after it does, you can check its status with <code>systemctl status peertube</code> and at this point, your PeerTube site should be live!
</p>
<h2>Using PeerTube</h2>
<p>To set a password for your admin user, run:</p>
<pre><code>cd /var/www/peertube/peertube-latest
NODE_CONFIG_DIR=/var/www/peertube/config NODE_ENV=production npm run reset-password -- -u root</code></pre>
<p>Login to your PeerTube instance using the admin email specified in your <code>production.yaml</code> file and the admin password you just set.</p>
<img src="pix/peertube-login.jpg" height=400px>
<p>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.</p>
<p>Enjoy your PeerTube instance!</p>
<hr>
<h2>Updating PeerTube</h2>
<p>PeerTube is constantly adding new features, so it's a good idea to <a href="https://github.com/Chocobozzz/PeerTube/blob/develop/CHANGELOG.md">check for new updates</a> and add them if you wish. Just in the past year, they have added livestreaming and more.</p>
<p>Updating is fairly easy now since an <code>upgrade.sh</code> script has been added. Just run:</p>
<pre><code>cd /var/www/peertube/peertube-latest/scripts &amp;&amp; sudo -H -u peertube ./upgrade.sh</code></pre>
<p>
Although check the <a href="https://github.com/Chocobozzz/PeerTube/blob/develop/CHANGELOG.md">changelog</a> to see if there are additional manual requirements for particular updates.
</p>
<hr>
<p><em>Written by <a href="https://denshi.live">Denshi.</a> Donate Monero <a href="https://denshi.live/donate.html">here</a> <a href="https://denshi.live/images/monero.png">[QR]</a></em></p>
</main>
<!--# include file=".footer.html" -->
</body>
</html>