Updated ssl and domain name updates
[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, run the following to implement any database migrations.
73
74 ```
75 # su -l pleroma
76 $ cd /home/pleroma/pleroma
77 $ MIX_ENV=prod mix ecto.migrate
78 ```
79
80 You will need to do this whenever you update with `git pull`:
81
82 ## Configuring nginx
83
84 As root, install the example configuration file
85 `/home/pleroma/pleroma/installation/pleroma.nginx` to
86 `/usr/local/etc/nginx/nginx.conf`.
87
88 Note that it will need to be wrapped in a `http {}` block. You should add
89 settings for the nginx daemon outside of the http block, for example:
90
91 ```
92 user nginx nginx;
93 error_log /var/log/nginx/error.log;
94 worker_processes 4;
95
96 events {
97 }
98 ```
99
100 Edit the defaults of `/usr/local/etc/nginx/nginx.conf`:
101
102 * Change `ssl_trusted_certificate` to `/etc/ssl/example.tld/chain.pem`.
103 * Change `ssl_certificate` to `/etc/ssl/example.tld/fullchain.pem`.
104 * Change `ssl_certificate_key` to `/etc/ssl/example.tld/privkey.pem`.
105 * Change all references of `example.tld` to your instance's domain name.
106
107 ## Configuring acme.sh
108
109 We'll be using acme.sh in Stateless Mode for TLS certificate renewal.
110
111 First, get your account fingerprint:
112
113 ```
114 $ sudo -Hu nginx -g nginx acme.sh --register-account
115 ```
116
117 You need to add the following to your nginx configuration for the server
118 running on port 80:
119
120 ```
121 location ~ ^/\.well-known/acme-challenge/([-_a-zA-Z0-9]+)$ {
122 default_type text/plain;
123 return 200 "$1.6fXAG9VyG0IahirPEU2ZerUtItW2DHzDzD9wZaEKpqd";
124 }
125 ```
126
127 Replace the string after after `$1.` with your fingerprint.
128
129 Start nginx:
130
131 ```
132 # service nginx start
133 ```
134
135 It should now be possible to issue a cert (replace `example.com`
136 with your domain name):
137
138 ```
139 $ sudo -Hu nginx -g nginx acme.sh --issue -d example.com --stateless
140 $ acme.sh --install-cert -d example.com \
141 --key-file /path/to/keyfile/in/nginx/key.pem \
142 --fullchain-file /path/to/fullchain/nginx/cert.pem \
143 ```
144
145 Let's add auto-renewal to `/etc/daily.local`
146 (replace `example.com` with your domain):
147
148 ```
149 /usr/pkg/bin/sudo -Hu nginx -g nginx \
150 /usr/pkg/sbin/acme.sh -r \
151 -d example.com \
152 --cert-file /etc/nginx/tls/cert \
153 --key-file /etc/nginx/tls/key \
154 --ca-file /etc/nginx/tls/ca \
155 --fullchain-file /etc/nginx/tls/fullchain \
156 --stateless
157 ```
158
159 ## Creating a startup script for Pleroma
160
161 Pleroma will need to compile when it initially starts, which typically takes a longer
162 period of time. Therefore, it is good practice to initially run pleroma from the
163 command-line before utilizing the rc.d script. That is done as follows:
164
165 ```
166 # su -l pleroma
167 $ cd $HOME/pleroma
168 $ MIX_ENV=prod mix phx.server
169 ```
170
171 Copy the startup script to the correct location and make sure it's executable:
172
173 ```
174 # cp /home/pleroma/pleroma/installation/freebsd/rc.d/pleroma /usr/local/etc/rc.d/pleroma
175 # chmod +x /etc/rc.d/pleroma
176 ```
177
178 Add the following to `/etc/rc.conf`:
179
180 ```
181 pleroma=YES
182 pleroma_home="/home/pleroma"
183 pleroma_user="pleroma"
184 ```
185
186 Run `# /etc/rc.d/pleroma start` to start Pleroma.
187
188 ## Conclusion
189
190 Restart nginx with `# /etc/rc.d/nginx restart` and you should be up and running.
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**.