51990c5e4b50715bfd712ee2907c27232a8832cf
[akkoma] / docs / installation / freebsd_en.md
1 # Installing on FreeBSD
2
3 This document was written for FreeBSD 12.1, but should be trivially trailerable to future releases.
4 Additionally, this guide document can be modified to
5
6 ## Required software
7
8 This assumes the target system has `pkg(8)`.
9
10 `# pkg install elixir postgresql12-server postgresql12-client postgresql12-contrib git-lite sudo nginx gmake acme.sh`
11
12 Copy the rc.d scripts to the right directory:
13
14 Setup the required services to automatically start at boot, using `sysrc(8)`.
15
16 ```
17 # sysrc nginx_enable=YES
18 # sysrc postgresql_enable=YES
19 ```
20
21 ## Initialize postgres
22
23 ```
24 # service postgresql initdb
25 # service postgresql start
26 ```
27
28 ## Configuring Pleroma
29
30 Create a user for Pleroma:
31
32 ```
33 # pw add user pleroma -m
34 # echo 'export LC_ALL="en_US.UTF-8"' >> /home/pleroma/.profile
35 # su -l pleroma
36 ```
37
38 Clone the repository:
39
40 ```
41 $ cd $HOME # Should be the same as /home/pleroma
42 $ git clone -b stable https://git.pleroma.social/pleroma/pleroma.git
43 ```
44
45 Configure Pleroma. Note that you need a domain name at this point:
46
47 ```
48 $ cd /home/pleroma/pleroma
49 $ mix deps.get
50 $ mix pleroma.instance gen # You will be asked a few questions here.
51 $ cp config/generated_config.exs config/prod.secret.exs # The default values should be sufficient but you should edit it and check that everything seems OK.
52 ```
53
54 Since Postgres is configured, we can now initialize the database. There should
55 now be a file in `config/setup_db.psql` that makes this easier. Edit it, and
56 *change the password* to a password of your choice. Make sure it is secure, since
57 it'll be protecting your database. As root, you can now initialize the database:
58
59 ```
60 # cd /home/pleroma/pleroma
61 # sudo -Hu postgres -g postgres psql -f config/setup_db.psql
62 ```
63
64 Postgres allows connections from all users without a password by default. To
65 fix this, edit `/var/db/postgres/data12/pg_hba.conf`. Change every `trust` to
66 `password`.
67
68 Once this is done, restart Postgres with `# service postgresql restart`.
69
70 Run the database migrations.
71
72 Back as the pleroma user, you will need to do this whenever you update with `git pull`:
73
74 ```
75 # su -l pleroma
76 $ cd /home/pleroma/pleroma
77 $ MIX_ENV=prod mix ecto.migrate
78 ```
79
80 ## Configuring nginx
81
82 Install the example configuration file
83 `/home/pleroma/pleroma/installation/pleroma.nginx` to
84 `/usr/local/etc/nginx/nginx.conf`.
85
86 Note that it will need to be wrapped in a `http {}` block. You should add
87 settings for the nginx daemon outside of the http block, for example:
88
89 ```
90 user nginx nginx;
91 error_log /var/log/nginx/error.log;
92 worker_processes 4;
93
94 events {
95 }
96 ```
97
98 Edit the defaults:
99
100 * Change `ssl_certificate` and `ssl_trusted_certificate` to
101 `/etc/ssl/example.tld/fullchain`.
102 * Change `ssl_certificate_key` to `/etc/ssl/example.tld/key`.
103 * Change `example.tld` to your instance's domain name.
104
105 ## Configuring acme.sh
106
107 We'll be using acme.sh in Stateless Mode for TLS certificate renewal.
108
109 First, get your account fingerprint:
110
111 ```
112 $ sudo -Hu nginx -g nginx acme.sh --register-account
113 ```
114
115 You need to add the following to your nginx configuration for the server
116 running on port 80:
117
118 ```
119 location ~ ^/\.well-known/acme-challenge/([-_a-zA-Z0-9]+)$ {
120 default_type text/plain;
121 return 200 "$1.6fXAG9VyG0IahirPEU2ZerUtItW2DHzDzD9wZaEKpqd";
122 }
123 ```
124
125 Replace the string after after `$1.` with your fingerprint.
126
127 Start nginx:
128
129 ```
130 # service nginx start
131 ```
132
133 It should now be possible to issue a cert (replace `example.com`
134 with your domain name):
135
136 ```
137 $ sudo -Hu nginx -g nginx acme.sh --issue -d example.com --stateless
138 $ acme.sh --install-cert -d example.com \
139 --key-file /path/to/keyfile/in/nginx/key.pem \
140 --fullchain-file /path/to/fullchain/nginx/cert.pem \
141 ```
142
143 Let's add auto-renewal to `/etc/daily.local`
144 (replace `example.com` with your domain):
145
146 ```
147 /usr/pkg/bin/sudo -Hu nginx -g nginx \
148 /usr/pkg/sbin/acme.sh -r \
149 -d example.com \
150 --cert-file /etc/nginx/tls/cert \
151 --key-file /etc/nginx/tls/key \
152 --ca-file /etc/nginx/tls/ca \
153 --fullchain-file /etc/nginx/tls/fullchain \
154 --stateless
155 ```
156
157 ## Creating a startup script for Pleroma
158
159 Pleroma will need to compile when it initially starts, which typically takes a longer
160 period of time. Therefore, it is good practice to initially run pleroma from the
161 command-line before utilizing the rc.d script. That is done as follows:
162
163 ```
164 # su -l pleroma
165 $ cd $HOME/pleroma
166 $ MIX_ENV=prod mix phx.server
167 ```
168
169 Copy the startup script to the correct location and make sure it's executable:
170
171 ```
172 # cp /home/pleroma/pleroma/installation/freebsd/rc.d/pleroma /usr/local/etc/rc.d/pleroma
173 # chmod +x /etc/rc.d/pleroma
174 ```
175
176 Add the following to `/etc/rc.conf`:
177
178 ```
179 pleroma=YES
180 pleroma_home="/home/pleroma"
181 pleroma_user="pleroma"
182 ```
183
184 Run `# /etc/rc.d/pleroma start` to start Pleroma.
185
186 ## Conclusion
187
188 Restart nginx with `# /etc/rc.d/nginx restart` and you should be up and running.
189
190 If you need further help, contact niaa on freenode.
191
192 Make sure your time is in sync, or other instances will receive your posts with
193 incorrect timestamps. You should have ntpd running.
194
195 #### Further reading
196
197 {! backend/installation/further_reading.include !}
198
199 ## Questions
200
201 Questions about the installation or didn’t it work as it should be, ask in [#pleroma:matrix.org](https://matrix.heldscal.la/#/room/#freenode_#pleroma:matrix.org) or IRC Channel **#pleroma** on **Freenode**.