Skip to content

(:redirect openbsd/pleroma:)

Pleroma

Pleroma is a microblogging server software that can federate (exchange messages with) other servers that support ActivityPub. What that means is that you can host a server for yourself or your friends and stay in control of your online identity, but still exchange messages with people on larger servers. Pleroma will federate with all servers that implement ActivityPub, like Friendica, GNU Social, Hubzilla, Mastodon, Misskey, Peertube, and Pixelfed.

This guide describes the installation and configuration of Pleroma (and the required software to run it) on a single OpenBSD 7.2 server.

Installation

First, We need to install the required dependencies

# pkg_add elixir gmake git postgresql-server postgresql-contrib cmake ffmpeg ImageMagick p5-Image-ExifTool libmagic erlang-wx

Pick the latest version of erlang-wx when asked.

Create pleroma user to be run in dedicated user. Before creating it, Edit /etc/login.conf:

pleroma:\
    :datasize-max=1536M:\
    :datasize-cur=1536M:\
    :openfiles-max=4096

This creates a "pleroma" login class and sets higher values than default for datasize and openfiles (see login.conf(5)), this is required to avoid having pleroma crash some time after starting.

Create the _pleroma user, assign it the pleroma login class and create its home directory (/home/_pleroma/):

# useradd -m -L pleroma _pleroma

Enter a shell as the _pleroma user. As root, run

# su -l _pleroma

Because we're running in a VM, Disable time correction to prevent interruption during compilation, And disable Busy-waiting feature to improve performance a bit. Edit ~/.vm.args, insert:

+c false
+sbwt none
+sbwtdcpu none
+sbwtdio none

Then save it.

Edit ~/.profile, Then add this to the bottom of file:

export LC_ALL=en_US.UTF-8
alias mix="elixir --erl \"-args_file $HOME/.vm.args\" -S $(command -v mix)"

Then save it.

Then clone the repository by doing:

$ git clone https://git.pleroma.social/pleroma/pleroma.git

Pleroma is now installed in /home/_pleroma/pleroma/, it will be configured and started at the end of this guide.

Setting up the database: postgresql

Start a shell as the _postgresql user. As root, run

# su -l _postgresql

Then run the initdb command to initialize postgresql. You will need to specify pgdata directory to the default (/var/postgresql/data) with the -D <path> and set the user to postgres with the -U <username> flag. This can be done as follows:

# initdb -D /var/postgresql/data -U postgres

If you are not using the default directory, you will have to update the datadir variable in the /etc/rc.d/postgresql script.

When this is done, enable postgresql so that it starts on boot and start it. As root, run:

$ doas rcctl enable postgresql
$ doas rcctl start postgresql

To check that it started properly and didn't fail right after starting, you can run ps aux | grep postgres, there should be multiple lines of output.

Configuring httpd

httpd will have three fuctions:

Redirect requests trying to reach the instance over http to the https URL

Serve a robots.txt file

Get Let's Encrypt certificates, with acme-client

Insert the following config in httpd.conf:

ext_inet="<IPv4 address>"
ext_inet6="<IPv6 address>"
server "default" {
    listen on $ext_inet port 80 # Comment to disable listening on IPv4
    listen on $ext_inet6 port 80 # Comment to disable listening on IPv6
    listen on 127.0.0.1 port 80 # Do NOT comment this line
    log syslog
    directory no index
    location "/.well-known/acme-challenge/*" {
        root "/acme"
        request strip 2
    }
    location "/robots.txt" { root "/htdocs/" }
    location "/*" { block return 302 "https://$HTTP_HOST$REQUEST_URI" }
}

Do not forget to change <IPv4/6 address> to your server's address(es). If httpd should only listen on one protocol family, comment one of the two first listen options.

Write the content of your robots.txt in /var/www/htdocs/robots.txt:

User-Agent: *
Disallow:

Check the httpd configuration

$ doas httpd -n

If it's OK, enable and start httpd

$ doas rcctl enable httpd
$ doas rcctl start httpd

acme-client

See https://wiki.ircnow.org/index.php?n=Acme-client.Configure

Configuring relayd

relayd will be used as the reverse proxy sitting in front of pleroma. Insert the following configuration in /etc/relayd.conf:

