2019-03-14 14:00:34 +00:00
# Install
2020-01-30 19:27:25 +00:00
!!! info "Docker"
Docker production installation is not yet supported. See [issue #352 ](https://framagit.org/framasoft/mobilizon/issues/352 ).
2019-11-17 17:11:33 +00:00
## Pre-requisites
2019-03-14 14:00:34 +00:00
2019-11-17 17:11:33 +00:00
* A Linux machine with **root access**
2020-06-16 08:57:11 +00:00
* A **domain name** (or subdomain) for the Mobilizon server, e.g. `your-mobilizon-domain.com`
2020-01-30 19:27:25 +00:00
* An **SMTP server** to deliver emails
2019-03-14 14:00:34 +00:00
2019-11-17 17:11:33 +00:00
## Dependencies
2019-03-14 14:00:34 +00:00
2019-11-17 17:11:33 +00:00
Mobilizon requires Elixir, NodeJS and PostgreSQL among other things.
Installing dependencies depends on the system you're using. Follow the steps of the [dependencies guide ](dependencies.md ).
2019-03-14 14:00:34 +00:00
2019-11-17 17:11:33 +00:00
## Setup
2019-03-14 14:00:34 +00:00
2019-11-17 17:11:33 +00:00
We're going to use a dedicated `mobilizon` user with `/home/mobilizon` home:
2019-03-14 14:00:34 +00:00
```bash
2019-11-17 17:11:33 +00:00
sudo adduser --disabled-login mobilizon
2019-03-14 14:00:34 +00:00
```
2019-11-17 17:11:33 +00:00
!!! tip
On FreeBSD
``` bash
sudo pw useradd -n mobilizon -d /home/mobilizon -s /usr/local/bin/bash -m
sudo passwd mobilizon
```
2019-03-14 14:00:34 +00:00
2019-11-17 17:11:33 +00:00
Then let's connect as this user:
2019-03-14 14:00:34 +00:00
```bash
sudo -i -u mobilizon
```
2019-11-17 17:11:33 +00:00
Let's start by cloning the repository in a directory named `live` :
2019-03-14 14:00:34 +00:00
```bash
git clone https://framagit.org/framasoft/mobilizon live & & cd live
```
2019-11-17 17:11:33 +00:00
## Installing dependencies
2019-03-14 14:00:34 +00:00
2019-05-19 09:38:09 +00:00
Install Elixir dependencies
2019-03-14 14:00:34 +00:00
```bash
mix deps.get
```
2020-06-16 08:57:11 +00:00
!!! note
When asked for `Shall I install Hex?` or `Shall I install rebar3?` , hit the enter key to confirm.
Then compile these dependencies and Mobilizon (this can take a few minutes, and can output all kinds of warnings, such as depreciation issues)
2019-03-14 14:00:34 +00:00
```bash
2020-06-16 08:57:11 +00:00
MIX_ENV=prod mix compile
2019-03-14 14:00:34 +00:00
```
Go into the `js/` directory
```bash
2019-05-19 09:38:09 +00:00
cd js
2019-03-14 14:00:34 +00:00
```
2019-05-19 09:38:09 +00:00
2019-03-14 14:00:34 +00:00
and install the Javascript dependencies
2019-05-19 09:38:09 +00:00
2019-03-14 14:00:34 +00:00
```bash
2019-04-10 15:30:18 +00:00
yarn install
2019-03-14 14:00:34 +00:00
```
2020-07-05 06:32:11 +00:00
Finally, we can build the front-end (this can take a few seconds).
!!! warning
Building front-end can consume up to 512MB of RAM by default. If it's too much or not sufficient for your setup, you can adjust the maximum memory used by prefixing the command with the following option:
```
NODE_OPTIONS=--max_old_space_size=4096
```
2019-03-14 14:00:34 +00:00
```bash
2020-06-16 08:57:11 +00:00
yarn run build
2019-03-14 14:00:34 +00:00
```
2019-05-19 09:38:09 +00:00
2019-11-17 17:11:33 +00:00
Let's go back to the main directory
```bash
cd ../
```
## Configuration
Mobilizon provides a command line tool to generate configuration
```bash
2020-06-16 08:57:11 +00:00
MIX_ENV=prod mix mobilizon.instance gen
2019-11-17 17:11:33 +00:00
```
2020-01-30 19:27:25 +00:00
This will ask you questions about your setup and your instance to generate a `prod.secret.exs` file in the `config/` folder, and a `setup_db.psql` file to setup the database.
### Database setup
The `setup_db.psql` file contains SQL instructions to create a PostgreSQL user and database with the chosen credentials and add the required extensions to the Mobilizon database.
2020-06-16 08:57:11 +00:00
Exit running as the mobilizon user (as it shouldn't have `root` /`sudo` rights) and execute in the `/home/mobilizon/live` directory:
2020-01-30 19:27:25 +00:00
```bash
sudo -u postgres psql -f setup_db.psql
```
2020-06-16 08:57:11 +00:00
It should output something like:
```
CREATE ROLE
CREATE DATABASE
You are now connected to database "mobilizon_prod" as user "postgres".
CREATE EXTENSION
CREATE EXTENSION
CREATE EXTENSION
```
Let's get back to our `mobilizon` user:
```bash
sudo -i -u mobilizon
cd live
```
2020-01-30 19:27:25 +00:00
!!! warning
2019-11-17 17:11:33 +00:00
2020-01-30 19:27:25 +00:00
When it's done, don't forget to remove the `setup_db.psql` file.
2019-11-17 17:11:33 +00:00
2020-01-30 19:27:25 +00:00
### Database Migration
2019-11-17 17:11:33 +00:00
2020-01-30 19:27:25 +00:00
Run database migrations:
```bash
MIX_ENV=prod mix ecto.migrate
```
!!! note
Note the `MIX_ENV=prod` environment variable prefix in front of the command. You will have to use it for each `mix` command from now on.
You will have to do this again after most updates.
2019-11-17 17:11:33 +00:00
!!! tip
If some migrations fail, it probably means you're not using a recent enough version of PostgreSQL, or that you haven't installed the required extensions.
2019-03-14 14:00:34 +00:00
## Services
2020-06-16 08:57:11 +00:00
We can quit using the `mobilizon` user again.
2019-03-14 14:00:34 +00:00
### Systemd
2019-05-19 09:38:09 +00:00
Copy the `support/systemd/mobilizon.service` to `/etc/systemd/system` .
2019-03-14 14:00:34 +00:00
```bash
sudo cp support/systemd/mobilizon.service /etc/systemd/system/
```
Reload Systemd to detect your new file
```bash
sudo systemctl daemon-reload
```
2019-05-19 09:38:09 +00:00
2019-03-14 14:00:34 +00:00
And enable the service
```bash
systemctl enable --now mobilizon.service
```
2019-05-19 09:38:09 +00:00
It will run Mobilizon and enable startup on boot. You can follow the logs with
2019-03-14 14:00:34 +00:00
```bash
sudo journalctl -fu mobilizon.service
```
2019-10-11 15:03:18 +00:00
2020-06-16 08:57:11 +00:00
You should see something like this:
```
Running Mobilizon.Web.Endpoint with cowboy 2.8.0 at :::4000 (http)
Access Mobilizon.Web.Endpoint at https://your-mobilizon-domain.com
```
2019-11-17 17:11:33 +00:00
The Mobilizon server runs on port 4000 on the local interface only, so you need to add a reverse-proxy.
2019-10-11 15:03:18 +00:00
## Reverse proxy
### Nginx
Copy the file from `support/nginx/mobilizon.conf` to `/etc/nginx/sites-available` .
```bash
sudo cp support/nginx/mobilizon.conf /etc/nginx/sites-available
```
Then symlink the file into the `/etc/nginx/sites-enabled` directory.
```bash
sudo ln -s /etc/nginx/sites-available/mobilizon.conf /etc/nginx/sites-enabled/
```
Edit the file `/etc/nginx/sites-available` and adapt it to your own configuration.
2019-11-17 17:11:33 +00:00
Test the configuration with `sudo nginx -t` and reload nginx with `systemctl reload nginx` .
2020-01-30 19:27:25 +00:00
2020-06-16 08:57:11 +00:00
### Let's Encrypt
The nginx configuration template handles the HTTP-01 challenge with the webroot plugin:
```bash
sudo mkdir /var/www/certbot
```
Run certbot with (don't forget to adapt the command)
```bash
sudo certbot certonly --rsa-key-size 4096 --webroot -w /var/www/certbot/ --email your@email.com --agree-tos --text --renew-hook "/usr/sbin/nginx -s reload" -d your-mobilizon-domain.com
```
Then adapt the nginx configuration `/etc/nginx/sites-available/mobilizon.conf` by uncommenting certificate paths and removing obsolete blocks.
Finish by testing the configuration with `sudo nginx -t` and reloading nginx with `systemctl reload nginx` .
You should now be able to load https://your-mobilizon-domain.com inside your browser.
## Creating your first user
Login back as the `mobilizon` system user:
```bash
sudo -i -u mobilizon
cd live
```
Create a new user:
```
MIX_ENV=prod mix mobilizon.users.new "your@email.com" --admin --password "Y0urP4ssw0rd"
```
!!! danger
Don't forget to prefix the command with an empty space so that the chosen password isn't kept in your shell history.
!!! tip
You can ignore the `--password` option and Mobilizon will generate one for you.
See the [full documentation ](./CLI tasks/manage_users.md#create-a-new-user ) for this command.
You may now login with your credentials and discover Mobilizon. Feel free to explore [configuration documentation ](./configure ) as well.
2020-01-30 19:27:25 +00:00
## Optional tasks
### Geolocation databases
Mobilizon can use geolocation from MMDB format data from sources like [MaxMind GeoIP ](https://dev.maxmind.com/geoip/geoip2/geolite2/ ) databases or [db-ip.com ](https://db-ip.com/db/download/ip-to-city-lite ) databases. This allows showing events happening near the user's location.
2020-06-16 08:57:11 +00:00
You will need to download the City database and put it into `priv/data/GeoLite2-City.mmdb` . Finish by restarting the `mobilizon` service.
2020-01-30 19:27:25 +00:00
Mobilizon will only show a warning at startup if the database is missing, but it isn't required.