> For the complete documentation index, see [llms.txt](https://luice96.gitbook.io/messenger/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://luice96.gitbook.io/messenger/installation.md).

# Installation

This guide describes how to install the application and server solely to run on an emulator. To run the application on a real device, you need to start your server and specify the hosts of your server in [Config file](https://luice96.gitbook.io/messenger/config-file#messenger-app). To start your server, you need to install everything as described in this guide and start the server using the flag `production`  [See here](https://luice96.gitbook.io/messenger/installation#running-on-production).

## Installation and running on localhost

{% embed url="<https://www.youtube.com/watch?v=J4d5lJLC0BQ>" %}

> Solely for testing purposes on a real device, you can use the [hosts of my server](https://luice96.gitbook.io/messenger/hosts-of-server-for-testing-app), use them in the configuration file

## 1. Socket Server

Socket server uses Redis for messaging between API and socket server

First we need to install and run Redis. You can use [Redis installation guide](https://redis.io/topics/quickstart)&#x20;

**Starting Redis**

```bash
$ redis-server
```

{% hint style="info" %}
You can set a password for Redis, after which you will need to enter the Redis password into config file socket server and api server. See [Config file](/messenger/config-file.md)
{% endhint %}

**In `socket-server` directory**

```
$ yarn install
```

**Next**&#x20;

```
$ yarn development
```

## **2. API Server**

First install MongoDB. [Installation Guide](https://docs.mongodb.com/manual/installation/).&#x20;

**Starting MongoDB**

```bash
$ mkdir messenger
$ mongod --dbpath messenger
```

**In `messenger-api` directory**

```
$ yarn install
$ yarn development
```

## 3. Setup AWS S3

[How to create bucket ](https://medium.com/@shamnad.p.s/how-to-create-an-s3-bucket-and-aws-access-key-id-and-secret-access-key-for-accessing-it-5653b6e54337)

[How to add Policy ](https://docs.aws.amazon.com/en_us/AmazonS3/latest/user-guide/add-bucket-policy.html)

{% code title="Policy for this project" %}

```
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Stmt1458840156000",
            "Effect": "Allow",
            "Action": [
                "s3:GetObject",
                "s3:GetObjectAcl",
                "s3:GetObjectVersion",
                "s3:PutObject",
                "s3:PutObjectAcl",
                "s3:PutObjectVersionAcl"
            ],
            "Resource": [
                "arn:aws:s3:::my-bucket/*"
            ]
        }
    ]
}
```

{% endcode %}

When `my-bucket` is your bucket name

**Put your AWS S3 data into config file.** [**More here**](https://luice96.gitbook.io/messenger/config-file#messenger-app)

## 4. Messenger Application.

**In `messenger-app` directory**

```
$ yarn install
$ expo start 
```

## Running on Production

To run Socket Server and API server, uses the package [PM2](https://pm2.io/doc/en/runtime/overview/).

To start the process PM2, you can use commands: `yarn production`  this will launch a server with configurations for production, `yarn staging` this will launch a server with configurations for staging. See [Config file](/messenger/config-file.md).

> To run you need to change config files

**Socket server**&#x20;

```
$ yarn production 
# or 
# $ yarn staging
```

**API Server**&#x20;

```
$ yarn build
$ yarn production 
# or 
# $ yarn staging
```

**Messenger Application**

Just set production mode. See [here](https://docs.expo.io/versions/latest/workflow/development-mode/). This will launch Expo with a production configuration.

## Note

Also for Socket Server and API Server there is a command `yarn start-as-prod`. This starts the server with configuration settings for production without build and PM2. It is needed to develop an application on the localhost using the production configuration

> To run all the commands you can also use `npm run`&#x20;

##
