4e52b2155b6de0c3055d2d13b08ed1055fd4e211
[anni] / docs / installation / debian_based_en.md
1 # Installing on Debian Based Distributions
2
3 {! backend/installation/otp_vs_from_source_source.include !}
4
5 ## Installation
6
7 This guide will assume you are on Debian 11 (“bullseye”) or later. This guide should also work with Ubuntu 18.04 (“Bionic Beaver”) and later. It also assumes that you have administrative rights, either as root or a user with [sudo permissions](https://www.digitalocean.com/community/tutorials/how-to-add-delete-and-grant-sudo-privileges-to-users-on-a-debian-vps). If you want to run this guide with root, ignore the `sudo` at the beginning of the lines, unless it calls a user like `sudo -Hu pleroma`; in this case, use `su <username> -s $SHELL -c 'command'` instead.
8
9 {! backend/installation/generic_dependencies.include !}
10
11 ### Prepare the system
12
13 * First update the system, if not already done:
14
15 ```shell
16 sudo apt update
17 sudo apt full-upgrade
18 ```
19
20 * Install some of the above mentioned programs:
21
22 ```shell
23 sudo apt install git build-essential postgresql postgresql-contrib cmake libmagic-dev
24 ```
25
26 ### Install Elixir and Erlang
27
28 * Install Elixir and Erlang (you might need to use backports or [asdf](https://github.com/asdf-vm/asdf) on old systems):
29
30 ```shell
31 sudo apt update
32 sudo apt install elixir erlang-dev erlang-nox
33 ```
34
35
36 ### Optional packages: [`docs/installation/optional/media_graphics_packages.md`](../installation/optional/media_graphics_packages.md)
37
38 ```shell
39 sudo apt install imagemagick ffmpeg libimage-exiftool-perl
40 ```
41
42 ### Install PleromaBE
43
44 * Add a new system user for the Pleroma service:
45
46 ```shell
47 sudo useradd -r -s /bin/false -m -d /var/lib/pleroma -U pleroma
48 ```
49
50 **Note**: To execute a single command as the Pleroma system user, use `sudo -Hu pleroma command`. You can also switch to a shell by using `sudo -Hu pleroma $SHELL`. If you don’t have and want `sudo` on your system, you can use `su` as root user (UID 0) for a single command by using `su -l pleroma -s $SHELL -c 'command'` and `su -l pleroma -s $SHELL` for starting a shell.
51
52 * Git clone the PleromaBE repository and make the Pleroma user the owner of the directory:
53
54 ```shell
55 sudo mkdir -p /opt/pleroma
56 sudo chown -R pleroma:pleroma /opt/pleroma
57 sudo -Hu pleroma git clone -b stable https://git.pleroma.social/pleroma/pleroma /opt/pleroma
58 ```
59
60 * Change to the new directory:
61
62 ```shell
63 cd /opt/pleroma
64 ```
65
66 * Install the dependencies for Pleroma and answer with `yes` if it asks you to install `Hex`:
67
68 ```shell
69 sudo -Hu pleroma mix deps.get
70 ```
71
72 * Generate the configuration: `sudo -Hu pleroma MIX_ENV=prod mix pleroma.instance gen`
73   * Answer with `yes` if it asks you to install `rebar3`.
74   * This may take some time, because parts of pleroma get compiled first.
75   * After that it will ask you a few questions about your instance and generates a configuration file in `config/generated_config.exs`.
76
77 * Check the configuration and if all looks right, rename it, so Pleroma will load it (`prod.secret.exs` for productive instance, `dev.secret.exs` for development instances):
78
79 ```shell
80 sudo -Hu pleroma mv config/{generated_config.exs,prod.secret.exs}
81 ```
82
83
84 * The previous command creates also the file `config/setup_db.psql`, with which you can create the database:
85
86 ```shell
87 sudo -Hu postgres psql -f config/setup_db.psql
88 ```
89
90 * Now run the database migration:
91
92 ```shell
93 sudo -Hu pleroma MIX_ENV=prod mix ecto.migrate
94 ```
95
96 * Now you can start Pleroma already
97
98 ```shell
99 sudo -Hu pleroma MIX_ENV=prod mix phx.server
100 ```
101
102 ### Finalize installation
103
104 If you want to open your newly installed instance to the world, you should run nginx or some other webserver/proxy in front of Pleroma and you should consider to create a systemd service file for Pleroma.
105
106 #### Nginx
107
108 * Install nginx, if not already done:
109
110 ```shell
111 sudo apt install nginx
112 ```
113
114 * Setup your SSL cert, using your method of choice or certbot. If using certbot, first install it:
115
116 ```shell
117 sudo apt install certbot
118 ```
119
120 and then set it up:
121
122 ```shell
123 sudo mkdir -p /var/lib/letsencrypt/
124 sudo certbot certonly --email <your@emailaddress> -d <yourdomain> --standalone
125 ```
126
127 If that doesn’t work, make sure, that nginx is not already running. If it still doesn’t work, try setting up nginx first (change ssl “on” to “off” and try again).
128
129 ---
130
131 * Copy the example nginx configuration and activate it:
132
133 ```shell
134 sudo cp /opt/pleroma/installation/pleroma.nginx /etc/nginx/sites-available/pleroma.nginx
135 sudo ln -s /etc/nginx/sites-available/pleroma.nginx /etc/nginx/sites-enabled/pleroma.nginx
136 ```
137
138 * Before starting nginx edit the configuration and change it to your needs (e.g. change servername, change cert paths)
139 * Enable and start nginx:
140
141 ```shell
142 sudo systemctl enable --now nginx.service
143 ```
144
145 If you need to renew the certificate in the future, uncomment the relevant location block in the nginx config and run:
146
147 ```shell
148 sudo certbot certonly --email <your@emailaddress> -d <yourdomain> --webroot -w /var/lib/letsencrypt/
149 ```
150
151 #### Other webserver/proxies
152
153 You can find example configurations for them in `/opt/pleroma/installation/`.
154
155 #### Systemd service
156
157 * Copy example service file
158
159 ```shell
160 sudo cp /opt/pleroma/installation/pleroma.service /etc/systemd/system/pleroma.service
161 ```
162
163 * Edit the service file and make sure that all paths fit your installation
164 * Enable and start `pleroma.service`:
165
166 ```shell
167 sudo systemctl enable --now pleroma.service
168 ```
169
170 #### Create your first user
171
172 If your instance is up and running, you can create your first user with administrative rights with the following task:
173
174 ```shell
175 sudo -Hu pleroma MIX_ENV=prod mix pleroma.user new <username> <your@emailaddress> --admin
176 ```
177
178 #### Further reading
179
180 {! backend/installation/further_reading.include !}
181
182 ## Questions
183
184 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.