386a0ae10eadb14a82d9ce71131b87f0a420662e
[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 # Enter "y" when asked to install Hex
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 acme.sh
83
84 We'll be using acme.sh in Stateless Mode for TLS certificate renewal.
85
86 First, as root, allow the user `acme` to have access to the acme log file, as follows:
87
88 ```
89 # touch /var/log/acme.sh.log
90 # chown acme:acme /var/log/acme.sh.log
91 # chmod 600 /var/log/acme.sh.log
92 ```
93
94 Next, obtain your account fingerprint:
95
96 ```
97 # sudo -Hu acme -g acme acme.sh --register-account
98 ```
99
100 You need to add the following to your nginx configuration for the server
101 running on port 80:
102
103 ```
104 location ~ ^/\.well-known/acme-challenge/([-_a-zA-Z0-9]+)$ {
105 default_type text/plain;
106 return 200 "$1.6fXAG9VyG0IahirPEU2ZerUtItW2DHzDzD9wZaEKpqd";
107 }
108 ```
109
110 Replace the string after after `$1.` with your fingerprint.
111
112 Start nginx:
113
114 ```
115 # service nginx start
116 ```
117
118 It should now be possible to issue a cert (replace `example.com`
119 with your domain name):
120
121 ```
122 # mkdir -p /etc/ssl/example.com
123 # sudo -Hu acme -g acme acme.sh --issue -d example.com --stateless
124 # acme.sh --home /var/db/acme/.acme.sh/ --install-cert -d example.com \
125 --key-file /etc/ssl/example.com/key.pem
126 --fullchain-file /etc/ssl/example.com/fullchain.pem
127 ```
128
129 Let's add auto-renewal to `/etc/daily.local`
130 (replace `example.com` with your domain):
131
132 ```
133 /usr/local/bin/sudo -Hu acme -g acme \
134 /usr/local/sbin/acme.sh -r \
135 -d example.com \
136 --cert-file /etc/nginx/tls/cert \
137 --key-file /etc/nginx/tls/key \
138 --ca-file /etc/nginx/tls/ca \
139 --fullchain-file /etc/nginx/tls/fullchain \
140 --stateless
141 ```
142
143 ### Configuring nginx
144
145 FreeBSD's default nginx configuration does not contain an include directive, which is
146 typically used for multiple sites. Therefore, you will need to first create the required
147 directory as follows:
148
149
150 ```
151 # mkdir -p /usr/local/etc/nginx/sites-available
152 ```
153
154 Next, add an `include` directive to `/usr/local/etc/nginx/nginx.conf`, within the `http {}`
155 block, as follows:
156
157
158 ```
159 http {
160 ...
161 include /usr/local/etc/nginx/sites-available/*.conf;
162 }
163 ```
164
165 As root, copy `/home/pleroma/pleroma/installation/pleroma.nginx` to
166 `/usr/local/etc/nginx/sites-available/pleroma.conf`.
167
168 Edit the defaults of `/usr/local/etc/nginx/sites-available/pleroma.conf`:
169
170 * Change `ssl_trusted_certificate` to `/etc/ssl/example.tld/chain.pem`.
171 * Change `ssl_certificate` to `/etc/ssl/example.tld/fullchain.pem`.
172 * Change `ssl_certificate_key` to `/etc/ssl/example.tld/privkey.pem`.
173 * Change all references of `example.tld` to your instance's domain name.
174
175 ## Creating a startup script for Pleroma
176
177 Pleroma will need to compile when it initially starts, which typically takes a longer
178 period of time. Therefore, it is good practice to initially run pleroma from the
179 command-line before utilizing the rc.d script. That is done as follows:
180
181 ```
182 # su -l pleroma
183 $ cd $HOME/pleroma
184 $ MIX_ENV=prod mix phx.server
185 ```
186
187 Copy the startup script to the correct location and make sure it's executable:
188
189 ```
190 # cp /home/pleroma/pleroma/installation/freebsd/rc.d/pleroma /usr/local/etc/rc.d/pleroma
191 # chmod +x /usr/local/etc/rc.d/pleroma
192 ```
193
194 Update the `/etc/rc.conf` and start pleroma with the following commands:
195
196 ```
197 # sysrc pleroma_enable=YES
198 # service pleroma start
199 ```
200
201 Now you can start pleroma with `# service pleroma start`.
202
203 ## Conclusion
204
205 Restart nginx with `# service nginx restart` and you should be up and running.
206
207 Make sure your time is in sync, or other instances will receive your posts with
208 incorrect timestamps. You should have ntpd running.
209
210 ## Questions
211
212 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**.