Installation Guide for xCams

I. Server Requirements

xCams supports all platforms: Windows, MacOS, Linux. There are 2 web service and streaming media service we need to setup

1. Web service

xCams V3 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

2. Streaming Server

xCams V3 use Ant media as a media streaming service for broadcast, private and group chat. Recommend server with CPU optimized plan at least

  • Ubuntu 18.04

  • 4GB of RAM

  • 2 CPU core

  • streaming domain like streaming.[your-domain]

Note: Ant media is able to be installed on Ubuntu 18.04, Ubuntu 20.04 or CentOS 8 only

II. Software Requirements

xCams V3 architecture needs these softwares

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 v21.2.1

2. MongoDB

$ mongo --version MongoDB shell version v5.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=7.0.4 sha=00000000:0 malloc=libc bits=64 build=d4ba11298acbb366

4. FFMPEG

5. NGINX

6. Pm2

7. Yarn

III. Setup and test it locally

We provide source code with 4 folders, check below and use in the app accordingly

  • user web frontend (front office)

  • admin backend (back office), admin control panel

  • api api of the app

  • config-example

    • env product environment example config

    • nginx nginx config example

1. API

  • Ensure node v12.xMongoDBRedis serverFFMPEG and yarn are running

  • CD to your API folder

  • Run yarn to install nodeJS dependencies. Make sure your NODE_ENV is not production or run yarn install --production=false to install both dependencies and devDependencies

  • Create new .env from config-example > env > api.env file in the root dir

  • Open file .env and change config accordingly. The config looks like below

  • Open browsers and run http://localhost:8080 it should show success message or Hello World!

2. User Frontend Web

  • CD to user folder

  • Run yarn to install nodeJS dependencies. Make sure your NODE_ENV is not production or run yarn install --production=false to install both dependencies and devDependencies

  • Create file .env from config-example > env > user.env and update your config accordingly. Config looks like below

  • Run yarn run dev to start development env

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

3. Admin

  • Similar Frontend web, same steps. but create .env from config-example > env > admin.env

  • Run yarn dev then open http://localhost:8082 to see your admin app

IV. Setup production environment with NGINX

1. API

  • Deploy / copy your api folder to /var/www/api.example.com

  • CD to /var/www/api.example.com and install nodeJS dependencies by yarn command. Setup .env file accordingly

  • Install pm2 (check softwares point)

  • Make sure you have installed nodeJS dependencies by yarn command or run yarn install --production=false to install both dependencies and devDependencies

  • Change port to 8080 in .env file or export HTTP_PORT=8080

  • In API root directory, run yarn build

  • Testing by run command yarn start:prod or node dist/main.js

  • Run export NODE_ENV=production

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

Or run pm2 start yarn --interpreter bash --name xcams-v3-api -- start:prod to run application under port 8080

Note: If have error when starting with Pm2, please try to start without interpreter.

2. Frontend Web

  • Deploy / copy your user folder to /var/www/example.com

  • CD to /var/www/example.com and install nodeJS dependencies by yarn command. Setup .env file accordingly

  • Install pm2 (check softwares point)

  • Make sure you have installed nodeJS dependencies and devDependencies by yarn command or run yarn install --production=false to install both dependencies and devDependencies

  • Run yarn build

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

  • Run export NODE_ENV=production

  • Run export PORT=8081

  • Run pm2 start dist/index.js --name xcams-v3-web -- start to run application

3. Admin

  • Similar as Frontend web, same steps.

  • Deploy / copy your user folder to /var/www/admin.example.com

  • CD to /var/www/admin.example.com and install nodeJS dependencies by yarn command. Setup .env file accordingly

  • Install pm2 (check softwares point)

  • Make sure you have installed nodeJS dependencies and devDependencies by yarn command or run yarn install --production=false to install both dependencies and devDependencies

  • Run yarn build

  • Run export NODE_ENV=production

  • Run export PORT=8082

  • If have dist folder after build, run pm2 start dist/index.js --name xcams-v3-admin -- start to run application

  • Or run pm2 start yarn --interpreter bash --name xcams-v3-admin -- start -p 8082 to run application under port 8080

    Note: If have error when starting with Pm2, please try to start without interpreter

4. Setup nginx

  • Api

    • Let say our frontend code is in /var/www/api.example.com folder and api is running under port 8080, add new file in /etc/nginx/sites-enabled/api.example.com 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/example.com folder and Frontend app is running under port 8081, add new file in /etc/nginx/sites-enabled/example.com and content as bellow

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

Note

  • if have dist folder after build, the location /_next/static/ should be alias /var/www/example.com/dist/.next/static/$1;

  • If don’t have dist folder, check and update location /_next/static/ toe alias /var/www/example.com/.next/static/$1;

  • Admin

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

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

Note

  • if have dist folder after build, the location /_next/static/ should be alias /var/www/admin.example.com/dist/.next/static/$1;

  • If don’t have dist folder, check and update location /_next/static/ toe alias /var/www/example.com/.next/static/$1;

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, open .env and edit DOMAIN value to your domain (without protocol eg http://example.com ). Run yarn migrate (if command not found, try to check package.json file and see if have script:migrate command instead) to seed default values for settings and users

    • Default admin: admin@[yourdomain] with domain is in .env file

    • Default password: adminadmin

    • If admin password is wrong, you can run node script reset-admin-pw to reset it to adminadmin

  • You can change default values in src > migrations folder