Installation Documentation - xTalk

I. Server Requirements

xChat supports all platforms: Windows, MacOS, Linux.

xChat needs a VPS server with at least:

  • 2GB of RAM - recommend 4GB

  • 40GB of HDD

  • 1 CPU core - recommend 2 cores at least

  • 3 domains / sub domains

    • api.[your-domain] and point to server IP address

    • admin.[your-domain] and point to server IP address

    • [your-domain] and point to server IP address

II. Software Requirements

Ensure all softwares above are running before setup source code

Testing

From command line / terminal please run these commands to check

1. NodeJS

$ node -v v14.16.0

2. MongoDB

$ mongo --version MongoDB shell version v4.0.7 git version: 1b82c812a9c0bbf6dc79d5400de9ea99e6ffa025 allocator: system modules: none build environment: distarch: x86_64 target_arch: x86_64

3. Redis Server

$ redis-server --version Redis server v=5.0.4 sha=00000000:0 malloc=libc bits=64 build=d4ba11298acbb366

4. FFMPEG

5. NGINX

6. Graphicsmagick

7. Pm2

8. Yarn

III. Setup and Test It Locally

1. API

  • Ensure node v14.x, MongoDB, Redis server, FFMPEG, Graphicsmagick and yarn are running

  • CD to your API folder

  • Run yarn to install nodeJS dependencies

  • Create new .env from .env.example file in the root dir

  • Open file .env and change config

  • Run yarn dev to start development env

  • Open browsers and run http://localhost:9000 it should show success message or Cannot GET /

2. Frontend Web

  • Ensure nodejs and yarn are running

  • From frontend root directory run yarn command to install nodejs dependencies

  • Open config > shared.ts file and edit information. Change with your url in development or production API url

  • Run export PORT=8081 or edit default port in server/index.ts at line 7 const port = parseInt(process.env.PORT || '8081', 10)

  • Run yarn run dev to start development env

  • Then you can open browser http://localhost:8081 to see the web

3. Admin Web

  • Similar Frontend web, same steps.

  • You should change default port with 8082 then open http://localhost:8082 to see your admin app

IV. Setup Production Environment with NGINX

1. API

  • Make sure you have installed nodeJS dependencies by yarn command

  • In API root directory, copy config > development.json to config > production.json

  • Open .env file and change

    • NODE_ENV to production

    • PORT to 8080

    • Change your base url, logoUrl… to your production Url

  • Replace your real logo in public > assets folder.

  • Change related info such as MongoDB, redis uri for production env

  • Testing by run command yarn start or node server/www.js

  • Run pm2 start server/www.js --name=api to run API under background

2. Frontend Web

  • Make sure you have installed nodeJS dependencies by yarn command

  • Edit your API url and socket Url in config > shared.ts

  • Run yarn build

  • Run export PORT=8081 or change port in server > index.ts file

  • Testing by run yarn start or node dist/index.js it should show success message

  • Run pm2 start yarn --interpreter bash --name xchat-web to run application under port 8081

3. Admin Web

  • Similar Frontend web, same steps.

  • You should change default port to 8082 by export PORT=8082 or change port in server > index.ts file

  • Run pm2 start yarn --interpreter bash --name xchat-admin to run app under port 8082

4. Setup NGINX

Config ports api, web, admin as following

  • API: 8080

  • Web: 8081

  • Admin: 8082

Api

  • Let say our api code is in /var/www/api.xchat.info folder and api is running under port 8080, add new file in /etc/nginx/sites-enabled/api.xchat.info and content as bellow

  • You have to change with our server name and source code path

Frontend

  • Let say our frontend code is in /var/www/xchat.info folder and Frontend app is running under port 8081, add new file in /etc/nginx/sites-enabled/xchat.info and content as bellow

  • You have to change with our server name and source code path

Admin

  • Let say our frontend code is in /var/www/admin.xchat.info folder and Frontend app is running under port 8082, add new file in /etc/nginx/sites-enabled/admin.xchat.info and content as bellow

  • You have to change with our server name and source code path

Testing

  • Open browser and access: http://yourdomain.com to access web frontend

  • Open browser and access: http://admin.yourdomain.com to access web admin

5. Check applications are running under pm2

  • Run pm2 ls to see your applications

  • Run pm2 stop [id] to stop app or pm2 reload [id] to reload

  • Run applications in start up by pm2 startup then pm2 save

6. Set up NGINX with HTTPS

7. Migration

  • From API root directory run node server/migrate to seed default values for settings and users

    • Default Admin: admin@example.com

    • Default Password: admin

  • You can change default values in server > migrations folder