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