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