2018-09-01 11:53:14 +00:00
# Installing Plume (for development or production)
2018-06-28 23:28:15 +00:00
2018-09-01 11:53:14 +00:00
## Prerequisites
In order to be installed and to work correctly, Plume needs:
2018-09-02 11:13:17 +00:00
- *Git* (to get the code)
- *Curl* (for RustUp, the Rust installer)
2018-09-02 15:43:20 +00:00
- *GCC* and *make* (to compile C dependencies)
2018-10-06 15:34:09 +00:00
- *PostgreSQL* or *SQlite 3 development files* (for the database)
2018-09-02 11:13:17 +00:00
- *GetText* (to manage translations)
- *Rust* and *Cargo* (to build the code)
2018-09-02 15:43:20 +00:00
- *OpenSSL* and *OpenSSL librairies* (for security)
2018-09-01 11:53:14 +00:00
All the following instructions will need a terminal.
Here are the commands to install PostgreSQL and GetText on various operating systems.
Some of them may need root permissions.
2018-09-03 19:45:17 +00:00
You can also install the project using Docker and docker-compose, please refer
to the `Docker install` section.
2018-09-01 11:53:14 +00:00
On **Debian** :
2018-06-29 17:13:58 +00:00
```bash
2018-06-28 23:28:15 +00:00
apt update
2018-10-06 15:06:50 +00:00
# If you want PostgreSQL
2018-09-03 12:17:42 +00:00
apt install gettext postgresql postgresql-contrib libpq-dev git curl gcc make openssl libssl-dev
2018-10-06 15:06:50 +00:00
# If you want SQlite
2018-10-06 15:34:09 +00:00
apt install gettext sqlite3 libsqlite3-dev git curl gcc make openssl libssl-dev
2018-09-01 11:53:14 +00:00
```
On **Fedora** , **CentOS** or **RHEL** :
```bash
2018-10-06 15:06:50 +00:00
# If you want PostgreSQL
dnf install postgresql-server postgresql-contrib libpqxx libpqxx-devel git curl gcc make openssl openssl-devel gettext
# If you want SQLite
2018-10-06 15:34:09 +00:00
dnf install libsq3-devel sqlite3 libsqlite3-dev git curl gcc make openssl openssl-devel gettext
2018-09-01 11:53:14 +00:00
```
On **Gentoo** :
```bash
emerge --sync
2018-10-06 15:06:50 +00:00
# If you want PostgreSQL
2018-09-02 16:01:36 +00:00
emerge -av postgresql eselect-postgresql gettext & & emerge --ask dev-vcs/git
2018-10-06 15:34:09 +00:00
# If you want SQlite
emerge -av gettext & & emerge --ask dev-vcs/git & & emerge -pv sqlite3 libsqlite3-dev
2018-09-01 11:53:14 +00:00
```
2018-10-06 15:35:39 +00:00
On **Mac OS X** , with [Homebrew ](https://brew.sh/ ):
2018-09-01 11:53:14 +00:00
```bash
brew update
2018-10-06 15:35:39 +00:00
# For PostgreSQL
2018-09-02 16:01:36 +00:00
brew install postgres gettext git
2018-10-06 15:35:39 +00:00
# For SQlite (already present, so only GetText and Git are needed)
brew install gettext git
2018-09-01 11:53:14 +00:00
```
2018-10-06 15:06:50 +00:00
## Configuring PostgreSQL
You can either run PostgreSQL from the machine that runs Plume, or from another server. We recommend you to use the first setup for development environments, or in production for small instances.
In the first case, just run this command after the PostgreSQL installation, to start it:
```
service postgresql start
```
If you want to have two separate machines, run these commands on the database server once you've installed the dependencies mentioned above on both servers:
```bash
service postgresql start
su - postgres
createuser -d -P plume
createdb -O plume plume
```
2018-09-01 11:53:14 +00:00
## Creating a new user (optional)
This step is recommended if you are in a **production environment** , but it is not necessary.
```bash
2018-06-28 23:28:15 +00:00
adduser plume
su - plume
2018-09-01 11:53:14 +00:00
cd ~
```
Creating a new user will let you use systemd to manage Plume if you want (see the dedicated section below).
## Installing Rust and Cargo
2018-09-10 11:22:23 +00:00
We said that Plume needed Rust and Cargo to work, but we didn't install them at the same time as PostgreSQL and GetText, because there is an universal installation method called RustUp.
2018-09-01 11:53:14 +00:00
You can install it on **GNU/Linux** and **Mac OS X** with:
```bash
curl https://sh.rustup.rs -sSf | sh
```
2018-09-02 11:13:17 +00:00
When asked, choose the *"1) Proceed with installation (default)"* option.
Then run this command to be able to run cargo in the current session:
```bash
export PATH="$PATH:/home/plume/.cargo/bin:/home/plume/.local/bin:/usr/local/sbin"
```
2018-09-01 17:32:31 +00:00
On **Windows** , you'll need, if you don't already have them, to download and install the [Visual C++ 2015 Build Tools ](https://www.microsoft.com/en-us/download/details.aspx?id=48159 ). Then, download the [rustup installer ](https://www.rust-lang.org/en-US/install.html ) and run it.
2018-09-01 11:53:14 +00:00
2018-10-06 15:06:50 +00:00
## Getting Plume's source code
2018-09-01 11:53:14 +00:00
2018-10-06 15:06:50 +00:00
Plume needs to be compiled from source. To download the code, run:
2018-09-01 11:53:14 +00:00
```bash
2018-06-28 23:28:15 +00:00
git clone https://github.com/Plume-org/Plume.git
cd Plume
2018-10-06 15:39:33 +00:00
# If you want PostgreSQL
export FEATURES=postgres
# If you want SQlite
export FEATURES=sqlite
2018-06-29 17:13:58 +00:00
```
2018-06-28 23:28:15 +00:00
2018-10-06 18:17:36 +00:00
## Configuring Plume
Before starting Plume, you'll need to create a configuration file, called `.env` . Here is a sample of what you should put inside.
```bash
# The address of the database
# (replace USER, PASSWORD, PORT and DATABASE_NAME with your values)
#
# If you are using SQlite, use the path of the database file (`plume.db` for instance)
DATABASE_URL=postgres://USER:PASSWORD@IP:PORT/DATABASE_NAME
# For PostgreSQL: migrations/postgres
# For SQlite: migrations/sqlite
2018-10-22 18:13:15 +00:00
MIGRATION_DIRECTORY=migrations/postgres
2018-10-06 18:17:36 +00:00
# The domain on which your instance will be available
BASE_URL=plu.me
# Secret key used for private cookies and CSRF protection
# You can generate one with `openssl rand -base64 32`
ROCKET_SECRET_KEY=
```
For more information about what you can put in your `.env` , see [the documentation about environment variables ](ENV-VARS.md ).
2018-09-01 11:53:14 +00:00
## Running migrations
2018-09-10 11:22:23 +00:00
Migrations are scripts used to update the database. They are run by a tool called Diesel, which can be installed with:
2018-06-29 17:13:58 +00:00
```bash
2018-10-06 15:39:33 +00:00
cargo install diesel_cli --no-default-features --features $FEATURES --version '=1.3.0'
2018-06-29 17:13:58 +00:00
```
2018-06-28 23:32:15 +00:00
2018-10-06 15:06:50 +00:00
To run the migrations, you can do:
2018-06-28 23:32:15 +00:00
2018-09-01 11:53:14 +00:00
```bash
2018-10-06 18:17:36 +00:00
diesel migration run
2018-09-01 11:53:14 +00:00
```
2018-06-28 23:32:15 +00:00
2018-10-06 15:06:50 +00:00
Migrations should be run before using Plume or the `plm` CLI tool, and after each update.
When in doubt, run them.
2018-06-28 23:32:15 +00:00
2018-10-06 15:06:50 +00:00
## Running Plume
2018-06-28 23:32:15 +00:00
2018-10-06 15:06:50 +00:00
Then, you'll need to install Plume and the CLI tools to manage your instance.
2018-06-29 17:13:58 +00:00
2018-09-01 11:53:14 +00:00
```
2018-10-06 15:39:33 +00:00
cargo install --no-default-features --features $FEATURES
cargo install --no-default-features --features $FEATURES --path plume-cli
2018-10-06 10:59:39 +00:00
```
After that, you'll need to setup your instance, and the admin's account.
```
plm instance new
plm users new --admin
```
For more information about these commands, and the arguments you can give them, check out [their documentaion ](CLI.md ).
2018-09-01 11:53:14 +00:00
2018-10-06 10:59:39 +00:00
Finally, you can start Plume with:
```bash
plume
2018-09-10 11:22:23 +00:00
```
2018-09-03 19:45:17 +00:00
2018-10-06 15:06:50 +00:00
We may provide precompiled packages in the future; if you have experience in these fields and want to help, feel free to discuss this in issues and to propose pull-requests!
2018-09-03 19:45:17 +00:00
## Docker install
2018-10-06 10:59:39 +00:00
You can use `docker` and `docker-compose` in order to manage your Plume instance and have it isolated from your host:
2018-09-03 19:45:17 +00:00
2018-10-06 10:59:39 +00:00
```bash
2018-09-03 19:45:17 +00:00
git clone git@github.com:Plume-org/Plume.git
cd Plume
cp docs/docker-compose.sample.yml docker-compose.yml
cp docs/docker.sample.env .env
2018-10-06 10:59:39 +00:00
# Build the containers
2018-09-03 19:45:17 +00:00
docker-compose build
2018-10-06 10:59:39 +00:00
# Launch the database
2018-09-03 19:45:17 +00:00
docker-compose up -d postgres
2018-10-12 19:41:05 +00:00
# Setup the database (create it and run migrations)
docker-compose run --rm plume diesel database setup
2018-10-06 10:59:39 +00:00
# Setup your instance
2018-10-06 18:17:36 +00:00
docker-compose run --rm plume plm instance new
docker-compose run --rm plume plm users new --admin
2018-10-06 10:59:39 +00:00
# Launch your instance for good
2018-09-03 19:45:17 +00:00
docker-compose up -d
2018-09-01 11:53:14 +00:00
```
2018-06-29 19:15:10 +00:00
2018-09-03 19:45:17 +00:00
Then, you can configure your reverse proxy.
2018-09-01 11:53:14 +00:00
## Configuring Nginx
2018-06-29 19:09:25 +00:00
2018-09-01 17:24:35 +00:00
Here is a sample Nginx configuration for a Plume instance (replace `blog.example.com` with your domain name):
2018-09-01 11:53:14 +00:00
```nginx
2018-09-01 17:24:35 +00:00
server {
listen 80;
2018-09-08 08:02:56 +00:00
listen [::]:80;
2018-09-01 17:24:35 +00:00
server_name blog.example.com;
location /.well-known/acme-challenge {}
location / {
return 301 https://$host$request_uri;
}
}
2018-09-01 11:53:14 +00:00
2018-09-01 17:24:35 +00:00
server {
2018-09-08 08:02:56 +00:00
listen 443 ssl http2;
listen [::]:443 ssl http2;
2018-09-01 17:24:35 +00:00
server_name blog.example.org;
2018-10-06 10:59:39 +00:00
2018-09-01 17:24:35 +00:00
access_log /var/log/nginx/access.log;
2018-09-03 21:37:51 +00:00
root /home/plume/Plume/ ;
2018-09-01 17:24:35 +00:00
SSLCertificateFile /etc/letsencrypt/live/blog.example.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/blog.example.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/blog.example.com/chain.pem
# for ssl conf: https://cipherli.st/
ssl_protocols TLSv1.2 TLSv1.3;# Requires nginx >= 1.13.0 else use TLSv1.2
2018-09-01 23:34:03 +00:00
ssl_prefer_server_ciphers on;
2018-09-01 17:24:35 +00:00
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;# openssl dhparam -out /etc/letsencrypt/ssl-dhparam.pem 4096
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;
ssl_ecdh_curve secp384r1; # Requires nginx >= 1.1.0
ssl_session_timeout 10m;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off; # Requires nginx >= 1.5.9
ssl_stapling on; # Requires nginx >= 1.3.7
ssl_stapling_verify on; # Requires nginx => 1.3.7
resolver 9.9.9.9 80.67.169.12 valid=300s;
2018-09-01 23:34:03 +00:00
resolver_timeout 5s;
2018-09-01 17:24:35 +00:00
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
2018-09-19 16:18:39 +00:00
add_header Content-Security-Policy "default-src 'self'; frame-ancestors 'self'; frame-src https:";
2018-09-01 17:24:35 +00:00
location ~* \.(jpg|jpeg|png|gif|ico|js|pdf)$ {
add_header Cache-Control "public";
expires 7d;
}
location / {
2018-09-01 23:34:03 +00:00
proxy_pass http://localhost:7878/;
2018-09-01 17:24:35 +00:00
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size 10m;
}
2018-09-01 11:53:14 +00:00
}
2018-06-29 19:09:25 +00:00
```
2018-09-01 17:24:35 +00:00
## Configuring Apache
2018-09-10 11:22:23 +00:00
If you prefer Apache, you can use this configuration (here too, replace `blog.example.com` with your domain):
2018-09-01 17:24:35 +00:00
```apache
< VirtualHost * :80 >
ServerName blog.example.com
Redirect / https://blog.example.com/
< / VirtualHost >
2018-10-18 12:49:53 +00:00
SSLStaplingCache "shmcb:logs/stapling-cache(150000)"
2018-09-01 17:24:35 +00:00
< VirtualHost * :443 >
ServerAdmin admin@example.com
ServerName blog.example.com
2018-09-03 21:37:51 +00:00
< Directory " / home / plume / Plume " >
2018-09-01 17:24:35 +00:00
Header always set Referrer-Policy "strict-origin-when-cross-origin"
Header always set Strict-Transport-Security "max-age=31536000"
2018-10-18 12:49:53 +00:00
< / Directory >
2018-09-01 17:24:35 +00:00
SSLEngine on
# for cipher conf: https://cipherli.st/
SSLCipherSuite EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH
SSLProtocol All -SSLv2 -SSLv3 -TLSv1 -TLSv1.1
SSLHonorCipherOrder On
Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains; preload"
Header always set X-Frame-Options DENY
Header always set X-Content-Type-Options nosniff
SSLCompression off
SSLUseStapling on
# Requires Apache >= 2.4.11
SSLSessionTickets Off
SSLCertificateFile /etc/letsencrypt/live/blog.example.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/blog.example.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/blog.example.com/chain.pem
ProxyPreserveHost On
RequestHeader set X-Forwarded-Proto "https"
ProxyPass / http://127.0.0.1:7878/
ProxyPassReverse / http://127.0.0.1:7878/
< / VirtualHost >
```
2018-10-12 18:50:41 +00:00
## Configuring Caddyserver
If you prefer [Caddyserver ](http://caddyserver.com ), you can use this configuration (again, replacing `blog.example.com` with your domain):
```
blog.example.com {
proxy / localhost:7878 {
transparent
}
}
```
2018-09-01 11:53:14 +00:00
## Systemd integration
2018-09-01 23:34:03 +00:00
If you want to manage your Plume instance with systemd, you can use the following unit file (to be saved in `/etc/systemd/system/plume.service` ):
2018-09-01 11:53:14 +00:00
```toml
[Unit]
Description=plume
[Service]
Type=simple
User=plume
WorkingDirectory=/home/plume/Plume
2018-10-06 10:59:39 +00:00
ExecStart=/home/plume/.cargo/bin/plume
2018-09-01 11:53:14 +00:00
TimeoutSec=30
Restart=always
[Install]
WantedBy=multi-user.target
```
2018-09-20 13:21:32 +00:00
Now you need to enable all of these services:
```bash
systemctl enable /etc/systemd/system/plume.service
```
Now start the services:
```bash
systemctl start plume.service
```
Check that they are properly running:
```bash
systemctl status plume.service
```
2018-09-01 23:34:03 +00:00
## SysVinit integration
This script can also be useful if you are using SysVinit.
```bash
2018-09-02 15:25:28 +00:00
#!/bin/sh
### BEGIN INIT INFO
# Provides:
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Federated blogging
# Based on https://raw.githubusercontent.com/fhd/init-script-template/master/template
### END INIT INFO
dir="/home/plume/Plume"
2018-10-06 10:59:39 +00:00
cmd="/home/plume/.cargo/bin/plume"
2018-09-02 15:25:28 +00:00
user="plume"
name=`basename $0`
pid_file="/var/run/$name.pid"
stdout_log="/home/plume/Plume/plume.log"
stderr_log="/home/plume/Plume/plume.err"
get_pid() {
cat "$pid_file"
2018-09-01 23:34:03 +00:00
}
2018-09-02 15:25:28 +00:00
is_running() {
[ -f "$pid_file" ] && ps -p `get_pid` > /dev/null 2>& 1
2018-09-01 23:34:03 +00:00
}
case "$1" in
2018-09-02 15:25:28 +00:00
start)
if is_running; then
echo "Already started"
else
echo "Starting $name"
cd "$dir"
if [ -z "$user" ]; then
sudo $cmd >> "$stdout_log" 2>> "$stderr_log" &
else
sudo -u "$user" $cmd >> "$stdout_log" 2>> "$stderr_log" &
fi
echo $! > "$pid_file"
if ! is_running; then
echo "Unable to start, see $stdout_log and $stderr_log"
exit 1
fi
fi
;;
stop)
if is_running; then
echo -n "Stopping $name.."
kill `get_pid`
for i in 1 2 3 4 5 6 7 8 9 10
# for i in `seq 10`
do
if ! is_running; then
break
fi
echo -n "."
sleep 1
done
echo
if is_running; then
echo "Not stopped; may still be shutting down or shutdown may have failed"
exit 1
else
echo "Stopped"
if [ -f "$pid_file" ]; then
rm "$pid_file"
fi
fi
else
echo "Not running"
fi
;;
restart)
$0 stop
if is_running; then
echo "Unable to stop, will not attempt to start"
exit 1
fi
$0 start
;;
status)
if is_running; then
echo "Running"
else
echo "Stopped"
2018-09-01 23:34:03 +00:00
exit 1
2018-09-02 15:25:28 +00:00
fi
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
2018-09-01 23:34:03 +00:00
esac
exit 0
2018-09-02 15:25:28 +00:00
2018-09-01 23:34:03 +00:00
```
2018-09-01 11:53:14 +00:00
## Caveats:
2018-09-10 11:22:23 +00:00
- Pgbouncer is not supported yet (named transactions are used).
2018-10-06 18:17:36 +00:00
- Rust nightly is a moving target, dependancies can break and sometimes you need to check a few versions to find the one working (run `rustup override set nightly-2018-07-17` in the Plume directory if you have issues during the compilation)
2018-09-01 11:53:14 +00:00
## Acknowledgements
2018-06-29 19:09:25 +00:00
2018-10-06 10:59:39 +00:00
Most of this documentation has been written by *gled-rs* . The systemd unit file, Nginx and Apache configurations have been written by *nonbinaryanargeek* . Some parts (especially the instructions to install native dependencies) are from the [Aardwolf project ](https://github.com/Aardwolf-Social/aardwolf ). The docker instructions, and files have been added by *Eliot Berriot* .