NVM
Evolution API can be easily installed using the Node Version Manager (NVM). Follow these steps to set up your environment and get Evolution API up and running on your server.
Install NVM
First, download and install Node.js. You can do this by running the following commands:
- curl
- wget
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
Now just point the NVM directiories and install node:
# Source the bash for environments
source ~/.bashrc
# Directories
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
# Install node:
nvm install v20.10.0 && nvm use v20.10.0
Confirm that NVM is successfully installed:
command -v nvm
If you haven`t already you could also configure your private server timezone with the following command
dpkg-reconfigure tzdata
Clone the oficial repository from Github to your private server.
git clone https://github.com/EvolutionAPI/evolution-api.git
Then access the folder that the project is on
cd evolution-api
npm install
Now lets copy the env.yml
file with the configurations that you have to edit.
cp src/dev-env.yml src/env.yml
nano src/env.yml
This command creates a copy of the default environment file.
Next, open the env.yml file in a text editor to input your configuration settings. You can use nano, a command-line text editor, for this purpose:
nano src/env.yml
In the nano editor, navigate through the file and replace the default values with your specific configurations. This may include database connection strings, API keys, server ports, etc.
Access the environment variables section for detailed instructions on configuring your env.yml
file.
To start the Evolution API, use the following command:
npm run start:prod
Install and Configure PM2
Use PM2 to install PM2 and start the manager for the API process:
npm install pm2 -g
pm2 start 'npm run start:prod' --name ApiEvolution
pm2 startup
pm2 save --force
You may need to allocate more memory to PM2, especially if your server has the capacity:
pm2 start 'npm run start:prod' --name ApiEvolution -- start --node-args="--max-old-space-size=4096" --max-memory-restart 4G
In the above example, it's assumed that your VPS has at least 4GB of RAM available exclusively for the Evolution API.
The available memory may vary we recommend at least 1GB to run Evolution.
If you want to make sure that the api is running just use your browser to access http://localhost:8080. This should be your browsers response:
{
"status": 200,
"message": "Welcome to the Evolution API, it is working!",
"version": "1.x.x",
"documentation": "http://localhost:8080/docs"
}
Make your life easier with some the JSON Formatter extension on Google Chrome or Microsoft Edge stores.
EvolutionAPI has a in-built Swagger endpoint documentation, you could use to see all the possible endpoints and test the requests by accessing http://localhost:8080/docs
.
Nginx configuration
First let`s install, start, enable and test the Nginx service in your private server.
apt-get install -y nginx
systemctl start nginx
systemctl enable nginx
systemctl status nginx
If the information "Active: active (running)" appears in green, it means that Nginx is running and you can move on to the next step.
Remove Nginx Default Configuration
First, remove the default website file that comes enabled with Nginx:
rm /etc/nginx/sites-enabled/default
Create a new server block file in the directory
nano /etc/nginx/conf.d/default.conf
Then paste the Nginx config in the default.conf
file:
server {
listen 80;
listen \[::\]:80;
server_name \_;
root /var/www/html/;
index index.php index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \\.php$ {
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document\_root$fastcgi_script_name;
include fastcgi_params;
include snippets/fastcgi-php.conf;
}
# A long browser cache lifetime can speed up repeat visits to your page
location ~\* \\.(jpg|jpeg|gif|png|webp|svg|woff|woff2|ttf|css|js|ico|xml)$ {
access_log off;