Installation Documentation - xFans
- 1 I. Server Requirement
- 2 II. Software Requirements
- 3 Testing
- 3.1 1. NodeJS
- 3.2 2. MongoDB
- 3.3 3. Redis server
- 3.4 4. FFMPEG
- 3.5 5. NGINX
- 3.6 6. Pm2
- 3.7 7. Yarn
- 4 III. Setup and Test It Locally
- 4.1 1. API
- 4.2 2. User Frontend web
- 4.3 3. Admin web
- 5 IV. Setup Production Environment with NGINX
- 5.1 1. API
- 5.2 2. Frontend Web
- 5.3 3. Admin Web
- 5.4 4. Setup NGINX
- 5.4.1 a. Api
- 5.4.2 b. Frontend
- 5.4.3 c. Admin
- 5.4.4 d. Testing
- 5.5 5. Check applications are running under pm2
- 5.6 6. Set up nginx with https
- 5.7 7. Migration
I. Server Requirement
xFans supports all platforms: Windows, MacOS, Linux.
1. Web Service
xFans needs a VPS server with at least:
4GB of RAM - recommend 8GB
40GB of HDD
2 CPU cores
4 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
xFans V3 uses Ant media as a media streaming service for broadcast, private and group chat. Recommend server with at least
Ubuntu 18.04
4GB of RAM
2 CPU core - CPU optimized
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
xFans architecture needs these softwares
NodeJS LTS >= v20.11.1
To install please download NodeJS here
MongoDB >= v4.2
To install please download mongoDB
Redis server >= v7.x
To install please download and setup redis
Nginx >= v1.3 with http_auth_module is enabled
PM2 is a daemon process manager that will help you manage and keep your application online 24/7
Yarn or npm to manage nodeJS package
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
v20.11.1
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=7.1.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 panelapi
api of the appconfig-example
env
product environment example confignginx
nginx config example
1. API
Ensure
node v16.x
,MongoDB
,Redis Server
,FFMPEG
andYarn
are runningCD to your API folder
Run
Yarn
to install nodeJS dependencies. Make sure your NODE_ENV is not production or runYarn install --production=false
to install both dependencies anddevDependencies
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
Check Migration point to seed default data
Run
yarn start:dev
to start development env
Open browsers and run http://localhost:8080
it should show success message or Hello World!
2. User Frontend web
CD to
user
folderRun
Yarn
to install nodeJS dependencies. Make sure your NODE_ENV is notproduction
or runYarn 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 web
Similar Frontend web, same steps. But create
.env
fromconfig-example > env > admin.env
Run
Yarn dev
then openhttp://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 byYarn
command. Setup.env
file accordinglyInstall
pm2
(check softwares point)Make sure you have installed nodeJS dependencies by
Yarn
command or runYarn install --production=false
to install both dependencies and devDependenciesChange 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 xfans-v2-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 byYarn
command. Setup.env
file accordinglyInstall
pm2
(check softwares point)Make sure you have installed nodeJS dependencies and devDependencies by
Yarn
command or runYarn install --production=false
to install both dependencies and devDependenciesRun
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 xfans-v2-web
-- start to run application
3. Admin Web
Similar to 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 byyarn
command. Setup.env
file accordinglyInstall
pm2
(check softwares point)Make sure you have installed nodeJS dependencies and devDependencies by
yarn
command or runyarn install --production=false
to install both dependencies and devDependenciesRun
yarn build
Run
export NODE_ENV=production
Run
export PORT=8082
If have dist folder after build, run
pm2 start dist/index.js --name xfans-v2-admin -- start
to run applicationOr run
pm2 start yarn --interpreter bash --name xfans-v2-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
a. Api
Let say our frontend code is in
/var/www/api.xfans.info
folder and api is running under port 8080, add new file in/etc/nginx/sites-enabled/api.xfans.info
and content as bellowYou have to change with our server name and source code path
b. Frontend
Let say our frontend code is in
/var/www/xfans.xscripts.info
folder and Frontend app is running under port 8081, add new file in/etc/nginx/sites-enabled/xfans.info
and content as bellowYou have to change with our server name and source code path
c. Admin
Let say our frontend code is in
/var/www/admin.xfans.info
folder and Frontend app is running under port 8082, add new file in/etc/nginx/sites-enabled/admin.xfans.info
and content as bellowYou have to change with our server name and source code path
d. 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 applicationsRun
pm2 stop [id]
to stop app orpm2 reload [id]
to reloadRun applications in start up by
pm2 startup
thenpm2 save
6. Set up nginx with https
Check here to setup https with nginx
Setup https with Certbot NGINX
7. Migration
From API root directory run
yarn migrate
to seed default values for settings and usersDefault 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