Self-Hosting
Learn how to deploy erxes on your own server with detailed instructions for Ubuntu/CentOS, including server requirements and configuration.
System Requirements
- RAM: Ensure your environment has at least 2GB of RAM. Insufficient memory can cause processes to crash.
- Disk Space: Ensure you have at least 10GB of free disk space.
- Operating System: Ubuntu or CentOS
Prerequisites
Steps
Create an erxes user on the instance
Assuming you have connected to your instance and ready to execute following steps. First you need to create erxes user
because all erxes related installation scripts are made for erxes user.
Why?
You don't want to use root user to administer your server. So everything will be done by a user called, erxes
. To accomplish this, run the following command:
sudo adduser erxes
When prompted, enter unique & strong password. (Finish adding the user simply by pressing the enter or return key through the questions)
Grant sudo and docker rights to erxes user by following command:
sudo usermod -aG sudo erxes
sudo usermod -aG docker erxes
sudo su - erxes
exit
Create a directory for erxes
mkdir erxes
Initiate docker swarm mode
Now you need to initiate docker swarm mode in order to do that use following command.
Initiate docker swarm mode
docker swarm init
Note
If you get a permission denied warning when you run this command, you haven't run the usermod -aG docker erxes command.
docker network create --driver=overlay --attachable erxes
Note
In erxes directory we have docker-compose.yml file even with that we do not use docker-compose up, docker-compose down, docker-compose restart commands further
Setup and start the databases
openssl rand -base64 756 > mongo-key
sudo chmod 400 mongo-key && sudo chown 999:999 mongo-key
openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 365 -out certificate.pem --batch
cat key.pem certificate.pem > mongo.pem
mkdir -p mongodata
mkdir -p redisdata
docker stack deploy --compose-file docker-compose-dbs.yml erxes-dbs --with-registry-auth --resolve-image changed
Check the status of the databases
To check database services up use following command it will shows you all the running docker services id, name and state etc.
docker ps -a | grep mongo
Make mongo have a replica set
Now we need to make our mongo have a replica set. First we need to enter the mongo container then enter the mongo instance then execute the 3 following commands.
docker exec -it erxes-dbs-mongo-1 bash
mongo -u erxes -p <auto generated in configs.json>
rs.initiate();
Note
You may want to hit return or enter button a few times, if we have done it correctly mongo shell will changes into "RS0: primary"
To quit mongo instance and container run exit command twice.
Copy the generated docker-compose.yml file to the erxes directory
Note
If you are using plugin and you need to add environment variables to the docker-compose.yml file, you can add them in the docker-compose.yml file.
Start the erxes
docker stack deploy --compose-file docker-compose.yml erxes --with-registry-auth --resolve-image changed
Check the status of the erxes
To check erxes services up use following command it will shows you all the running docker services id, name and state etc.
docker ps -a | grep erxes
Configure the nginx
Now we need to configure the erxes.
Create a new nginx configuration file
sudo nano /etc/nginx/sites-enabled/erxes.conf
Copy the nginx configuration file below
Note
Replace example.com with your domain name.
server {
server_name example.com;
index index.html;
client_max_body_size 50M;
client_header_buffer_size 32k;
location / {
access_log /var/log/nginx/erxes-front.access.log;
error_log /var/log/nginx/erxes-front.error.log;
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /widgets/ {
access_log /var/log/nginx/erxes-widgets.access.log;
error_log /var/log/nginx/erxes-widgets.error.log;
proxy_pass http://127.0.0.1:3200/;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
}
location /gateway/ {
access_log /var/log/nginx/erxes-api.access.log;
error_log /var/log/nginx/erxes-api.error.log;
proxy_pass http://127.0.0.1:3300/;
proxy_http_version 1.1;
proxy_buffering off;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
}
Test the nginx configuration
After that we need to test the nginx config. To do that use following command.
sudo nginx -t
Restart the nginx
If nginx test shows successful message we need to restart Nginx. To do that use the following command.
sudo service nginx restart
Setup SSL certificate
erxes only works in secure connection to generate free ssl certificate we use Certbot. To configure that use the following command.
sudo certbot --nginx
Note
you have to point your domain's A record to your erxes host machine in order to get certificate without that certbot will not generate certificate order.
Open the browser and enjoy our product
After entering this command, provide your email and subscription information, and accept the terms. Following that, you will be prompted about the 'redirect' option. We highly recommend enabling this option for security reasons. Once these steps are completed, open your browser and enjoy our product.
Removing erxes
Check the status of the erxes
First, it is unfortunate, but every server needs to be kept tidy. The following commands will help remove the Docker stack and any dangling containers in the swarm.
docker stack ls
Remove the erxes docker stack
To remove the erxes docker stack, use the following command.
docker stack rm erxes
docker stack rm erxes-dbs
To remove all dangling containers use the following commands.
List and remove all dangling images.
docker images -f dangling=true
docker rmi $(docker images -q -f dangling=true)
List and remove all dangling containers.
docker ps -a -f status=exited
docker rm $(docker ps -a -q -f status=exited)
List and remove all dangling volumes
docker volume ls -f dangling=true
docker volume rm $(docker volume ls -q -f dangling=true)
List and remove all dangling networks
docker network ls -f dangling=true
docker network rm $(docker network ls -q -f dangling=true)