ext_inet="<IPv4 address>"
ext_inet6="<IPv6 address>"
table <pleroma_server> { 127.0.0.1 }
table <httpd_server> { 127.0.0.1 }
http protocol plerup { # Protocol for upstream pleroma server
    #tcp { nodelay, sack, socket buffer 65536, backlog 128 } # Uncomment and adjust as you see fit
    tls { keypair fedi.example.com }
    # Forward some paths to the local server (as pleroma won't respond to them as you might want)
    pass request quick path "/robots.txt" forward to <httpd_server>
    # Append a bunch of headers
    match request header append "X-Forwarded-For" value "$REMOTE_ADDR" # This two header and the next one are not strictly required by pleroma but adding them won't hurt
    match request header append "X-Forwarded-By" value "$SERVER_ADDR:$SERVER_PORT"
    match request header append "Connection" value "upgrade"
}
relay www {
    listen on $ext_inet port https tls # Comment to disable listening on IPv4
    protocol plerup
    forward to <pleroma_server> port 4000
}
relay www6 {
    listen on $ext_inet6 port https tls # Comment to disable listening on IPv6
    protocol plerup
    forward to <pleroma_server> port 4000
}

Change fedi.example.com with your instance domain.

Again, change <IPv4 address> and <IPv6 address> to your server's address(es) and comment one of the two listen options if needed.

Check the configuration with relayd -n, if it is OK enable and start relayd (as root):

$ doas rcctl enable relayd
$ doas rcctl start relayd

Configuring pf

Enabling and configuring pf is highly recommended. In /etc/pf.conf, insert the following configuration:

# Macros
if="<network interface>"
authorized_ssh_clients="any"
# Skip traffic on loopback interface
set skip on lo
# Default behavior
set block-policy drop
block in log all
pass out quick
# Security features
match in all scrub (no-df random-id)
block in log from urpf-failed
# Rules
pass in quick on $if inet proto icmp to ($if) icmp-type { echoreq unreach paramprob trace } # ICMP
pass in quick on $if inet6 proto icmp6 to ($if) icmp6-type { echoreq unreach paramprob timex toobig } # ICMPv6
pass in quick on $if proto tcp to ($if) port { http https } # relayd/httpd
pass in quick on $if proto tcp from $authorized_ssh_clients to ($if) port ssh

Replace <network interface> by your server's network interface name (which you can get with ifconfig). Consider replacing the content of the authorized_ssh_clients macro by, for example, your home IP address, to avoid SSH connection attempts from bots.

Check pf's configuration by running pfctl -nf /etc/pf.conf, load it with pfctl -f /etc/pf.conf and enable pf at boot with rcctl enable pf.

Configuring and starting Pleroma

Enter a shell as _pleroma (as root do su -l _pleroma) and enter pleroma's installation directory:

$ cd ~/pleroma

Now, Run the following command:

$ mix deps.get

When asked to install Hex dependencies, Press Y then RETURN/Enter.

Once dependencies succesfully retrieved, Run

$ MIX_PROD=prod mix pleroma.instance gen

When asked to install rebar3, Press Y then RETURN/Enter, and enter your instance information when asked.

Copy config/generated_config.exs to config/prod.secret.exs. The default values should be sufficient but you should edit it and check that everything seems OK.

$ cp config/generated_config.exs config/prod.secret.exs

Exit your current shell back to root one and run the following command to set up database:

# psql -U postgres -f /home/_pleroma/pleroma/config/setup_db.psql

Return to _pleroma shell into pleroma's installation directory (su -l _pleroma;cd ~/pleroma) and run

$ MIX_ENV=prod mix ecto.migrate

As _pleroma in /home/_pleroma/pleroma, You can now run the following command to start your instance:

$ MIX_ENV=prod mix phx.server

In another SSH session/tmux window, check that it is working properly by running ftp -MVo - http://127.0.0.1:4000/api/v1/instance, you should get json output. Double-check that uri's value is your instance's domain name.

Starting Pleroma at boot

As _pleroma, Edit crontab by doing this:

$ crontab -e

Then insert this:

@reboot tmux new -d "source ~/.profile; cd ~/pleroma; while true; do LC_ALL=en_US.UTF-8 MIX_ENV=prod mix phx.server; done"

Create administrative user

If your instance is up and running, you can create your first user with administrative rights with the following command as the _pleroma user.

$ MIX_ENV=prod mix pleroma.user new <username> <your@emailaddress> --admin